Skip to content

Commit

Permalink
v. 2.1.0 (re-upload)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikos M committed Oct 13, 2015
1 parent e52c5d5 commit cabc4b8
Show file tree
Hide file tree
Showing 12 changed files with 753 additions and 667 deletions.
127 changes: 32 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,62 +70,31 @@ var xml_grammar = {
// Style model
"Style" : {
// lang token type -> Editor (style) tag
"comment_block": "comment",
"meta_block": "meta",
"cdata_block": "atom",
"atom": "atom",
"open_tag": "tag",
"close_open_tag": "tag",
"auto_close_open_tag": "tag",
"close_tag": "tag",
"attribute": "attribute",
"id": "attribute",
"number": "number",
"string": "string"
"comment" : "comment",
"meta" : "meta",
"cdata" : "atom",
"atom" : "atom",
"open_tag" : "tag",
"close_open_tag" : "tag",
"auto_close_open_tag" : "tag",
"close_tag" : "tag",
"att" : "attribute",
"id" : "attribute",
"number" : "number",
"string" : "string"
},

//
// Lexical model
"Lex": {
"comment:comment": ["<!--","-->"],

"comment_block": {
"type": "comment",
"tokens": [
// block comments
// start, end delims
[ "<!--", "-->" ]
]
},
"cdata:block": ["<![CDATA[","]]>"],

"cdata_block": {
"type": "block",
"tokens": [
// cdata block
// start, end delims
[ "<![CDATA[", "]]>" ]
]
},
"meta:block": ["RE::/<\\?[_a-zA-Z][\\w\\._\\-]*/","?>"],

"meta_block": {
"type": "block",
"tokens": [
// meta block
// start, end delims
[ "RE::/<\\?[_a-zA-Z][\\w\\._\\-]*/", "?>" ]
]
},

// strings
"string": {
"type": "block",
"multiline": false,
"tokens": [
// if no end given, end is same as start
[ "\"" ], [ "'" ]
]
},
"string:block": {"tokens":[[ "\"" ],[ "'" ]], "multiline":false},

// numbers, in order of matching
"number": [
// dec
"RE::/[0-9]\\d*/",
Expand All @@ -140,88 +109,56 @@ var xml_grammar = {
"RE::/&[a-zA-Z][a-zA-Z0-9]*;/"
],

// tag attributes
"attribute": "RE::/[_a-zA-Z][_a-zA-Z0-9\\-]*/",
// tag attribute
"att": "RE::/[_a-zA-Z][_a-zA-Z0-9\\-]*/",

// tags
"open_tag": "RE::/<([_a-zA-Z][_a-zA-Z0-9\\-]*)/",
"close_open_tag": ">",
"auto_close_open_tag": "/>",
"close_tag": "RE::/<\\/([_a-zA-Z][_a-zA-Z0-9\\-]*)>/",

// NEW feature
// action tokens to perform complex grammar functionality
// like associated tag matching and unique identifiers

"ctx_start": {
"context-start": true
},

"ctx_end": {
"context-end": true
},
"text": "RE::/[^<&]+/",

// actions
"ctx_start:action": {"context-start":true},
"ctx_end:action": {"context-end":true},
// allow to find duplicate xml identifiers, with action tokens
"unique": {
"unique:action": {
"unique": ["id", "$1"],
"msg": "Duplicate id attribute \"$0\""
},

// allow to find duplicate xml tag attributes, with action tokens
"unique_att": {
"unique_att:action": {
"unique": ["att", "$0"],
"in-context": true,
"in-context":true,
"msg": "Duplicate attribute \"$0\""
},

// allow to match start/end tags, with action tokens
"match": {
"push": "<$1>"
},

"matched": {
"match:action": {"push":"<$1>"},
"matched:action": {
"pop": "<$1>",
"msg": "Tags \"$0\" and \"$1\" do not match!"
},

"nomatch": {
"pop": null
}
"nomatch:action": {"pop":null}
},

//
// Syntax model (optional)
"Syntax": {
// NEW feature
// using PEG/BNF-like shorthands, instead of multiple grammar configuration objects

"id_att": "'id' unique_att '=' string unique",

"tag_att": "attribute unique_att '=' (string | number)",
"tag_att": "att unique_att '=' (string | number)",

"start_tag": "open_tag match ctx_start (id_att | tag_att)* (close_open_tag | auto_close_open_tag nomatch) ctx_end",
"end_tag": "close_tag matched",

"tags": {
"type": "ngram",
"tokens": [
["start_tag"],
["end_tag"]
]
},
"end_tag": "close_tag matched",

"blocks": {
"type": "ngram",
"tokens": [
["comment_block"],
["cdata_block"],
["meta_block"],
]
}
"xml": "comment | cdata | meta | start_tag | end_tag | atom | text"
},

// what to parse and in what order
"Parser": [ "blocks", "tags", "atom" ]
"Parser": [ ["xml"] ]
};

// 2. parse the grammar into a Codemirror syntax-highlight mode
Expand Down
Loading

0 comments on commit cabc4b8

Please sign in to comment.