diff --git a/README.md b/README.md index 9132eb0..ec3f78c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A simple and light-weight (~ 20kB minified, ~ 8kB zipped) [CodeMirror](https://g to generate syntax-highlight parsers (codemirror modes) from a grammar specification in JSON format. -See also: [ace-grammar](https://github.com/foo123/ace-grammar) , [prism-grammar](https://github.com/foo123/prism-grammar) +See also: [ace-grammar](https://github.com/foo123/ace-grammar) , [prism-grammar](https://github.com/foo123/prism-grammar) ###Contents @@ -33,12 +33,12 @@ Code Indentation is Codemirror default, looking for ways to add more elaborate i ###Features -* A grammar can **extend other grammars** (so arbitrary variations and dialects can be parsed more easily) -* [`Grammar`](/grammar-reference.md) includes: `Style` Model , `Lex` Model and `Syntax` Model (optional), plus a couple of *settings* (see examples) -* `Grammar` **specification can be minimal** (defaults will be used) (see example grammars) -* [`Grammar Syntax Model`](/grammar-reference.md) can enable highlight in a more context-specific way, plus detect possible *syntax errors* -* [`Grammar Syntax Model`](/grammar-reference.md) can contain *recursive references* (see `/test/grammar-js-recursion.html`) -* [`Grammar Syntax Model`](/grammar-reference.md) can be specificed using [`PEG`](https://en.wikipedia.org/wiki/Parsing_expression_grammar)-like notation or [`BNF`](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form)-like notation (**NEW feature**) +* A `Grammar` can **extend other `Grammars`** (so arbitrary `variations` and `dialects` can be handled more easily) +* [`Grammar`](/grammar-reference.md) includes: **`Style Model`** , **`Lex Model`** and **`Syntax Model`** (optional), plus a couple of *settings* (see examples) +* **`Grammar` specification can be minimal** (defaults will be used) (see example grammars) +* `Grammar.Syntax Model` can enable highlight in a more context-specific way, plus detect possible *syntax errors* +* `Grammar.Syntax Model` can contain **recursive references** (see `/test/grammar-js-recursion.html`) +* `Grammar.Syntax Model` can be (fully) specificed using [`PEG`](https://en.wikipedia.org/wiki/Parsing_expression_grammar)-like notation or [`BNF`](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form)-like notation (**NEW feature**) * Generated highlight modes can support **toggle comments** and **keyword autocompletion** functionality if defined in the grammar * Generated highlight modes can support **lint-like syntax-annotation** functionality generated from the grammar * Generated parsers are **optimized for speed and size** diff --git a/api-reference.md b/api-reference.md index a753934..0600378 100644 --- a/api-reference.md +++ b/api-reference.md @@ -23,9 +23,9 @@ __Method__: `extend` extendedgrammar = CodeMirrorGrammar.extend( grammar, basegrammar1 [, basegrammar2, ..] ); ``` -Extend a grammar with basegrammar1, basegrammar2, etc.. +Extend a `grammar` with `basegrammar1`, `basegrammar2`, etc.. -This way arbitrary dialects and variations can be handled more easily +This way arbitrary `dialects` and `variations` can be handled more easily @@ -35,9 +35,9 @@ __Method__: `parse` parsedgrammar = CodeMirrorGrammar.parse( grammar ); ``` -This is used internally by the CodeMirrorGrammar Class -In order to parse a JSON grammar to a form suitable to be used by the syntax-highlight parser. -However user can use this method to cache a parsedgrammar to be used later. +This is used internally by the `CodeMirrorGrammar` Class +In order to parse a `JSON grammar` to a form suitable to be used by the syntax-highlight parser. +However user can use this method to cache a `parsedgrammar` to be used later. Already parsed grammars are NOT re-parsed when passed through the parse method again @@ -48,7 +48,7 @@ __Method__: `getMode` mode = CodeMirrorGrammar.getMode( grammar [, DEFAULT] ); ``` -This is the main method which transforms a JSON grammar into a CodeMirror syntax-highlight parser. -DEFAULT is the default return value (null by default) for things that are skipped or not styled +This is the main method which transforms a `JSON grammar` into a `CodeMirror` syntax-highlight parser. +`DEFAULT` is the default return value (`null` by default) for things that are skipped or not styled In general there is no need to set this value, unless you need to return something else \ No newline at end of file diff --git a/beeld.config b/beeld.config index 3886203..c02de38 100644 --- a/beeld.config +++ b/beeld.config @@ -40,7 +40,7 @@ tasks =[{}] "@@ROOT@@" = "this" "@@EXPORTS@@" = "exports" - "@@VERSION@@" = "1.0" + "@@VERSION@@" = "1.0.1" "@@MODULE_NAME@@" = "CodeMirrorGrammar" @ diff --git a/build/codemirror_grammar.js b/build/codemirror_grammar.js index 80a372a..0cc29b2 100644 --- a/build/codemirror_grammar.js +++ b/build/codemirror_grammar.js @@ -1,7 +1,7 @@ /** * * CodeMirrorGrammar -* @version: 1.0 +* @version: 1.0.1 * * Transform a grammar specification in JSON format, into a syntax-highlight parser mode for CodeMirror * https://github.com/foo123/codemirror-grammar @@ -292,7 +292,7 @@ var undef = undefined, PROTO = 'prototype', HAS = 'hasOwnProperty', IS_ENUM = 'p }, newline_re = /\r\n|\r|\n/g, dashes_re = /[\-_]/g, - bnf_special_re = /^([{}()*+?|'"]|\s)/, + peg_bnf_notation_re = /^([{}()*+?|'"]|\s)/, has_prefix = function(s, id) { return ( @@ -1546,20 +1546,13 @@ CompositeToken = Class(Token, { } }); -function parse_bnf_shorthand( tok, Lex, Syntax, sub_seq ) +function parse_peg_bnf_notation( tok, Lex, Syntax ) { var alternation, sequence, token, literal, repeat, - t, q, c, prev_token, curr_token; + t, q, c, prev_token, curr_token, stack, tmp; - if ( 'undefined' === typeof tok.pos ) - { - t = new String( trim(tok) ); - t.pos = 0; - } - else - { - t = tok; - } + t = new String( trim(tok) ); + t.pos = 0; if ( 1 === t.length ) { @@ -1569,15 +1562,16 @@ function parse_bnf_shorthand( tok, Lex, Syntax, sub_seq ) } else { + // parse PEG/BNF-like shorthand notations for syntax groups alternation = [ ]; sequence = [ ]; token = ''; + stack = []; while ( t.pos < t.length ) { - // parse BNF-like shorthand notations for syntax groups c = t.charAt( t.pos++ ); - if ( bnf_special_re.test( c ) ) + if ( peg_bnf_notation_re.test( c ) ) { if ( token.length ) { @@ -1591,7 +1585,7 @@ function parse_bnf_shorthand( tok, Lex, Syntax, sub_seq ) sequence.push( token ); token = ''; } - + if ( '"' === c || "'" === c ) { // literal token, quoted @@ -1705,24 +1699,57 @@ function parse_bnf_shorthand( tok, Lex, Syntax, sub_seq ) else if ( '(' === c ) { // start of grouped sub-sequence - prev_token = parse_bnf_shorthand( t, Lex, Syntax, true ); - curr_token = '(' + prev_token + ')'; - if ( !Syntax[curr_token] ) Syntax[curr_token] = clone( Lex[prev_token] || Syntax[prev_token] ); - sequence.push( curr_token ); + stack.push([sequence, alternation, token]); + sequence = []; alternation = []; token = ''; } else if ( ')' === c ) { // end of grouped sub-sequence - if ( sub_seq ) + if ( sequence.length > 1 ) { - //t.pos++; - break; + curr_token = '' + sequence.join( " " ); + if ( !Syntax[curr_token] ) + { + Syntax[curr_token] = { + type: 'group', + match: 'sequence', + tokens: sequence + }; + } + alternation.push( curr_token ); } - else + else if ( sequence.length ) { - continue; + alternation.push( sequence[0] ); } + sequence = []; + + if ( alternation.length > 1 ) + { + curr_token = '' + alternation.join( " | " ); + if ( !Syntax[curr_token] ) + { + Syntax[curr_token] = { + type: 'group', + match: 'either', + tokens: alternation + }; + } + } + else if ( alternation.length ) + { + curr_token = alternation[ 0 ]; + } + alternation = []; + + tmp = stack.pop( ); + sequence = tmp[0]; alternation = tmp[1]; token = tmp[2]; + + prev_token = curr_token; + curr_token = '(' + prev_token + ')'; + if ( !Syntax[curr_token] ) Syntax[curr_token] = clone( Lex[prev_token] || Syntax[prev_token] ); + sequence.push( curr_token ); } else // space @@ -1861,7 +1888,7 @@ function get_tokenizer( tokenID, RegExpID, Lex, Syntax, Style, if ( T_STR & get_type( tok ) ) { - tok = parse_bnf_shorthand( tok, Lex, Syntax ); + tok = parse_peg_bnf_notation( tok, Lex, Syntax ); tok = Lex[ tok ] || Syntax[ tok ]; } @@ -1884,17 +1911,10 @@ function get_tokenizer( tokenID, RegExpID, Lex, Syntax, Style, // loop and get all references } - // provide some defaults if ( 'undefined' === typeof tok.type ) { - if ( tok['either'] ) - { - tok.type = "group"; - tok.match = "either"; - tok.tokens = tok['either']; - delete tok['either']; - } - else if ( tok['all'] || tok['sequence'] ) + // provide some defaults + if ( tok['all'] || tok['sequence'] ) { tok.type = "group"; tok.match = "sequence"; @@ -1902,6 +1922,13 @@ function get_tokenizer( tokenID, RegExpID, Lex, Syntax, Style, if ( tok['all'] ) delete tok['all']; else delete tok['sequence']; } + else if ( tok['either'] ) + { + tok.type = "group"; + tok.match = "either"; + tok.tokens = tok['either']; + delete tok['either']; + } else if ( tok['zeroOrMore'] ) { tok.type = "group"; @@ -1923,6 +1950,30 @@ function get_tokenizer( tokenID, RegExpID, Lex, Syntax, Style, tok.tokens = tok['zeroOrOne']; delete tok['zeroOrOne']; } + else if ( tok['comment'] ) + { + tok.type = "comment"; + tok.tokens = tok['comment']; + delete tok['comment']; + } + else if ( tok['block'] ) + { + tok.type = "block"; + tok.tokens = tok['block']; + delete tok['block']; + } + else if ( tok['escaped-block'] ) + { + tok.type = "escaped-block"; + tok.tokens = tok['escaped-block']; + delete tok['escaped-block']; + } + else if ( tok['simple'] ) + { + tok.type = "simple"; + tok.tokens = tok['simple']; + delete tok['simple']; + } else { tok.type = "simple"; @@ -2179,7 +2230,7 @@ function parse_grammar( grammar ) /** * * CodeMirrorGrammar -* @version: 1.0 +* @version: 1.0.1 * * Transform a grammar specification in JSON format, into a syntax-highlight parser mode for CodeMirror * https://github.com/foo123/codemirror-grammar @@ -2536,7 +2587,7 @@ function get_mode( grammar, DEFAULT ) [/DOC_MARKDOWN]**/ var CodeMirrorGrammar = exports['CodeMirrorGrammar'] = { - VERSION: "1.0", + VERSION: "1.0.1", // extend a grammar using another base grammar /**[DOC_MARKDOWN] @@ -2546,9 +2597,9 @@ var CodeMirrorGrammar = exports['CodeMirrorGrammar'] = { * extendedgrammar = CodeMirrorGrammar.extend( grammar, basegrammar1 [, basegrammar2, ..] ); * ``` * - * Extend a grammar with basegrammar1, basegrammar2, etc.. + * Extend a `grammar` with `basegrammar1`, `basegrammar2`, etc.. * - * This way arbitrary dialects and variations can be handled more easily + * This way arbitrary `dialects` and `variations` can be handled more easily [/DOC_MARKDOWN]**/ extend: extend, @@ -2560,9 +2611,9 @@ var CodeMirrorGrammar = exports['CodeMirrorGrammar'] = { * parsedgrammar = CodeMirrorGrammar.parse( grammar ); * ``` * - * This is used internally by the CodeMirrorGrammar Class - * In order to parse a JSON grammar to a form suitable to be used by the syntax-highlight parser. - * However user can use this method to cache a parsedgrammar to be used later. + * This is used internally by the `CodeMirrorGrammar` Class + * In order to parse a `JSON grammar` to a form suitable to be used by the syntax-highlight parser. + * However user can use this method to cache a `parsedgrammar` to be used later. * Already parsed grammars are NOT re-parsed when passed through the parse method again [/DOC_MARKDOWN]**/ parse: parse_grammar, @@ -2575,8 +2626,8 @@ var CodeMirrorGrammar = exports['CodeMirrorGrammar'] = { * mode = CodeMirrorGrammar.getMode( grammar [, DEFAULT] ); * ``` * - * This is the main method which transforms a JSON grammar into a CodeMirror syntax-highlight parser. - * DEFAULT is the default return value (null by default) for things that are skipped or not styled + * This is the main method which transforms a `JSON grammar` into a `CodeMirror` syntax-highlight parser. + * `DEFAULT` is the default return value (`null` by default) for things that are skipped or not styled * In general there is no need to set this value, unless you need to return something else [/DOC_MARKDOWN]**/ getMode: get_mode diff --git a/build/codemirror_grammar.min.js b/build/codemirror_grammar.min.js index 2a6f40b..5e5f337 100644 --- a/build/codemirror_grammar.min.js +++ b/build/codemirror_grammar.min.js @@ -1,9 +1,9 @@ /** * * CodeMirrorGrammar -* @version: 1.0 +* @version: 1.0.1 * * Transform a grammar specification in JSON format, into a syntax-highlight parser mode for CodeMirror * https://github.com/foo123/codemirror-grammar * -**/!function(t,n,e){"use strict";var r,l="object"==typeof module&&module.exports,o="function"==typeof define&&define.amd;l?module.exports=(module.$deps=module.$deps||{})[n]=module.$deps[n]||e.call(t,{NODE:module})||1:o&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(n)?define(n,["require","exports","module"],function(n,r,l){return e.call(t,{AMD:l})}):n in t||(t[n]=r=e.call(t,{})||1)&&o&&define(n,[],function(){return r})}(this,"CodeMirrorGrammar",function(t){"use strict";function n(t,n){var e,r=this;return(e=t.chr(r.tp,n))?[r.tk,e]:!1}function e(t,n){var e,r=this;return(e=t.chl(r.tp,n))?[r.tk,e]:!1}function r(t,n){var e,r=this;return(e=t.str(r.tp,r.p,n))?[r.tk,e]:!1}function l(t,n){var e,r=this;return(e=t.rex(r.tp,r.p,r.np,r.tg,n))?[r.tk,e]:!1}function o(t,n){var e=this;return!1!==n&&t.end(),[e.tk,""]}function u(t,n,e,r){var l=gn(n);if(Y===l)return n;if(r[t])return r[t];e=e||0;var o,u=0;return n&&n.isCharList&&(u=1,delete n.isCharList),o=sn&l?new zn(sn,t,n,e):tn===l?new zn(tn,t,n,e):X&l?u?new zn(nn,t,n,e):new zn(X,t,n,e):en&l?new zn(on,t,n,e):n,r[t]=o}function s(t,n,e,r,l,o){if(o[t])return o[t];var i,c,a,p,f,h,g,d=0,k=0,E=1;if(i=mn(n),a=i.length,1===a)g=u(t,Dn(i[0],e,l),0,o);else if(a>1){for(p=(a>>1)+1,c=0;p>=c;c++)f=gn(i[c]),h=gn(i[a-1-c]),(tn!==f||tn!==h)&&(E=0),en&f||en&h?d=1:(Bn(i[c],e)||Bn(i[a-1-c],e))&&(k=1);if(!E||r&&X&gn(r))if(!r||d||k){for(c=0;a>c;c++)i[c]=en&gn(i[c])?s(t+"_"+c,i[c],e,r,l,o):u(t+"_"+c,Dn(i[c],e,l),c,o);g=a>1?new Fn(t,i):i[0]}else g=u(t,jn(i,r),0,o);else i=i.slice().join(""),i.isCharList=1,g=u(t,i,0,o)}return o[t]=g}function i(t,n,e,r,l){if(l[t])return l[t];var o,s,i,c,a,p,f;for(c=[],a=[],o=Rn(n),s=0,i=o.length;i>s;s++)p=u(t+"_0_"+s,Dn(o[s][0],e,r),s,l),f=o[s].length>1?on!==p.tt||X!==gn(o[s][1])||Bn(o[s][1],e)?u(t+"_1_"+s,Dn(o[s][1],e,r),s,l):o[s][1]:p,c.push(p),a.push(f);return l[t]=new Vn(t,c,a)}function c(t,n,e,r){var l,o,u,s,i,a,p,f,h,g;if("undefined"==typeof t.pos?(a=new String(wn(t)),a.pos=0):a=t,1===a.length)g=""+t,n[g]||(n[g]={type:"simple",tokens:t}),t=g;else{for(l=[],o=[],u="";a.posi[0]&&(i[0]=0),2>i.length?i.push(i[0]):i[1]=i[1].length?parseInt(i[1],10)||R:R,0>i[1]&&(i[1]=0),h=o.pop(),g=""+h+["{",i[0]||"",",",isFinite(i[1])?i[1]||"":"","}"].join(""),e[g]||(e[g]={type:"group",match:[i[0],i[1]],tokens:[h]}),o.push(g)}else{if("}"===f)continue;if("|"===f)o.length>1?(g=""+o.join(" "),e[g]||(e[g]={type:"group",match:"sequence",tokens:o}),l.push(g)):o.length&&l.push(o[0]),o=[];else if("("===f)h=c(a,n,e,!0),g="("+h+")",e[g]||(e[g]=Cn(n[h]||e[h])),o.push(g);else if(")"===f){if(r)break;continue}}else u+=f;u.length&&(n[u]||e[u]||(n[u]={type:"simple",tokens:u}),o.push(u)),u="",o.length>1?(g=""+o.join(" "),e[g]||(e[g]={type:"group",match:"sequence",tokens:o}),l.push(g)):o.length&&l.push(o[0]),o=[],l.length>1?(g=""+l.join(" | "),e[g]||(e[g]={type:"group",match:"either",tokens:l}),t=g):l.length&&(t=l[0]),l=[]}return t}function a(t,n,e,r,l,o,u,h,g,d,k){var C,v,y,A,T,N,Q,q,F,K,U,Z,H,Y,J,W,tn=null;if(null===t)return new Kn(_,"EOL",t);if(""===t)return new Kn(b,"NONSPACE",t);if(!1===t||0===t)return new Kn(O,"EMPTY",t);if(en&gn(t)&&(W=t,t="NGRAM_"+W.join("_"),r[t]||(r[t]={type:"ngram",tokens:W})),t=""+t,h[t])return h[t];for(e[t]?(C=e[t],pn&gn(C)&&(C=e[t]={type:"simple",tokens:C})):C=r[t]?r[t]:t,X&gn(C)&&(C=c(C,e,r),C=e[C]||r[C]);C.extend;)Y=C.extend,J=e[Y]||r[Y],delete C.extend,J&&(pn&gn(J)&&(J={type:"simple",tokens:J}),C=vn(J,C));if("undefined"==typeof C.type&&(C.either?(C.type="group",C.match="either",C.tokens=C.either,delete C.either):C.all||C.sequence?(C.type="group",C.match="sequence",C.tokens=C.all||C.sequence,C.all?delete C.all:delete C.sequence):C.zeroOrMore?(C.type="group",C.match="zeroOrMore",C.tokens=C.zeroOrMore,delete C.zeroOrMore):C.oneOrMore?(C.type="group",C.match="oneOrMore",C.tokens=C.oneOrMore,delete C.oneOrMore):C.zeroOrOne?(C.type="group",C.match="zeroOrOne",C.tokens=C.zeroOrOne,delete C.zeroOrOne):C.type="simple"),v=C.type?V[C.type.toUpperCase().replace(xn,"")]:S,S&v){if(""===C.tokens)return tn=new Kn(b,t,t),h[t]=tn,tn;if(null===C.tokens)return tn=new Kn(_,t,t),h[t]=tn,tn;if(!1===C.tokens||0===C.tokens)return tn=new Kn(O,t,t),h[t]=tn,tn}if(C.tokens=mn(C.tokens),S&v)C.autocomplete&&f(C,t,k),C.push?(C.action||(C.action=["push",C.push]),delete C.push):C[$]("pop")&&(C.action||(C.action=["pop",C.pop]),delete C.pop),A=null,C.action&&C.action[0]&&("push"===C.action[0]?A=[E,C.action[1]]:"pop"===C.action[0]&&(A=[m,C.action[1]])),y="undefined"==typeof C.combine?"\\b":C.combine,tn=new Kn(S,t,s(t,C.tokens.slice(),n,y,o,u)),tn.ta=A,h[t]=tn;else if(w&v)M&v&&p(C,d),tn=new $n(v,t,i(t,C.tokens.slice(),n,o,u),C.multiline,C.escape,l[t+".inside"]?1:0),h[t]=tn,C.interleave&&g.push(tn.clone());else if(P&v){for(N=C.tokens.slice(),en&gn(C.match)?tn=new Un(D,t,null,C.match[0],C.match[1]):(T=z[C.match.toUpperCase()],tn=j===T?new Un(j,t,null,0,1):L===T?new Un(L,t,null,0,R):G===T?new Un(G,t,null,1,R):x&T?new Un(x,t,null):new Un(B,t,null)),h[t]=tn,Q=[],K=0,U=N.length;U>K;K++)Q=Q.concat(a(N[K],n,e,r,l,o,u,h,g,d,k));tn.set(Q)}else if(I&v){for(tn=Rn(C.tokens.slice()).slice(),q=[],K=0,U=tn.length;U>K;K++)q[K]=tn[K].slice(),tn[K]=new Un(I,t+"_NGRAM_"+K,null);for(h[t]=tn,K=0,U=tn.length;U>K;K++){for(F=q[K],Q=[],Z=0,H=F.length;H>Z;Z++)Q=Q.concat(a(F[Z],n,e,r,l,o,u,h,g,d,k));tn[K].set(Q)}}return h[t]}function p(t,n){var e,r,l,o,u,s=Rn(t.tokens.slice());for(o=0,u=s.length;u>o;o++)e=s[o][0],r=s[o].length>1?s[o][1]:s[o][0],l=s[o].length>2?s[o][2]:"",null===r?(n.line=n.line||[],n.line.push(e)):(n.block=n.block||[],n.block.push([e,r,l]))}function f(t,n,e){var r=[].concat(mn(t.tokens)).map(function(t){return{word:t,meta:n}});e.autocomplete=(e.autocomplete||[]).concat(r)}function h(t){var n,e,r,l,o,u,s,i,c,p,f,h,g,d,k,E;if(t.__parsed)return t;for(f={},h={},g={},k={},E={},d=[],t=Cn(t),n=t.RegExpID||null,t.RegExpID=null,delete t.RegExpID,u=t.Lex||{},t.Lex=null,delete t.Lex,s=t.Syntax||{},t.Syntax=null,delete t.Syntax,o=t.Style||{},l=t.Parser||[],r=l.length,e=[],i=0;r>i;i++)c=l[i],p=a(c,n,u,s,o,f,h,g,d,k,E)||null,p&&(en&gn(p)?e=e.concat(p):e.push(p));return t.Parser=e,t.cTokens=d,t.Style=o,t.Comments=k,t.Keywords=E,t.Extra=t.Extra||{},t.__parsed=1,t}function g(t,n){var e=new Jn(h(t),{DEFAULT:n||d,ERROR:k}),r=function(t,n){return{startState:function(){return new Hn},copyState:function(t){return t.clone()},token:function(t,n){return e.getToken(t,n)},indent:function(r,l,o){return e.indent(r,l,o,t,n)},lineComment:e.LC,blockCommentStart:e.BCS,blockCommentEnd:e.BCE,blockCommentContinue:e.BCC,blockCommentLead:e.BCL,electricChars:e.Extra.electricChars||!1,fold:e.Extra.fold||!1}};return r.supportGrammarAnnotations=!1,r.validator=function(t){if(!r.supportGrammarAnnotations||!t||!t.length)return[];var n,l,o,u,s,i=[],c=e.parse(t),a=c.length;for(u=0;a>u;u++)if(n=c[u],n&&n.length)for(s=0,o=0;oo;o++)if(e=s[o],rn===gn(e))for(l in e)e[$](l)&&e[U](l)&&(r=e[l],u=gn(r),n[l]=Y&u?0+r:pn&u?r.slice():r);return n},kn=Object.create,En=function(t,n){var e,r=arguments.length,l="constructor";return 0===r?(t=Object,n={}):1===r?(n=t||{},t=Object):(t=t||Object,n=n||{}),n[$](l)||(n[l]=function(){}),e=n[l],delete n[l],e[K]=dn(kn(t[K]),n),e[K][l]=e,e},mn=function(t,n){return n||en!==gn(t)?[t]:t},Rn=function(t,n){return t=mn(t,n),(n||en!==gn(t[0]))&&(t=[t]),t},Cn=function(t){var n,e=gn(t);if(!(fn&e))return t;var r,l={};for(r in t)t[$](r)&&t[U](r)&&(n=gn(t[r]),l[r]=rn&n?Cn(t[r]):pn&n?t[r].slice():t[r]);return l},vn=function(){var t=arguments,n=t.length;if(1>n)return null;if(2>n)return Cn(t[0]);var e,r,l,o,u=t[0],s=Cn(u);for(n--,r=1;n>r;r++)if(e=t[r])for(l in e)e[$](l)&&e[U](l)&&(u[$](l)&&u[U](l)?(o=gn(u[l]),rn&~X&o&&(s[l]=vn(u[l],e[l]))):s[l]=Cn(e[l]));return s},yn=/([.*+?^${}()|[\]\/\\\-])/g,Sn=function(t){return t.replace(yn,"\\$1")},_n=/\$(\d{1,2})/g,bn=function(t,n){var e,r,l,o;for(o=function(t,e){return n[1+parseInt(e,10)]},e=t.split("$$"),l=e.length,r=0;l>r;r++)e[r]=e[r].replace(_n,o);return e.join("$")},On=/^\s+|\s+$/g,wn=String[K].trim?function(t){return t.trim()}:function(t){return t.replace(On,"")},An=function(t,n){return n.length-t.length},Mn=/\r\n|\r|\n/g,xn=/[\-_]/g,Tn=/^([{}()*+?|'"]|\s)/,Bn=function(t,n){return X&gn(n)&&X&gn(t)&&n.length&&n.length<=t.length&&n==t.substr(0,n.length)},Dn=function(t,n,e){if(!t||Y===gn(t))return t;var r,l=n?n.length||0:0;if(l&&n==t.substr(0,l)){var o,u,s,i,r,c,a=t.substr(l),p=a[0],f="";for(r=a.length;r--&&(c=a[r],p!=c);)"i"==c.toLowerCase()&&(f="i");return o=a.substring(1,r),u="^("+o+")",e[u]||(s=new RegExp(u,f),i={peek:null,negativepeek:null},e[u]=[s,i]),e[u]}return t},jn=function(t,n){var e={},r="",l=gn(n);(X===l||tn===l)&&(r=n);var o=t.sort(An).map(function(t){return e[t.charAt(0)]=1,Sn(t)}).join("|");return[new RegExp("^("+o+")"+r),{peek:e,negativepeek:null},1]},Ln=0,Gn=function(){return++Ln},Pn=function(t){return[t||"uuid",++Ln,(new Date).getTime()].join("_")},In=(!("undefined"==typeof global||"[object global]"!==H.call(global)),Math.max),Nn=/^[\s\u00a0]+/,Qn=/[^\s\u00a0]/,qn=En({constructor:function(t){var n=this;n._=null,n.s=t?""+t:"",n.start=n.pos=0,n.lCP=n.lCV=0,n.lS=0},_:null,s:"",start:0,pos:0,lCP:0,lCV:0,lS:0,dispose:function(){var t=this;return t._=null,t.s=null,t.start=null,t.pos=null,t.lCP=null,t.lCV=null,t.lS=null,t},toString:function(){return this.s},sol:function(){return 0===this.pos},eol:function(){return this.pos>=this.s.length},chr:function(t,n){var e=this,r=e.s.charAt(e.pos)||null;return r&&t===r?(!1!==n&&(e.pos+=1,e._&&(e._.pos=e.pos)),r):!1},chl:function(t,n){var e=this,r=e.s.charAt(e.pos)||null;return r&&-10?!1:(!1!==l&&(u.pos+=o[r||0].length,u._&&(u._.pos=u.pos)),o)},spc:function(t){var n,e=this,r=e.pos,l=e.s.slice(r);return(n=l.match(Nn))?(!1!==t&&(e.pos+=n[0].length,e._&&(e._.pos=e.pos)),1):0},end:function(){var t=this;return t.pos=t.s.length,t._&&(t._.pos=t.pos),t},nxt:function(){var t,n=this,e=n.s;return n.poso;++o)u+=" "==t.charAt(o)?e-u%e:1;return u},qn._=function(t){var n=new qn;return n._=t,n.s=""+t.string,n.start=t.start,n.pos=t.pos,n.lCP=t.lastColumnPos,n.lCV=t.lastColumnValue,n.lS=t.lineStart,n};var zn,Vn,Fn,Kn,$n,Un,Zn=En({constructor:function(t){this._=t||[]},_:null,dispose:function(){var t=this;return t._=null,t},toString:function(){return this._.slice().reverse().join("\n")},clone:function(){return new Zn(this._.slice())},isEmpty:function(){return 0>=this._.length},pos:function(){return this._.length},peek:function(t){var n=this,e=n._;if(t=arguments.length?t:-1,e.length){if(0>t&&0<=e.length+t)return e[e.length+t];if(t>=0&&te;e++)if(r=o[e].get(t,n))return s?[e,r[1]]:r;return!1}}),Vn=En(zn,{constructor:function(t,n,e){var r=this;r.mt=y,r.tn=t,r.s=new Fn(r.tn+"_Start",n,!1),r.e=e},s:null,e:null,get:function(t,n){var e,r=this,l=r.s,o=r.e;if(e=l.get(t,n)){var u,s=o[e[0]],i=gn(s),c=l.ms[e[0]].tt;return on===c&&(Y===i?(u=e[1][s+1],s=new zn(u.length>1?X:tn,r.tn+"_End",u)):X===i&&(u=bn(s,e[1]),s=new zn(u.length>1?X:tn,r.tn+"_End",u))),s}return!1}}),Kn=En({constructor:function(t,n,e){var r=this;r.tt=t||S,r.id=n,r.tk=e,r.REQ=0,r.ERR=0,r.ACTER=0,r.MSG=null,r.CLONE=["tk"]},sID:null,id:null,tt:null,tk:null,ta:null,REQ:0,ERR:0,ACTER:0,MSG:null,CLONE:null,act:function(t,n){var e,r,l=this,o=l.ta||null,u=n.data;if(o)if(e=o[0],r=o[1],m===e)if(r){if(t&&(r=Y===gn(r)?t[1][r]:bn(r,t[1])),u.isEmpty()||r!==u.peek())return l.MSG='Token "'+r+'" No Match',u.pop(),1;u.pop()}else u.pop();else E===e&&r&&(t&&(r=Y===gn(r)?t[1][r]:bn(r,t[1])),u.push(r));return 0},get:function(t,n){var e=this,r=e.ta,l=e.tk,o=e.tt,u=e.id,s=null;if(e.MSG=null,e.ACTER=0,O===o)return e.ERR=0,e.REQ=0,!0;if(_===o){if(t.spc(),t.eol())return u}else if(b===o)e.ERR=e.REQ&&t.spc()&&!t.eol()?1:0,e.REQ=0;else if(s=l.get(t))return r&&(e.ACTER=e.act(s,n)),u;return!1},req:function(t){return this.REQ=!!t,this},err:function(){var t=this;return t.MSG?t.MSG:t.REQ?'Token "'+t.id+'" Expected':'Syntax Error: "'+t.id+'"'},clone:function(){var t,n,e,r=this,l=r.CLONE;if(t=new r.constructor,t.tt=r.tt,t.id=r.id,t.ta=r.ta?r.ta.slice():r.ta,l&&l.length)for(n=0,e=l.length;e>n;n++)t[l[n]]=r[l[n]];return t},toString:function(){var t=this;return["[","Tokenizer: ",t.id,", Matcher: ",t.tk?t.tk.toString():null,"]"].join("")}}),$n=En(Kn,{constructor:function(t,n,e,r,l,o){var u=this;u.tt=t,u.id=n,u.tk=e,u.REQ=0,u.ERR=0,u.ACTER=0,u.MSG=null,u.mline="undefined"==typeof r?1:r,u.esc=l||"\\",u.inter=o,u.CLONE=["tk","mline","esc","inter"]},inter:0,mline:0,esc:null,get:function(t,n){var e,r,l,o,u,s,i,c,a,p=this,f=0,h=0,g="",d=p.mline,k=p.tk,E=p.id,m=p.tt,R=p.inter,C=R?E+".inside":E,v=0,y=A===m,S=p.esc;if(p.MSG=null,p.ACTER=0,M===m&&(p.REQ=0),u=0,n.inBlock===E?(h=1,e=n.endBlock,u=1,s=C):!n.inBlock&&(e=k.get(t))&&(h=1,n.inBlock=E,n.endBlock=e,s=E),h){if(l=n.stack.pos(),o=sn===e.tt,R){if(u&&o&&t.sol())return p.REQ=0,n.inBlock=null,n.endBlock=null,!1;if(!u)return n.stack.pushAt(l,p.clone(),"sID",E),s}if(f=e.get(t),r=d,a=0,f)s=o?C:E;else for(c=t.pos;!t.eol();){if(i=t.pos,!(y&&v||!e.get(t))){R&&t.pos>i&&i>c?(s=C,t.bck2(i),a=1):(s=E,f=1);break}g=t.nxt(),v=!v&&g==S}return r=d||y&&v,f||!r&&!a?(n.inBlock=null,n.endBlock=null):n.stack.pushAt(l,p.clone(),"sID",E),s}return!1}}),Un=En(Kn,{constructor:function(t,n,e,r,l){var o=this;o.tt=t?t:D,o.id=n||null,o.tk=null,o.ts=null,o.REQ=0,o.ERR=0,o.ACTER=0,o.MSG=null,o.min=r||0,o.max=l||R,o.found=0,o.CLONE=["ts","min","max","found"],e&&o.set(e)},ts:null,min:0,max:1,found:0,set:function(t){return t&&(this.ts=mn(t)),this},get:function(t,n){var e,r,l,o,u,s,i,c,a,p,f,h,g=this,d=g.tt,k=g.ts,E=k.length;if(x===d){for(i=0,c=0,g.REQ=1,g.ERR=0,g.ACTER=0,g.MSG=null,a=t.pos,e=0;E>e;e++){if(r=k[e].clone().req(1),l=r.get(t,n),i+=r.REQ?1:0,!1!==l)return g.ACTER=r.ACTER,g.MSG=r.MSG,l;r.ERR&&(c++,t.bck2(a))}return g.REQ=i>0,g.ERR=E==c&&i>0,!1}if(N&d){if(h=d&B?1:0,g.REQ=h,g.ERR=0,g.ACTER=0,g.MSG=null,a=t.pos,p=n.stack.pos(),r=k[0].clone().req(h),l=r.get(t,n),f=g.id+"_"+Gn(),!1!==l){if(!0!==l)for(var e=E-1;e>0;e--)n.stack.pushAt(p+E-e-1,k[e].clone().req(1),"sID",f);return g.ACTER=r.ACTER,g.MSG=r.MSG,l}return r.ERR?(g.ERR=h,t.bck2(a)):h&&r.REQ&&(g.ERR=1),!1}for(i=0,o=g.found,u=g.min,s=g.max,g.ERR=0,g.REQ=0,g.ACTER=0,g.MSG=null,a=t.pos,p=n.stack.pos(),f=g.id+"_"+Gn(),e=0;E>e;e++){if(r=k[e].clone().req(1),l=r.get(t,n),!1!==l){if(++o,s>=o)return g.found=o,n.stack.pushAt(p,g.clone(),"sID",f),g.found=0,g.ACTER=r.ACTER,g.MSG=r.MSG,l;break}r.REQ&&i++,r.ERR&&t.bck2(a)}return g.REQ=u>o,g.ERR=o>s||u>o&&i>0,!1}});var Yn=CodeMirror||{Pass:{toString:function(){return"CodeMirror.Pass"}}};d=null,k="error";{var Jn=En({constructor:function(t,n){var e=this;e.Extra=t.Extra||{},e.LC=t.Comments.line?t.Comments.line[0]:null,e.BCS=t.Comments.block?t.Comments.block[0][0]:null,e.BCE=t.Comments.block?t.Comments.block[0][1]:null,e.BCC=e.BCL=t.Comments.block?t.Comments.block[0][2]:null,e.DEF=n.DEFAULT,e.ERR=t.Style.error||n.ERROR,e.Keywords=t.Keywords.autocomplete||null,e.Tokens=t.Parser||[],e.cTokens=t.cTokens.length?t.cTokens:null,e.Style=t.Style},Extra:null,LC:null,BCS:null,BCE:null,BCL:null,BCC:null,ERR:null,DEF:null,Keywords:null,cTokens:null,Tokens:null,Style:null,dispose:function(){var t=this;return t.Extra=null,t.LC=null,t.BCS=null,t.BCE=null,t.BCL=null,t.BCC=null,t.ERR=null,t.DEF=null,t.Keywords=null,t.cTokens=null,t.Tokens=null,t.Style=null,t},parse:function(t){t=t||"";var n,e,r,l,o=this,u=t.split(Mn),s=u.length,i=[];for(r=new Hn,r.parseAll=1,n=0;s>n;n++){for(l=new qn(u[n]),e=[];!l.eol();)e.push(o.getToken(l,r));i.push(e)}return i},getToken:function(t,n){var e,r,l,o,u,s=this,i=s.cTokens,c=s.Tokens,a=c.length,p=!!n.parseAll,f=s.Style,h=s.DEF,g=s.ERR;if(t=p?t:qn._(t),u=n.stack,t.sol()&&!u.isEmpty()&&_===u.peek().tt&&u.pop(),(u.isEmpty()||b!==u.peek().tt)&&t.spc())return p?{value:t.cur(1),type:h,error:null}:n.t=h;for(;!u.isEmpty()&&!t.eol();){if(i)for(r=0;re;e++)if(l=c[e],o=l.get(t,n),!1!==o){if(!0!==o)return o=f[o]||h,l.ACTER?(u.empty("sID",l.sID),n.t=o=g,p?{value:t.cur(1),type:g,error:l.err()}:n.t=g):p?{value:t.cur(1),type:o,error:null}:n.t=o}else if(l.ERR||l.REQ)return u.empty("sID",l.sID),t.nxt(),n.t=o=g,p?{value:t.cur(1),type:g,error:l.err()}:n.t=g;return t.nxt(),n.t=h,p?{value:t.cur(1),type:h,error:null}:n.t=h},indent:function(t,n,e,r){var l=(r.indentUnit||4,Yn.Pass);return l}});t.CodeMirrorGrammar={VERSION:"1.0",extend:vn,parse:h,getMode:g}}return t.CodeMirrorGrammar}); \ No newline at end of file +**/!function(t,n,e){"use strict";var r,l="object"==typeof module&&module.exports,o="function"==typeof define&&define.amd;l?module.exports=(module.$deps=module.$deps||{})[n]=module.$deps[n]||e.call(t,{NODE:module})||1:o&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(n)?define(n,["require","exports","module"],function(n,r,l){return e.call(t,{AMD:l})}):n in t||(t[n]=r=e.call(t,{})||1)&&o&&define(n,[],function(){return r})}(this,"CodeMirrorGrammar",function(t){"use strict";function n(t,n){var e,r=this;return(e=t.chr(r.tp,n))?[r.tk,e]:!1}function e(t,n){var e,r=this;return(e=t.chl(r.tp,n))?[r.tk,e]:!1}function r(t,n){var e,r=this;return(e=t.str(r.tp,r.p,n))?[r.tk,e]:!1}function l(t,n){var e,r=this;return(e=t.rex(r.tp,r.p,r.np,r.tg,n))?[r.tk,e]:!1}function o(t,n){var e=this;return!1!==n&&t.end(),[e.tk,""]}function u(t,n,e,r){var l=gn(n);if(Y===l)return n;if(r[t])return r[t];e=e||0;var o,u=0;return n&&n.isCharList&&(u=1,delete n.isCharList),o=sn&l?new zn(sn,t,n,e):tn===l?new zn(tn,t,n,e):X&l?u?new zn(nn,t,n,e):new zn(X,t,n,e):en&l?new zn(on,t,n,e):n,r[t]=o}function s(t,n,e,r,l,o){if(o[t])return o[t];var i,c,a,p,f,h,g,k=0,m=0,d=1;if(i=En(n),a=i.length,1===a)g=u(t,Dn(i[0],e,l),0,o);else if(a>1){for(p=(a>>1)+1,c=0;p>=c;c++)f=gn(i[c]),h=gn(i[a-1-c]),(tn!==f||tn!==h)&&(d=0),en&f||en&h?k=1:(Bn(i[c],e)||Bn(i[a-1-c],e))&&(m=1);if(!d||r&&X&gn(r))if(!r||k||m){for(c=0;a>c;c++)i[c]=en&gn(i[c])?s(t+"_"+c,i[c],e,r,l,o):u(t+"_"+c,Dn(i[c],e,l),c,o);g=a>1?new Fn(t,i):i[0]}else g=u(t,jn(i,r),0,o);else i=i.slice().join(""),i.isCharList=1,g=u(t,i,0,o)}return o[t]=g}function i(t,n,e,r,l){if(l[t])return l[t];var o,s,i,c,a,p,f;for(c=[],a=[],o=Rn(n),s=0,i=o.length;i>s;s++)p=u(t+"_0_"+s,Dn(o[s][0],e,r),s,l),f=o[s].length>1?on!==p.tt||X!==gn(o[s][1])||Bn(o[s][1],e)?u(t+"_1_"+s,Dn(o[s][1],e,r),s,l):o[s][1]:p,c.push(p),a.push(f);return l[t]=new Vn(t,c,a)}function c(t,n,e){var r,l,o,u,s,i,c,a,p,f,h,g;if(i=new String(wn(t)),i.pos=0,1===i.length)f=""+t,n[f]||(n[f]={type:"simple",tokens:t}),t=f;else{for(r=[],l=[],o="",h=[];i.poss[0]&&(s[0]=0),2>s.length?s.push(s[0]):s[1]=s[1].length?parseInt(s[1],10)||R:R,0>s[1]&&(s[1]=0),p=l.pop(),f=""+p+["{",s[0]||"",",",isFinite(s[1])?s[1]||"":"","}"].join(""),e[f]||(e[f]={type:"group",match:[s[0],s[1]],tokens:[p]}),l.push(f)}else{if("}"===a)continue;"|"===a?(l.length>1?(f=""+l.join(" "),e[f]||(e[f]={type:"group",match:"sequence",tokens:l}),r.push(f)):l.length&&r.push(l[0]),l=[]):"("===a?(h.push([l,r,o]),l=[],r=[],o=""):")"===a&&(l.length>1?(f=""+l.join(" "),e[f]||(e[f]={type:"group",match:"sequence",tokens:l}),r.push(f)):l.length&&r.push(l[0]),l=[],r.length>1?(f=""+r.join(" | "),e[f]||(e[f]={type:"group",match:"either",tokens:r})):r.length&&(f=r[0]),r=[],g=h.pop(),l=g[0],r=g[1],o=g[2],p=f,f="("+p+")",e[f]||(e[f]=Cn(n[p]||e[p])),l.push(f))}else o+=a;o.length&&(n[o]||e[o]||(n[o]={type:"simple",tokens:o}),l.push(o)),o="",l.length>1?(f=""+l.join(" "),e[f]||(e[f]={type:"group",match:"sequence",tokens:l}),r.push(f)):l.length&&r.push(l[0]),l=[],r.length>1?(f=""+r.join(" | "),e[f]||(e[f]={type:"group",match:"either",tokens:r}),t=f):r.length&&(t=r[0]),r=[]}return t}function a(t,n,e,r,l,o,u,h,g,k,m){var C,v,y,A,T,N,Q,q,F,K,U,Z,H,Y,J,W,tn=null;if(null===t)return new Kn(_,"EOL",t);if(""===t)return new Kn(b,"NONSPACE",t);if(!1===t||0===t)return new Kn(O,"EMPTY",t);if(en&gn(t)&&(W=t,t="NGRAM_"+W.join("_"),r[t]||(r[t]={type:"ngram",tokens:W})),t=""+t,h[t])return h[t];for(e[t]?(C=e[t],pn&gn(C)&&(C=e[t]={type:"simple",tokens:C})):C=r[t]?r[t]:t,X&gn(C)&&(C=c(C,e,r),C=e[C]||r[C]);C.extend;)Y=C.extend,J=e[Y]||r[Y],delete C.extend,J&&(pn&gn(J)&&(J={type:"simple",tokens:J}),C=vn(J,C));if("undefined"==typeof C.type&&(C.all||C.sequence?(C.type="group",C.match="sequence",C.tokens=C.all||C.sequence,C.all?delete C.all:delete C.sequence):C.either?(C.type="group",C.match="either",C.tokens=C.either,delete C.either):C.zeroOrMore?(C.type="group",C.match="zeroOrMore",C.tokens=C.zeroOrMore,delete C.zeroOrMore):C.oneOrMore?(C.type="group",C.match="oneOrMore",C.tokens=C.oneOrMore,delete C.oneOrMore):C.zeroOrOne?(C.type="group",C.match="zeroOrOne",C.tokens=C.zeroOrOne,delete C.zeroOrOne):C.comment?(C.type="comment",C.tokens=C.comment,delete C.comment):C.block?(C.type="block",C.tokens=C.block,delete C.block):C["escaped-block"]?(C.type="escaped-block",C.tokens=C["escaped-block"],delete C["escaped-block"]):C.simple?(C.type="simple",C.tokens=C.simple,delete C.simple):C.type="simple"),v=C.type?V[C.type.toUpperCase().replace(xn,"")]:S,S&v){if(""===C.tokens)return tn=new Kn(b,t,t),h[t]=tn,tn;if(null===C.tokens)return tn=new Kn(_,t,t),h[t]=tn,tn;if(!1===C.tokens||0===C.tokens)return tn=new Kn(O,t,t),h[t]=tn,tn}if(C.tokens=En(C.tokens),S&v)C.autocomplete&&f(C,t,m),C.push?(C.action||(C.action=["push",C.push]),delete C.push):C[$]("pop")&&(C.action||(C.action=["pop",C.pop]),delete C.pop),A=null,C.action&&C.action[0]&&("push"===C.action[0]?A=[d,C.action[1]]:"pop"===C.action[0]&&(A=[E,C.action[1]])),y="undefined"==typeof C.combine?"\\b":C.combine,tn=new Kn(S,t,s(t,C.tokens.slice(),n,y,o,u)),tn.ta=A,h[t]=tn;else if(w&v)M&v&&p(C,k),tn=new $n(v,t,i(t,C.tokens.slice(),n,o,u),C.multiline,C.escape,l[t+".inside"]?1:0),h[t]=tn,C.interleave&&g.push(tn.clone());else if(P&v){for(N=C.tokens.slice(),en&gn(C.match)?tn=new Un(D,t,null,C.match[0],C.match[1]):(T=z[C.match.toUpperCase()],tn=j===T?new Un(j,t,null,0,1):L===T?new Un(L,t,null,0,R):G===T?new Un(G,t,null,1,R):x&T?new Un(x,t,null):new Un(B,t,null)),h[t]=tn,Q=[],K=0,U=N.length;U>K;K++)Q=Q.concat(a(N[K],n,e,r,l,o,u,h,g,k,m));tn.set(Q)}else if(I&v){for(tn=Rn(C.tokens.slice()).slice(),q=[],K=0,U=tn.length;U>K;K++)q[K]=tn[K].slice(),tn[K]=new Un(I,t+"_NGRAM_"+K,null);for(h[t]=tn,K=0,U=tn.length;U>K;K++){for(F=q[K],Q=[],Z=0,H=F.length;H>Z;Z++)Q=Q.concat(a(F[Z],n,e,r,l,o,u,h,g,k,m));tn[K].set(Q)}}return h[t]}function p(t,n){var e,r,l,o,u,s=Rn(t.tokens.slice());for(o=0,u=s.length;u>o;o++)e=s[o][0],r=s[o].length>1?s[o][1]:s[o][0],l=s[o].length>2?s[o][2]:"",null===r?(n.line=n.line||[],n.line.push(e)):(n.block=n.block||[],n.block.push([e,r,l]))}function f(t,n,e){var r=[].concat(En(t.tokens)).map(function(t){return{word:t,meta:n}});e.autocomplete=(e.autocomplete||[]).concat(r)}function h(t){var n,e,r,l,o,u,s,i,c,p,f,h,g,k,m,d;if(t.__parsed)return t;for(f={},h={},g={},m={},d={},k=[],t=Cn(t),n=t.RegExpID||null,t.RegExpID=null,delete t.RegExpID,u=t.Lex||{},t.Lex=null,delete t.Lex,s=t.Syntax||{},t.Syntax=null,delete t.Syntax,o=t.Style||{},l=t.Parser||[],r=l.length,e=[],i=0;r>i;i++)c=l[i],p=a(c,n,u,s,o,f,h,g,k,m,d)||null,p&&(en&gn(p)?e=e.concat(p):e.push(p));return t.Parser=e,t.cTokens=k,t.Style=o,t.Comments=m,t.Keywords=d,t.Extra=t.Extra||{},t.__parsed=1,t}function g(t,n){var e=new Jn(h(t),{DEFAULT:n||k,ERROR:m}),r=function(t,n){return{startState:function(){return new Hn},copyState:function(t){return t.clone()},token:function(t,n){return e.getToken(t,n)},indent:function(r,l,o){return e.indent(r,l,o,t,n)},lineComment:e.LC,blockCommentStart:e.BCS,blockCommentEnd:e.BCE,blockCommentContinue:e.BCC,blockCommentLead:e.BCL,electricChars:e.Extra.electricChars||!1,fold:e.Extra.fold||!1}};return r.supportGrammarAnnotations=!1,r.validator=function(t){if(!r.supportGrammarAnnotations||!t||!t.length)return[];var n,l,o,u,s,i=[],c=e.parse(t),a=c.length;for(u=0;a>u;u++)if(n=c[u],n&&n.length)for(s=0,o=0;oo;o++)if(e=s[o],rn===gn(e))for(l in e)e[$](l)&&e[U](l)&&(r=e[l],u=gn(r),n[l]=Y&u?0+r:pn&u?r.slice():r);return n},mn=Object.create,dn=function(t,n){var e,r=arguments.length,l="constructor";return 0===r?(t=Object,n={}):1===r?(n=t||{},t=Object):(t=t||Object,n=n||{}),n[$](l)||(n[l]=function(){}),e=n[l],delete n[l],e[K]=kn(mn(t[K]),n),e[K][l]=e,e},En=function(t,n){return n||en!==gn(t)?[t]:t},Rn=function(t,n){return t=En(t,n),(n||en!==gn(t[0]))&&(t=[t]),t},Cn=function(t){var n,e=gn(t);if(!(fn&e))return t;var r,l={};for(r in t)t[$](r)&&t[U](r)&&(n=gn(t[r]),l[r]=rn&n?Cn(t[r]):pn&n?t[r].slice():t[r]);return l},vn=function(){var t=arguments,n=t.length;if(1>n)return null;if(2>n)return Cn(t[0]);var e,r,l,o,u=t[0],s=Cn(u);for(n--,r=1;n>r;r++)if(e=t[r])for(l in e)e[$](l)&&e[U](l)&&(u[$](l)&&u[U](l)?(o=gn(u[l]),rn&~X&o&&(s[l]=vn(u[l],e[l]))):s[l]=Cn(e[l]));return s},yn=/([.*+?^${}()|[\]\/\\\-])/g,Sn=function(t){return t.replace(yn,"\\$1")},_n=/\$(\d{1,2})/g,bn=function(t,n){var e,r,l,o;for(o=function(t,e){return n[1+parseInt(e,10)]},e=t.split("$$"),l=e.length,r=0;l>r;r++)e[r]=e[r].replace(_n,o);return e.join("$")},On=/^\s+|\s+$/g,wn=String[K].trim?function(t){return t.trim()}:function(t){return t.replace(On,"")},An=function(t,n){return n.length-t.length},Mn=/\r\n|\r|\n/g,xn=/[\-_]/g,Tn=/^([{}()*+?|'"]|\s)/,Bn=function(t,n){return X&gn(n)&&X&gn(t)&&n.length&&n.length<=t.length&&n==t.substr(0,n.length)},Dn=function(t,n,e){if(!t||Y===gn(t))return t;var r,l=n?n.length||0:0;if(l&&n==t.substr(0,l)){var o,u,s,i,r,c,a=t.substr(l),p=a[0],f="";for(r=a.length;r--&&(c=a[r],p!=c);)"i"==c.toLowerCase()&&(f="i");return o=a.substring(1,r),u="^("+o+")",e[u]||(s=new RegExp(u,f),i={peek:null,negativepeek:null},e[u]=[s,i]),e[u]}return t},jn=function(t,n){var e={},r="",l=gn(n);(X===l||tn===l)&&(r=n);var o=t.sort(An).map(function(t){return e[t.charAt(0)]=1,Sn(t)}).join("|");return[new RegExp("^("+o+")"+r),{peek:e,negativepeek:null},1]},Ln=0,Gn=function(){return++Ln},Pn=function(t){return[t||"uuid",++Ln,(new Date).getTime()].join("_")},In=(!("undefined"==typeof global||"[object global]"!==H.call(global)),Math.max),Nn=/^[\s\u00a0]+/,Qn=/[^\s\u00a0]/,qn=dn({constructor:function(t){var n=this;n._=null,n.s=t?""+t:"",n.start=n.pos=0,n.lCP=n.lCV=0,n.lS=0},_:null,s:"",start:0,pos:0,lCP:0,lCV:0,lS:0,dispose:function(){var t=this;return t._=null,t.s=null,t.start=null,t.pos=null,t.lCP=null,t.lCV=null,t.lS=null,t},toString:function(){return this.s},sol:function(){return 0===this.pos},eol:function(){return this.pos>=this.s.length},chr:function(t,n){var e=this,r=e.s.charAt(e.pos)||null;return r&&t===r?(!1!==n&&(e.pos+=1,e._&&(e._.pos=e.pos)),r):!1},chl:function(t,n){var e=this,r=e.s.charAt(e.pos)||null;return r&&-10?!1:(!1!==l&&(u.pos+=o[r||0].length,u._&&(u._.pos=u.pos)),o)},spc:function(t){var n,e=this,r=e.pos,l=e.s.slice(r);return(n=l.match(Nn))?(!1!==t&&(e.pos+=n[0].length,e._&&(e._.pos=e.pos)),1):0},end:function(){var t=this;return t.pos=t.s.length,t._&&(t._.pos=t.pos),t},nxt:function(){var t,n=this,e=n.s;return n.poso;++o)u+=" "==t.charAt(o)?e-u%e:1;return u},qn._=function(t){var n=new qn;return n._=t,n.s=""+t.string,n.start=t.start,n.pos=t.pos,n.lCP=t.lastColumnPos,n.lCV=t.lastColumnValue,n.lS=t.lineStart,n};var zn,Vn,Fn,Kn,$n,Un,Zn=dn({constructor:function(t){this._=t||[]},_:null,dispose:function(){var t=this;return t._=null,t},toString:function(){return this._.slice().reverse().join("\n")},clone:function(){return new Zn(this._.slice())},isEmpty:function(){return 0>=this._.length},pos:function(){return this._.length},peek:function(t){var n=this,e=n._;if(t=arguments.length?t:-1,e.length){if(0>t&&0<=e.length+t)return e[e.length+t];if(t>=0&&te;e++)if(r=o[e].get(t,n))return s?[e,r[1]]:r;return!1}}),Vn=dn(zn,{constructor:function(t,n,e){var r=this;r.mt=y,r.tn=t,r.s=new Fn(r.tn+"_Start",n,!1),r.e=e},s:null,e:null,get:function(t,n){var e,r=this,l=r.s,o=r.e;if(e=l.get(t,n)){var u,s=o[e[0]],i=gn(s),c=l.ms[e[0]].tt;return on===c&&(Y===i?(u=e[1][s+1],s=new zn(u.length>1?X:tn,r.tn+"_End",u)):X===i&&(u=bn(s,e[1]),s=new zn(u.length>1?X:tn,r.tn+"_End",u))),s}return!1}}),Kn=dn({constructor:function(t,n,e){var r=this;r.tt=t||S,r.id=n,r.tk=e,r.REQ=0,r.ERR=0,r.ACTER=0,r.MSG=null,r.CLONE=["tk"]},sID:null,id:null,tt:null,tk:null,ta:null,REQ:0,ERR:0,ACTER:0,MSG:null,CLONE:null,act:function(t,n){var e,r,l=this,o=l.ta||null,u=n.data;if(o)if(e=o[0],r=o[1],E===e)if(r){if(t&&(r=Y===gn(r)?t[1][r]:bn(r,t[1])),u.isEmpty()||r!==u.peek())return l.MSG='Token "'+r+'" No Match',u.pop(),1;u.pop()}else u.pop();else d===e&&r&&(t&&(r=Y===gn(r)?t[1][r]:bn(r,t[1])),u.push(r));return 0},get:function(t,n){var e=this,r=e.ta,l=e.tk,o=e.tt,u=e.id,s=null;if(e.MSG=null,e.ACTER=0,O===o)return e.ERR=0,e.REQ=0,!0;if(_===o){if(t.spc(),t.eol())return u}else if(b===o)e.ERR=e.REQ&&t.spc()&&!t.eol()?1:0,e.REQ=0;else if(s=l.get(t))return r&&(e.ACTER=e.act(s,n)),u;return!1},req:function(t){return this.REQ=!!t,this},err:function(){var t=this;return t.MSG?t.MSG:t.REQ?'Token "'+t.id+'" Expected':'Syntax Error: "'+t.id+'"'},clone:function(){var t,n,e,r=this,l=r.CLONE;if(t=new r.constructor,t.tt=r.tt,t.id=r.id,t.ta=r.ta?r.ta.slice():r.ta,l&&l.length)for(n=0,e=l.length;e>n;n++)t[l[n]]=r[l[n]];return t},toString:function(){var t=this;return["[","Tokenizer: ",t.id,", Matcher: ",t.tk?t.tk.toString():null,"]"].join("")}}),$n=dn(Kn,{constructor:function(t,n,e,r,l,o){var u=this;u.tt=t,u.id=n,u.tk=e,u.REQ=0,u.ERR=0,u.ACTER=0,u.MSG=null,u.mline="undefined"==typeof r?1:r,u.esc=l||"\\",u.inter=o,u.CLONE=["tk","mline","esc","inter"]},inter:0,mline:0,esc:null,get:function(t,n){var e,r,l,o,u,s,i,c,a,p=this,f=0,h=0,g="",k=p.mline,m=p.tk,d=p.id,E=p.tt,R=p.inter,C=R?d+".inside":d,v=0,y=A===E,S=p.esc;if(p.MSG=null,p.ACTER=0,M===E&&(p.REQ=0),u=0,n.inBlock===d?(h=1,e=n.endBlock,u=1,s=C):!n.inBlock&&(e=m.get(t))&&(h=1,n.inBlock=d,n.endBlock=e,s=d),h){if(l=n.stack.pos(),o=sn===e.tt,R){if(u&&o&&t.sol())return p.REQ=0,n.inBlock=null,n.endBlock=null,!1;if(!u)return n.stack.pushAt(l,p.clone(),"sID",d),s}if(f=e.get(t),r=k,a=0,f)s=o?C:d;else for(c=t.pos;!t.eol();){if(i=t.pos,!(y&&v||!e.get(t))){R&&t.pos>i&&i>c?(s=C,t.bck2(i),a=1):(s=d,f=1);break}g=t.nxt(),v=!v&&g==S}return r=k||y&&v,f||!r&&!a?(n.inBlock=null,n.endBlock=null):n.stack.pushAt(l,p.clone(),"sID",d),s}return!1}}),Un=dn(Kn,{constructor:function(t,n,e,r,l){var o=this;o.tt=t?t:D,o.id=n||null,o.tk=null,o.ts=null,o.REQ=0,o.ERR=0,o.ACTER=0,o.MSG=null,o.min=r||0,o.max=l||R,o.found=0,o.CLONE=["ts","min","max","found"],e&&o.set(e)},ts:null,min:0,max:1,found:0,set:function(t){return t&&(this.ts=En(t)),this},get:function(t,n){var e,r,l,o,u,s,i,c,a,p,f,h,g=this,k=g.tt,m=g.ts,d=m.length;if(x===k){for(i=0,c=0,g.REQ=1,g.ERR=0,g.ACTER=0,g.MSG=null,a=t.pos,e=0;d>e;e++){if(r=m[e].clone().req(1),l=r.get(t,n),i+=r.REQ?1:0,!1!==l)return g.ACTER=r.ACTER,g.MSG=r.MSG,l;r.ERR&&(c++,t.bck2(a))}return g.REQ=i>0,g.ERR=d==c&&i>0,!1}if(N&k){if(h=k&B?1:0,g.REQ=h,g.ERR=0,g.ACTER=0,g.MSG=null,a=t.pos,p=n.stack.pos(),r=m[0].clone().req(h),l=r.get(t,n),f=g.id+"_"+Gn(),!1!==l){if(!0!==l)for(var e=d-1;e>0;e--)n.stack.pushAt(p+d-e-1,m[e].clone().req(1),"sID",f);return g.ACTER=r.ACTER,g.MSG=r.MSG,l}return r.ERR?(g.ERR=h,t.bck2(a)):h&&r.REQ&&(g.ERR=1),!1}for(i=0,o=g.found,u=g.min,s=g.max,g.ERR=0,g.REQ=0,g.ACTER=0,g.MSG=null,a=t.pos,p=n.stack.pos(),f=g.id+"_"+Gn(),e=0;d>e;e++){if(r=m[e].clone().req(1),l=r.get(t,n),!1!==l){if(++o,s>=o)return g.found=o,n.stack.pushAt(p,g.clone(),"sID",f),g.found=0,g.ACTER=r.ACTER,g.MSG=r.MSG,l;break}r.REQ&&i++,r.ERR&&t.bck2(a)}return g.REQ=u>o,g.ERR=o>s||u>o&&i>0,!1}});var Yn=CodeMirror||{Pass:{toString:function(){return"CodeMirror.Pass"}}};k=null,m="error";{var Jn=dn({constructor:function(t,n){var e=this;e.Extra=t.Extra||{},e.LC=t.Comments.line?t.Comments.line[0]:null,e.BCS=t.Comments.block?t.Comments.block[0][0]:null,e.BCE=t.Comments.block?t.Comments.block[0][1]:null,e.BCC=e.BCL=t.Comments.block?t.Comments.block[0][2]:null,e.DEF=n.DEFAULT,e.ERR=t.Style.error||n.ERROR,e.Keywords=t.Keywords.autocomplete||null,e.Tokens=t.Parser||[],e.cTokens=t.cTokens.length?t.cTokens:null,e.Style=t.Style},Extra:null,LC:null,BCS:null,BCE:null,BCL:null,BCC:null,ERR:null,DEF:null,Keywords:null,cTokens:null,Tokens:null,Style:null,dispose:function(){var t=this;return t.Extra=null,t.LC=null,t.BCS=null,t.BCE=null,t.BCL=null,t.BCC=null,t.ERR=null,t.DEF=null,t.Keywords=null,t.cTokens=null,t.Tokens=null,t.Style=null,t},parse:function(t){t=t||"";var n,e,r,l,o=this,u=t.split(Mn),s=u.length,i=[];for(r=new Hn,r.parseAll=1,n=0;s>n;n++){for(l=new qn(u[n]),e=[];!l.eol();)e.push(o.getToken(l,r));i.push(e)}return i},getToken:function(t,n){var e,r,l,o,u,s=this,i=s.cTokens,c=s.Tokens,a=c.length,p=!!n.parseAll,f=s.Style,h=s.DEF,g=s.ERR;if(t=p?t:qn._(t),u=n.stack,t.sol()&&!u.isEmpty()&&_===u.peek().tt&&u.pop(),(u.isEmpty()||b!==u.peek().tt)&&t.spc())return p?{value:t.cur(1),type:h,error:null}:n.t=h;for(;!u.isEmpty()&&!t.eol();){if(i)for(r=0;re;e++)if(l=c[e],o=l.get(t,n),!1!==o){if(!0!==o)return o=f[o]||h,l.ACTER?(u.empty("sID",l.sID),n.t=o=g,p?{value:t.cur(1),type:g,error:l.err()}:n.t=g):p?{value:t.cur(1),type:o,error:null}:n.t=o}else if(l.ERR||l.REQ)return u.empty("sID",l.sID),t.nxt(),n.t=o=g,p?{value:t.cur(1),type:g,error:l.err()}:n.t=g;return t.nxt(),n.t=h,p?{value:t.cur(1),type:h,error:null}:n.t=h},indent:function(t,n,e,r){var l=(r.indentUnit||4,Yn.Pass);return l}});t.CodeMirrorGrammar={VERSION:"1.0.1",extend:vn,parse:h,getMode:g}}return t.CodeMirrorGrammar}); \ No newline at end of file diff --git a/grammar-reference.md b/grammar-reference.md index 6adc38f..d73a5be 100644 --- a/grammar-reference.md +++ b/grammar-reference.md @@ -171,7 +171,7 @@ example: **Syntax shorthand BNF-like notations (new)** -`Syntax` part supports *shorthand definitions* (similar to `BNF-style` definitions) for syntax sequences and groups of syntax sequences: +`Syntax` part supports *shorthand definitions* (similar to `PEG / BNF-style` definitions) for syntax sequences and groups of syntax sequences: Specificaly: @@ -252,7 +252,7 @@ Specificaly: "tokens": ["t1* t2", "t3"] } -// a literal tokens wrapped in quotes (' or ") +// literal tokens wrapped in quotes (' or ") // are equivalent to their literal value // empty literal token (i.e '') matches empty production // NOTE: unlike NON-Space token definition described previously diff --git a/src/main.js b/src/main.js index 1e2fa4d..315df20 100644 --- a/src/main.js +++ b/src/main.js @@ -368,9 +368,9 @@ var CodeMirrorGrammar = exports['@@MODULE_NAME@@'] = { * extendedgrammar = CodeMirrorGrammar.extend( grammar, basegrammar1 [, basegrammar2, ..] ); * ``` * - * Extend a grammar with basegrammar1, basegrammar2, etc.. + * Extend a `grammar` with `basegrammar1`, `basegrammar2`, etc.. * - * This way arbitrary dialects and variations can be handled more easily + * This way arbitrary `dialects` and `variations` can be handled more easily [/DOC_MARKDOWN]**/ extend: extend, @@ -382,9 +382,9 @@ var CodeMirrorGrammar = exports['@@MODULE_NAME@@'] = { * parsedgrammar = CodeMirrorGrammar.parse( grammar ); * ``` * - * This is used internally by the CodeMirrorGrammar Class - * In order to parse a JSON grammar to a form suitable to be used by the syntax-highlight parser. - * However user can use this method to cache a parsedgrammar to be used later. + * This is used internally by the `CodeMirrorGrammar` Class + * In order to parse a `JSON grammar` to a form suitable to be used by the syntax-highlight parser. + * However user can use this method to cache a `parsedgrammar` to be used later. * Already parsed grammars are NOT re-parsed when passed through the parse method again [/DOC_MARKDOWN]**/ parse: parse_grammar, @@ -397,8 +397,8 @@ var CodeMirrorGrammar = exports['@@MODULE_NAME@@'] = { * mode = CodeMirrorGrammar.getMode( grammar [, DEFAULT] ); * ``` * - * This is the main method which transforms a JSON grammar into a CodeMirror syntax-highlight parser. - * DEFAULT is the default return value (null by default) for things that are skipped or not styled + * This is the main method which transforms a `JSON grammar` into a `CodeMirror` syntax-highlight parser. + * `DEFAULT` is the default return value (`null` by default) for things that are skipped or not styled * In general there is no need to set this value, unless you need to return something else [/DOC_MARKDOWN]**/ getMode: get_mode diff --git a/src/tokenizers.js b/src/tokenizers.js index 79bcfea..7fa7de7 100644 --- a/src/tokenizers.js +++ b/src/tokenizers.js @@ -768,20 +768,13 @@ CompositeToken = Class(Token, { } }); -function parse_bnf_shorthand( tok, Lex, Syntax, sub_seq ) +function parse_peg_bnf_notation( tok, Lex, Syntax ) { var alternation, sequence, token, literal, repeat, - t, q, c, prev_token, curr_token; + t, q, c, prev_token, curr_token, stack, tmp; - if ( 'undefined' === typeof tok.pos ) - { - t = new String( trim(tok) ); - t.pos = 0; - } - else - { - t = tok; - } + t = new String( trim(tok) ); + t.pos = 0; if ( 1 === t.length ) { @@ -791,15 +784,16 @@ function parse_bnf_shorthand( tok, Lex, Syntax, sub_seq ) } else { + // parse PEG/BNF-like shorthand notations for syntax groups alternation = [ ]; sequence = [ ]; token = ''; + stack = []; while ( t.pos < t.length ) { - // parse BNF-like shorthand notations for syntax groups c = t.charAt( t.pos++ ); - if ( bnf_special_re.test( c ) ) + if ( peg_bnf_notation_re.test( c ) ) { if ( token.length ) { @@ -813,7 +807,7 @@ function parse_bnf_shorthand( tok, Lex, Syntax, sub_seq ) sequence.push( token ); token = ''; } - + if ( '"' === c || "'" === c ) { // literal token, quoted @@ -927,24 +921,57 @@ function parse_bnf_shorthand( tok, Lex, Syntax, sub_seq ) else if ( '(' === c ) { // start of grouped sub-sequence - prev_token = parse_bnf_shorthand( t, Lex, Syntax, true ); - curr_token = '(' + prev_token + ')'; - if ( !Syntax[curr_token] ) Syntax[curr_token] = clone( Lex[prev_token] || Syntax[prev_token] ); - sequence.push( curr_token ); + stack.push([sequence, alternation, token]); + sequence = []; alternation = []; token = ''; } else if ( ')' === c ) { // end of grouped sub-sequence - if ( sub_seq ) + if ( sequence.length > 1 ) { - //t.pos++; - break; + curr_token = '' + sequence.join( " " ); + if ( !Syntax[curr_token] ) + { + Syntax[curr_token] = { + type: 'group', + match: 'sequence', + tokens: sequence + }; + } + alternation.push( curr_token ); } - else + else if ( sequence.length ) { - continue; + alternation.push( sequence[0] ); } + sequence = []; + + if ( alternation.length > 1 ) + { + curr_token = '' + alternation.join( " | " ); + if ( !Syntax[curr_token] ) + { + Syntax[curr_token] = { + type: 'group', + match: 'either', + tokens: alternation + }; + } + } + else if ( alternation.length ) + { + curr_token = alternation[ 0 ]; + } + alternation = []; + + tmp = stack.pop( ); + sequence = tmp[0]; alternation = tmp[1]; token = tmp[2]; + + prev_token = curr_token; + curr_token = '(' + prev_token + ')'; + if ( !Syntax[curr_token] ) Syntax[curr_token] = clone( Lex[prev_token] || Syntax[prev_token] ); + sequence.push( curr_token ); } else // space @@ -1083,7 +1110,7 @@ function get_tokenizer( tokenID, RegExpID, Lex, Syntax, Style, if ( T_STR & get_type( tok ) ) { - tok = parse_bnf_shorthand( tok, Lex, Syntax ); + tok = parse_peg_bnf_notation( tok, Lex, Syntax ); tok = Lex[ tok ] || Syntax[ tok ]; } @@ -1106,17 +1133,10 @@ function get_tokenizer( tokenID, RegExpID, Lex, Syntax, Style, // loop and get all references } - // provide some defaults if ( 'undefined' === typeof tok.type ) { - if ( tok['either'] ) - { - tok.type = "group"; - tok.match = "either"; - tok.tokens = tok['either']; - delete tok['either']; - } - else if ( tok['all'] || tok['sequence'] ) + // provide some defaults + if ( tok['all'] || tok['sequence'] ) { tok.type = "group"; tok.match = "sequence"; @@ -1124,6 +1144,13 @@ function get_tokenizer( tokenID, RegExpID, Lex, Syntax, Style, if ( tok['all'] ) delete tok['all']; else delete tok['sequence']; } + else if ( tok['either'] ) + { + tok.type = "group"; + tok.match = "either"; + tok.tokens = tok['either']; + delete tok['either']; + } else if ( tok['zeroOrMore'] ) { tok.type = "group"; @@ -1145,6 +1172,30 @@ function get_tokenizer( tokenID, RegExpID, Lex, Syntax, Style, tok.tokens = tok['zeroOrOne']; delete tok['zeroOrOne']; } + else if ( tok['comment'] ) + { + tok.type = "comment"; + tok.tokens = tok['comment']; + delete tok['comment']; + } + else if ( tok['block'] ) + { + tok.type = "block"; + tok.tokens = tok['block']; + delete tok['block']; + } + else if ( tok['escaped-block'] ) + { + tok.type = "escaped-block"; + tok.tokens = tok['escaped-block']; + delete tok['escaped-block']; + } + else if ( tok['simple'] ) + { + tok.type = "simple"; + tok.tokens = tok['simple']; + delete tok['simple']; + } else { tok.type = "simple"; diff --git a/src/utils.js b/src/utils.js index 1a8a381..7f829b3 100644 --- a/src/utils.js +++ b/src/utils.js @@ -199,7 +199,7 @@ var undef = undefined, PROTO = 'prototype', HAS = 'hasOwnProperty', IS_ENUM = 'p }, newline_re = /\r\n|\r|\n/g, dashes_re = /[\-_]/g, - bnf_special_re = /^([{}()*+?|'"]|\s)/, + peg_bnf_notation_re = /^([{}()*+?|'"]|\s)/, has_prefix = function(s, id) { return (