Skip to content

Commit

Permalink
v. 2.3.0, in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikos M committed Oct 18, 2015
1 parent 3002de6 commit d0a749f
Show file tree
Hide file tree
Showing 16 changed files with 459 additions and 637 deletions.
81 changes: 28 additions & 53 deletions README.md
Expand Up @@ -59,98 +59,73 @@ An example for XML:
// 1. a partial xml grammar in simple JSON format
var xml_grammar = {

// prefix ID for regular expressions used in the grammar
"RegExpID" : "RE::",
// prefix ID for regular expressions, represented as strings, used in the grammar
"RegExpID": "RE::",

//
// Style model
"Style" : {
"Style": {
// lang token type -> Editor (style) tag
"declaration" : "keyword",
"doctype" : "string",
"meta" : "string",
"comment" : "comment",
"meta" : "meta",
"atom" : "string",
"cdata" : "string",
"atom" : "string",
"open_tag" : "keyword",
"close_tag" : "keyword",
"auto_close_open_tag" : "keyword",
"close_open_tag" : "keyword",
"att" : "variable",
"id" : "variable",
"number" : "constant.numeric",
"string" : "string"
"string" : "string",
"error" : "invalid"
},

//
// Lexical model
"Lex": {
"declaration:block": ["<?xml","?>"],
"doctype:block": ["RE::/<!doctype\\b/i",">"],
"meta:block": ["RE::/<\\?[_a-zA-Z][\\w\\._\\-]*/","?>"],
"comment:comment": ["<!--","-->"],

"cdata:block": ["<![CDATA[","]]>"],

"meta:block": ["RE::/<\\?[_a-zA-Z][\\w\\._\\-]*/","?>"],

"string:block": {"tokens":[[ "\"" ],[ "'" ]], "multiline":false},

"number": [
// dec
"RE::/[0-9]\\d*/",
// hex
"RE::/#[0-9a-fA-F]+/"
],

// atoms
"atom": [
"RE::/&#x[a-fA-F\\d]+;/",
"RE::/&#[\\d]+;/",
"RE::/&[a-zA-Z][a-zA-Z0-9]*;/"
],

// tag attribute
"string:line-block": [[ "\"" ],[ "'" ]],
"number": ["RE::/[0-9]\\d*/", "RE::/#[0-9a-fA-F]+/"],
"atom": ["RE::/&#x[a-fA-F\\d]+;/", "RE::/&#[\\d]+;/", "RE::/&[a-zA-Z][a-zA-Z0-9]*;/"],
"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\\-]*)>/",

"text": "RE::/[^<&]+/",

// actions
"ctx_start:action": {"context-start":true},
"ctx_end:action": {"context-end":true},
// allow to find duplicate xml identifiers, with action tokens
"ctx:action": {"context":true},
"\\ctx:action": {"context":false},
"unique:action": {
"unique": ["id", "$1"],
"msg": "Duplicate id attribute \"$0\""
"msg": "Duplicate id value \"$0\""
},
// allow to find duplicate xml tag attributes, with action tokens
"unique_att:action": {
"unique": ["att", "$0"],
"in-context":true,
"msg": "Duplicate attribute \"$0\""
},
// allow to match start/end tags, with action tokens
"match:action": {"push":"<$1>"},
"matched:action": {
"match:action": {"push":"<$1>","ci": true},
"\\match:action": {
"pop": "<$1>",
"msg": "Tags \"$0\" and \"$1\" do not match!"
"ci": true,
"msg": "Tags \"$0\" and \"$1\" do not match"
},
"nomatch:action": {"pop":null}
"nomatch:action": {"pop":null},
"out_of_place:error": "\"$2>\" can only be at the beginning of XML document"
},

//
// Syntax model (optional)
"Syntax": {
"id_att": "'id' unique_att '=' string unique",

"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",

"xml": "comment | cdata | meta | start_tag | end_tag | atom | text"
"tag_att": "'id'.att unique_att '=' string unique | att unique_att '=' (string | number)",
"start_tag": "open_tag match ctx tag_att* (close_open_tag | auto_close_open_tag nomatch) \\ctx",
"end_tag": "close_tag \\match",
"xml": "(^^ $* declaration? doctype?)? (declaration.error out_of_place | doctype.error out_of_place | comment | meta | cdata | start_tag | end_tag | atom | text)*"
},

// what to parse and in what order
Expand Down

0 comments on commit d0a749f

Please sign in to comment.