Copyright © 2003, 2004, 2005, 2006, 2007 Igor Russkih (Cail Lomecb)
Abstract
Example 1. Common HRC file
<?xml version="1.0"?>
<!DOCTYPE hrc PUBLIC "-//Cail Lomecb//DTD Colorer HRC take5//EN"
"http://colorer.sf.net/2003/hrc.dtd">
<hrc version="take5" xmlns="http://colorer.sf.net/2003/hrc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://colorer.sf.net/2003/hrc
http://colorer.sf.net/2003/hrc.xsd">
<annotation>
<documentation>
your documentation...
</documentation>
</annotation>
your definitions...
</hrc>
<import type='def'/>to import all definitions from the 'def' type. Note, that if several imported types have some identical local names, they are resolved in order of import statements, i.e. the first one is used.
Example 4. Sample type definition
<type name="somelang">
<region name="Keyword" description="This language's keyword"/>
<scheme name="somelang">
<keywords region="Keyword">
<word name='word1'/><word name='word2'/>
<word name='otherkeyword'/>
</keywords>
<regexp match="/other(keyword)?/i" region="Keyword"/>
</scheme>
</type>
Table A.1. Metacharacters
| ^ | Match the beginning of the line |
| $ | Match the end of the line |
| . | Match any character (except \r\n) |
| [...] | Match any character in set |
| [^...] | Match any character that is not in set.
None of RE operators works here, but you some metacharacters and range operator
are possible: a-z stands for all alphabet chars between a and z,
Unicode class reference could be used from RE in form of
[{ASSIGNED}-[{Lu}]-[{Ll}]].
Additional boolean operations: -[] - Class substraction.
&&[] - Class intersection.
See Unicode RE TR#18 for more information.
|
| \# | The symbol '#' after slash (except a-z and 1-9) |
| \b | Word break at this point |
| \B | No word break at this point |
| \xHH, \x{HHHH} | HH, HHHH - character code (hex) |
| \n | 0x10 (lf) |
| \r | 0x13 (cr) |
| \t | 0x09 (tab) |
| \s | Whitespace character (tab/space/cr/lf) |
| \S | Not whitespace |
| \w | Word symbol (chars, digits, _) |
| \W | Not word symbols |
| \d | Digit |
| \D | Not Digit |
| \u | Uppercase symbol |
| \l | Lowercase symbol |
Table A.2. Extended Metacharacters
| \c | Means 'not word' before |
| \N | Reference from inside of regexp to one of its brackets. N - the number of brackets pair. This operator works only with non-operator symbols in a bracket. |
Table A.3. Colorer-take5 Parsing Metacharacters
| ~ | Matches for the start of parent scheme (end of <start> tag). |
| \m | Changes start of regexp |
| \M | Changes end of regexp |
| \yN \YN \y{name} \Y{name} | Link to the external regexp (in <end> token to <start> token param). N - required bracket pair, name - named bracket. |
Table A.4. Operators
| ( ) | Group and remember characters for later use. |
| (?{name} ) | Group and remember characters using named group. |
| (?{} ) or (?: ) | Group characters, but don't remember (unnamed group). |
| (?{} ) | Group and remember characters using unnamed uncounted group. |
| | | Alternative. Match previous or next pattern. |
| * | Match preceeding pattern 0 or more times. |
| + | Match preceeding pattern 1 or more times. |
| ? | Match preceeding pattern 0 or 1 time. |
| {n} | Repeat n times. |
| {n,} | Repeat n or more times. |
| {n,m} | Repeat from n to m times. |
Table A.5. Extended Operators
| ?#N | Look-behind. N - symbol number to look behind. |
| ?~N | Negative look-behind. |
| ?= | Look-ahead. |
| ?! | Negative Look-ahead. |
Example A.1. RE examples
<schema targetNamespace="http://colorer.sf.net/2003/catalog" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <element name="catalog" type="catalog"/> <complexType name="catalog"> <sequence> <element name="hrc-sets" type="hrc-sets"/> <element name="hrd-sets" type="hrd-sets"/> </sequence> </complexType> <complexType name="hrc-sets"> <sequence> <element name="location" type="location" maxOccurs="unbounded"/> </sequence> <attribute name="log-location" type="xs:string"> </attribute> </complexType> <complexType name="hrd-sets"> <sequence> <element name="hrd" type="hrd-entry" minOccurs="0" maxOccurs="unbounded"/> </sequence> </complexType> <complexType name="hrd-entry"> <sequence> <element name="location" type="location" maxOccurs="unbounded"/> </sequence> <attribute name="class" type="xs:NMTOKEN" use="required"> </attribute> <attribute name="name" type="xs:NMTOKEN" use="required"> </attribute> <attribute name="description" type="xs:string"> </attribute> </complexType> <complexType name="location"> <attribute name="link" type="xs:string" use="required"/> </complexType> </schema>
<schema targetNamespace="http://colorer.sf.net/2003/hrd" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <element name="hrd" type="hrd"/> <complexType name="hrd"> <sequence> <element name="documentation" type="documentation" minOccurs="0"/> <sequence minOccurs="0" maxOccurs="unbounded"> <element name="assign" type="assign"/> </sequence> </sequence> </complexType> <complexType name="documentation" mixed="true"> <sequence minOccurs="0" maxOccurs="unbounded"> <any namespace="##other" processContents="skip"/> </sequence> </complexType> <complexType name="assign"> <attribute name="name" use="required" type="region-name"> </attribute> <attribute name="fore" type="color"> </attribute> <attribute name="back" type="color"> </attribute> <attribute name="style" type="style"> </attribute> <attribute name="stext" type="xs:string"> </attribute> <attribute name="etext" type="xs:string"> </attribute> <attribute name="sback" type="xs:string"> </attribute> <attribute name="eback" type="xs:string"> </attribute> </complexType> <simpleType name="region-name"> <restriction base="xs:string"> <pattern value="\i\c*\:\i\c*"/> </restriction> </simpleType> <simpleType name="color"> <restriction base="xs:string"> <pattern value="#?[\dA-Fa-f]{1,6}"/> </restriction> </simpleType> <simpleType name="style"> <restriction base="xs:string"> <pattern value="\d"/> </restriction> </simpleType> </schema>
<schema targetNamespace="http://colorer.sf.net/2003/hrc" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <simpleType name="REstring"> <restriction base="xs:string"> <whiteSpace value="collapse"/> <pattern value="/.*/[ix]*"/> </restriction> </simpleType> <simpleType name="REworddiv"> <restriction base="xs:string"> <whiteSpace value="collapse"/> <pattern value="\[.*\]|%.*;"/> </restriction> </simpleType> <simpleType name="REentity"> <restriction base="xs:string"> <whiteSpace value="collapse"/> <pattern value=".*"/> </restriction> </simpleType> <simpleType name="REstring-or-null"> <union memberTypes="REstring"> <simpleType> <restriction base="xs:string"> <enumeration value=""/> </restriction> </simpleType> </union> </simpleType> <simpleType name="QName"> <restriction base="xs:QName"> <pattern value="(\i\c*:)?\i\c*"/> </restriction> </simpleType> <attributeGroup name="regionX"> <attribute name="region" type="QName"/> <attribute name="region0" type="QName"/> <attribute name="region1" type="QName"/> <attribute name="region2" type="QName"/> <attribute name="region3" type="QName"/> <attribute name="region4" type="QName"/> <attribute name="region5" type="QName"/> <attribute name="region6" type="QName"/> <attribute name="region7" type="QName"/> <attribute name="region8" type="QName"/> <attribute name="region9" type="QName"/> <attribute name="regiona" type="QName"/> <attribute name="regionb" type="QName"/> <attribute name="regionc" type="QName"/> <attribute name="regiond" type="QName"/> <attribute name="regione" type="QName"/> <attribute name="regionf" type="QName"/> </attributeGroup> <element name="hrc" type="hrc"/> <complexType name="hrc"> <sequence> <element name="annotation" type="annotation" minOccurs="0"/> <choice minOccurs="0" maxOccurs="unbounded"> <element name="prototype" type="prototype"/> <element name="package" type="package"/> <element name="type" type="type"/> </choice> </sequence> <attribute name="version" type="xs:NMTOKEN" use="required"> </attribute> </complexType> <complexType name="annotation"> <choice minOccurs="0" maxOccurs="unbounded"> <element name="appinfo"> <complexType mixed="true"> <sequence minOccurs="0" maxOccurs="unbounded"> <any namespace="##other" processContents="lax"/> </sequence> </complexType> </element> <element name="documentation"> <complexType mixed="true"> <sequence minOccurs="0" maxOccurs="unbounded"> <any namespace="##other" processContents="skip"/> </sequence> </complexType> </element> <element name="contributors"> <complexType mixed="true"> <sequence minOccurs="0" maxOccurs="unbounded"> <any namespace="##other" processContents="lax"/> </sequence> </complexType> </element> </choice> </complexType> <complexType name="package"> <sequence> <element name="annotation" type="annotation" minOccurs="0"/> <element name="location" type="location" minOccurs="0"/> </sequence> <attribute name="name" type="xs:NCName" use="required"> </attribute> <attribute