diff --git a/README.md b/README.md index 1531afe..8f5eebf 100644 --- a/README.md +++ b/README.md @@ -29,13 +29,14 @@ See also: [codemirror-grammar](https://github.com/foo123/codemirror-grammar) , ###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* -* [`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**) -* Generated parsers are **optimized for speed and size** +* 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** +* `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 highlighters are **optimized for speed and size** +* Can generate a syntax-highlighter from a grammar **interactively and on-the-fly** ( see example, http://foo123.github.io/examples/prism-grammar ) ###How to use: diff --git a/api-reference.md b/api-reference.md index 7a20b3f..fedf403 100644 --- a/api-reference.md +++ b/api-reference.md @@ -23,9 +23,9 @@ __Method__: `extend` extendedgrammar = PrismGrammar.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 = PrismGrammar.parse( grammar ); ``` -This is used internally by the PrismGrammar 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 `PrismGrammar` Class +In order to parse a `JSON grammar` to a form suitable to be used by the syntax-highlighter. +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,5 +48,5 @@ __Method__: `getMode` mode = PrismGrammar.getMode( grammar ); ``` -This is the main method which transforms a JSON grammar into a syntax-highlighter for Prism. +This is the main method which transforms a `JSON grammar` into a syntax-highlighter for `Prism`. \ No newline at end of file diff --git a/beeld.config b/beeld.config index 9f9f3f6..0a51439 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@@" = "PrismGrammar" @ diff --git a/build/prism_grammar.js b/build/prism_grammar.js index fe59b4d..5ff98ef 100644 --- a/build/prism_grammar.js +++ b/build/prism_grammar.js @@ -1,7 +1,7 @@ /** * * PrismGrammar -* @version: 1.0 +* @version: 1.0.1 * * Transform a grammar specification in JSON format, into a syntax-highlighter for Prism * https://github.com/foo123/prism-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 ) /** * * PrismGrammar -* @version: 1.0 +* @version: 1.0.1 * * Transform a grammar specification in JSON format, into a syntax-highlighter for Prism * https://github.com/foo123/prism-grammar @@ -2524,7 +2575,7 @@ function get_mode( grammar ) [/DOC_MARKDOWN]**/ var PrismGrammar = exports['PrismGrammar'] = { - VERSION: "1.0", + VERSION: "1.0.1", // extend a grammar using another base grammar /**[DOC_MARKDOWN] @@ -2534,9 +2585,9 @@ var PrismGrammar = exports['PrismGrammar'] = { * extendedgrammar = PrismGrammar.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, @@ -2548,9 +2599,9 @@ var PrismGrammar = exports['PrismGrammar'] = { * parsedgrammar = PrismGrammar.parse( grammar ); * ``` * - * This is used internally by the PrismGrammar 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 `PrismGrammar` Class + * In order to parse a `JSON grammar` to a form suitable to be used by the syntax-highlighter. + * 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, @@ -2563,7 +2614,7 @@ var PrismGrammar = exports['PrismGrammar'] = { * mode = PrismGrammar.getMode( grammar ); * ``` * - * This is the main method which transforms a JSON grammar into a syntax-highlighter for Prism. + * This is the main method which transforms a `JSON grammar` into a syntax-highlighter for `Prism`. [/DOC_MARKDOWN]**/ getMode: get_mode }; diff --git a/build/prism_grammar.min.js b/build/prism_grammar.min.js index 5dd6ca8..5a886c8 100644 --- a/build/prism_grammar.min.js +++ b/build/prism_grammar.min.js @@ -1,9 +1,9 @@ /** * * PrismGrammar -* @version: 1.0 +* @version: 1.0.1 * * Transform a grammar specification in JSON format, into a syntax-highlighter for Prism * https://github.com/foo123/prism-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,"PrismGrammar",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 s(t,n,e,r){var l=gn(n);if(Y===l)return n;if(r[t])return r[t];e=e||0;var o,s=0;return n&&n.isCharList&&(s=1,delete n.isCharList),o=un&l?new zn(un,t,n,e):tn===l?new zn(tn,t,n,e):X&l?s?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 u(t,n,e,r,l,o){if(o[t])return o[t];var i,c,a,p,f,h,g,k=0,d=0,E=1;if(i=Rn(n),a=i.length,1===a)g=s(t,jn(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?k=1:(Dn(i[c],e)||Dn(i[a-1-c],e))&&(d=1);if(!E||r&&X&gn(r))if(!r||k||d){for(c=0;a>c;c++)i[c]=en&gn(i[c])?u(t+"_"+c,i[c],e,r,l,o):s(t+"_"+c,jn(i[c],e,l),c,o);g=a>1?new Fn(t,i):i[0]}else g=s(t,Gn(i,r),0,o);else i=i.slice().join(""),i.isCharList=1,g=s(t,i,0,o)}return o[t]=g}function i(t,n,e,r,l){if(l[t])return l[t];var o,u,i,c,a,p,f;for(c=[],a=[],o=mn(n),u=0,i=o.length;i>u;u++)p=s(t+"_0_"+u,jn(o[u][0],e,r),u,l),f=o[u].length>1?on!==p.tt||X!==gn(o[u][1])||Dn(o[u][1],e)?s(t+"_1_"+u,jn(o[u][1],e,r),u,l):o[u][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,s,u,i,a,p,f,h,g;if("undefined"==typeof t.pos?(a=new String(An(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=[],s="";a.posi[0]&&(i[0]=0),2>i.length?i.push(i[0]):i[1]=i[1].length?parseInt(i[1],10)||m:m,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]=vn(n[h]||e[h])),o.push(g);else if(")"===f){if(r)break;continue}}else s+=f;s.length&&(n[s]||e[s]||(n[s]={type:"simple",tokens:s}),o.push(s)),s="",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,s,h,g,k,d){var v,y,_,w,x,L,Q,q,F,$,U,Z,H,Y,J,W,tn=null;if(null===t)return new $n(C,"EOL",t);if(""===t)return new $n(b,"NONSPACE",t);if(!1===t||0===t)return new $n(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]?(v=e[t],pn&gn(v)&&(v=e[t]={type:"simple",tokens:v})):v=r[t]?r[t]:t,X&gn(v)&&(v=c(v,e,r),v=e[v]||r[v]);v.extend;)Y=v.extend,J=e[Y]||r[Y],delete v.extend,J&&(pn&gn(J)&&(J={type:"simple",tokens:J}),v=yn(J,v));if("undefined"==typeof v.type&&(v.either?(v.type="group",v.match="either",v.tokens=v.either,delete v.either):v.all||v.sequence?(v.type="group",v.match="sequence",v.tokens=v.all||v.sequence,v.all?delete v.all:delete v.sequence):v.zeroOrMore?(v.type="group",v.match="zeroOrMore",v.tokens=v.zeroOrMore,delete v.zeroOrMore):v.oneOrMore?(v.type="group",v.match="oneOrMore",v.tokens=v.oneOrMore,delete v.oneOrMore):v.zeroOrOne?(v.type="group",v.match="zeroOrOne",v.tokens=v.zeroOrOne,delete v.zeroOrOne):v.type="simple"),y=v.type?V[v.type.toUpperCase().replace(Mn,"")]:S,S&y){if(""===v.tokens)return tn=new $n(b,t,t),h[t]=tn,tn;if(null===v.tokens)return tn=new $n(C,t,t),h[t]=tn,tn;if(!1===v.tokens||0===v.tokens)return tn=new $n(O,t,t),h[t]=tn,tn}if(v.tokens=Rn(v.tokens),S&y)v.autocomplete&&f(v,t,d),v.push?(v.action||(v.action=["push",v.push]),delete v.push):v[K]("pop")&&(v.action||(v.action=["pop",v.pop]),delete v.pop),w=null,v.action&&v.action[0]&&("push"===v.action[0]?w=[E,v.action[1]]:"pop"===v.action[0]&&(w=[R,v.action[1]])),_="undefined"==typeof v.combine?"\\b":v.combine,tn=new $n(S,t,u(t,v.tokens.slice(),n,_,o,s)),tn.ta=w,h[t]=tn;else if(A&y)T&y&&p(v,k),tn=new Kn(y,t,i(t,v.tokens.slice(),n,o,s),v.multiline,v.escape,l[t+".inside"]?1:0),h[t]=tn,v.interleave&&g.push(tn.clone());else if(P&y){for(L=v.tokens.slice(),en&gn(v.match)?tn=new Un(j,t,null,v.match[0],v.match[1]):(x=z[v.match.toUpperCase()],tn=G===x?new Un(G,t,null,0,1):I===x?new Un(I,t,null,0,m):N===x?new Un(N,t,null,1,m):M&x?new Un(M,t,null):new Un(D,t,null)),h[t]=tn,Q=[],$=0,U=L.length;U>$;$++)Q=Q.concat(a(L[$],n,e,r,l,o,s,h,g,k,d));tn.set(Q)}else if(B&y){for(tn=mn(v.tokens.slice()).slice(),q=[],$=0,U=tn.length;U>$;$++)q[$]=tn[$].slice(),tn[$]=new Un(B,t+"_NGRAM_"+$,null);for(h[t]=tn,$=0,U=tn.length;U>$;$++){for(F=q[$],Q=[],Z=0,H=F.length;H>Z;Z++)Q=Q.concat(a(F[Z],n,e,r,l,o,s,h,g,k,d));tn[$].set(Q)}}return h[t]}function p(t,n){var e,r,l,o,s,u=mn(t.tokens.slice());for(o=0,s=u.length;s>o;o++)e=u[o][0],r=u[o].length>1?u[o][1]:u[o][0],l=u[o].length>2?u[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(Rn(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,s,u,i,c,p,f,h,g,k,d,E;if(t.__parsed)return t;for(f={},h={},g={},d={},E={},k=[],t=vn(t),n=t.RegExpID||null,t.RegExpID=null,delete t.RegExpID,s=t.Lex||{},t.Lex=null,delete t.Lex,u=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,s,u,o,f,h,g,k,d,E)||null,p&&(en&gn(p)?e=e.concat(p):e.push(p));return t.Parser=e,t.cTokens=k,t.Style=o,t.Comments=d,t.Keywords=E,t.Extra=t.Extra||{},t.__parsed=1,t}function g(t){var n,e=new Yn(h(t),{DEFAULT:k,ERROR:d}),r=0,l=null,o={"before-highlight":function(t){l===t.language&&(t._code=t.code,t.code="")},"before-insert":function(t){l===t.language&&(t.code=t._code,t._code="",t.highlightedCode=n.Token.stringify(e.parse(t.code),t.language))}};return{hook:function(t,e){if(!r){n=t,l=e;for(var s in o)o[K](s)&&n.hooks.add(s,o[s]);r=1}},unhook:function(){if(r){var t,e,l=n.hooks.all;for(t in o)l[K](t)&&o[K](t)&&(e=l[t].indexOf(o[t]),e>-1&&l[t].splice(e,1));r=0}}}}var k,d,E=1,R=2,m=1/0,v=2,y=4,_=8,S=16,C=17,b=18,O=20,A=32,w=33,T=34,M=64,x=128,D=x,j=256,G=257,I=258,N=259,P=512,B=1024,L=D|B,Q=2048,q=4096,z={EITHER:M,ALL:x,SEQUENCE:D,ZEROORONE:G,ZEROORMORE:I,ONEORMORE:N,REPEATED:j},V={INDENT:Q,DEDENT:q,BLOCK:A,COMMENT:T,ESCAPEDBLOCK:w,SIMPLE:S,GROUP:P,NGRAM:B},F=void 0,$="prototype",K="hasOwnProperty",U="propertyIsEnumerable",Z=(Object.keys,Array[$],Object[$]),H=(Function[$],Z.toString),Y=4,J=5,W=8,X=16,tn=17,nn=18,en=32,rn=64,ln=128,on=256,sn=512,un=1024,cn=2048,an=4096,pn=X|en,fn=rn|en,hn={"[object Array]":en,"[object RegExp]":on,"[object Date]":sn,"[object Number]":Y,"[object String]":X,"[object Function]":ln,"[object Object]":rn},gn=function(t){var n;return null===t?un:!0===t||!1===t?W:F===t?cn:(n=H.call(t),n=hn[n]||an,Y===n||t instanceof Number?isNaN(t)?J:Y:X===n||t instanceof String?1===t.length?tn:X:en===n||t instanceof Array?en:on===n||t instanceof RegExp?on:sn===n||t instanceof Date?sn:ln===n||t instanceof Function?ln:rn===n?rn:an)},kn=function(){var t,n,e,r,l,o,s,u=arguments;for(n=u[0]||{},t=u.length,o=1;t>o;o++)if(e=u[o],rn===gn(e))for(l in e)e[K](l)&&e[U](l)&&(r=e[l],s=gn(r),n[l]=Y&s?0+r:pn&s?r.slice():r);return n},dn=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[K](l)||(n[l]=function(){}),e=n[l],delete n[l],e[$]=kn(dn(t[$]),n),e[$][l]=e,e},Rn=function(t,n){return n||en!==gn(t)?[t]:t},mn=function(t,n){return t=Rn(t,n),(n||en!==gn(t[0]))&&(t=[t]),t},vn=function(t){var n,e=gn(t);if(!(fn&e))return t;var r,l={};for(r in t)t[K](r)&&t[U](r)&&(n=gn(t[r]),l[r]=rn&n?vn(t[r]):pn&n?t[r].slice():t[r]);return l},yn=function(){var t=arguments,n=t.length;if(1>n)return null;if(2>n)return vn(t[0]);var e,r,l,o,s=t[0],u=vn(s);for(n--,r=1;n>r;r++)if(e=t[r])for(l in e)e[K](l)&&e[U](l)&&(s[K](l)&&s[U](l)?(o=gn(s[l]),rn&~X&o&&(u[l]=yn(s[l],e[l]))):u[l]=vn(e[l]));return u},_n=/([.*+?^${}()|[\]\/\\\-])/g,Sn=function(t){return t.replace(_n,"\\$1")},Cn=/\$(\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(Cn,o);return e.join("$")},On=/^\s+|\s+$/g,An=String[$].trim?function(t){return t.trim()}:function(t){return t.replace(On,"")},wn=function(t,n){return n.length-t.length},Tn=/\r\n|\r|\n/g,Mn=/[\-_]/g,xn=/^([{}()*+?|'"]|\s)/,Dn=function(t,n){return X&gn(n)&&X&gn(t)&&n.length&&n.length<=t.length&&n==t.substr(0,n.length)},jn=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,s,u,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),s="^("+o+")",e[s]||(u=new RegExp(s,f),i={peek:null,negativepeek:null},e[s]=[u,i]),e[s]}return t},Gn=function(t,n){var e={},r="",l=gn(n);(X===l||tn===l)&&(r=n);var o=t.sort(wn).map(function(t){return e[t.charAt(0)]=1,Sn(t)}).join("|");return[new RegExp("^("+o+")"+r),{peek:e,negativepeek:null},1]},In=0,Nn=function(){return++In},Pn=function(t){return[t||"uuid",++In,(new Date).getTime()].join("_")},Bn=(!("undefined"==typeof global||"[object global]"!==H.call(global)),Math.max),Ln=/^[\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&&(s.pos+=o[r||0].length,s._&&(s._.pos=s.pos)),o)},spc:function(t){var n,e=this,r=e.pos,l=e.s.slice(r);return(n=l.match(Ln))?(!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)s+=" "==t.charAt(o)?e-s%e:1;return s},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,$n,Kn,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 u?[e,r[1]]:r;return!1}}),Vn=En(zn,{constructor:function(t,n,e){var r=this;r.mt=_,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 s,u=o[e[0]],i=gn(u),c=l.ms[e[0]].tt;return on===c&&(Y===i?(s=e[1][u+1],u=new zn(s.length>1?X:tn,r.tn+"_End",s)):X===i&&(s=bn(u,e[1]),u=new zn(s.length>1?X:tn,r.tn+"_End",s))),u}return!1}}),$n=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,s=n.data;if(o)if(e=o[0],r=o[1],R===e)if(r){if(t&&(r=Y===gn(r)?t[1][r]:bn(r,t[1])),s.isEmpty()||r!==s.peek())return l.MSG='Token "'+r+'" No Match',s.pop(),1;s.pop()}else s.pop();else E===e&&r&&(t&&(r=Y===gn(r)?t[1][r]:bn(r,t[1])),s.push(r));return 0},get:function(t,n){var e=this,r=e.ta,l=e.tk,o=e.tt,s=e.id,u=null;if(e.MSG=null,e.ACTER=0,O===o)return e.ERR=0,e.REQ=0,!0;if(C===o){if(t.spc(),t.eol())return s}else if(b===o)e.ERR=e.REQ&&t.spc()&&!t.eol()?1:0,e.REQ=0;else if(u=l.get(t))return r&&(e.ACTER=e.act(u,n)),s;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("")}}),Kn=En($n,{constructor:function(t,n,e,r,l,o){var s=this;s.tt=t,s.id=n,s.tk=e,s.REQ=0,s.ERR=0,s.ACTER=0,s.MSG=null,s.mline="undefined"==typeof r?1:r,s.esc=l||"\\",s.inter=o,s.CLONE=["tk","mline","esc","inter"]},inter:0,mline:0,esc:null,get:function(t,n){var e,r,l,o,s,u,i,c,a,p=this,f=0,h=0,g="",k=p.mline,d=p.tk,E=p.id,R=p.tt,m=p.inter,v=m?E+".inside":E,y=0,_=w===R,S=p.esc;if(p.MSG=null,p.ACTER=0,T===R&&(p.REQ=0),s=0,n.inBlock===E?(h=1,e=n.endBlock,s=1,u=v):!n.inBlock&&(e=d.get(t))&&(h=1,n.inBlock=E,n.endBlock=e,u=E),h){if(l=n.stack.pos(),o=un===e.tt,m){if(s&&o&&t.sol())return p.REQ=0,n.inBlock=null,n.endBlock=null,!1;if(!s)return n.stack.pushAt(l,p.clone(),"sID",E),u}if(f=e.get(t),r=k,a=0,f)u=o?v:E;else for(c=t.pos;!t.eol();){if(i=t.pos,!(_&&y||!e.get(t))){m&&t.pos>i&&i>c?(u=v,t.bck2(i),a=1):(u=E,f=1);break}g=t.nxt(),y=!y&&g==S}return r=k||_&&y,f||!r&&!a?(n.inBlock=null,n.endBlock=null):n.stack.pushAt(l,p.clone(),"sID",E),u}return!1}}),Un=En($n,{constructor:function(t,n,e,r,l){var o=this;o.tt=t?t:j,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||m,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=Rn(t)),this},get:function(t,n){var e,r,l,o,s,u,i,c,a,p,f,h,g=this,k=g.tt,d=g.ts,E=d.length;if(M===k){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=d[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(L&k){if(h=k&D?1:0,g.REQ=h,g.ERR=0,g.ACTER=0,g.MSG=null,a=t.pos,p=n.stack.pos(),r=d[0].clone().req(h),l=r.get(t,n),f=g.id+"_"+Nn(),!1!==l){if(!0!==l)for(var e=E-1;e>0;e--)n.stack.pushAt(p+E-e-1,d[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,s=g.min,u=g.max,g.ERR=0,g.REQ=0,g.ACTER=0,g.MSG=null,a=t.pos,p=n.stack.pos(),f=g.id+"_"+Nn(),e=0;E>e;e++){if(r=d[e].clone().req(1),l=r.get(t,n),!1!==l){if(++o,u>=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=s>o,g.ERR=o>u||s>o&&i>0,!1}}),k="",d="";{var Yn=En({constructor:function(t,n){var e=this;e.DEF=n.DEFAULT,e.ERR=n.ERROR,e.Tokens=t.Parser||[],e.cTokens=t.cTokens.length?t.cTokens:null,e.Style=t.Style},ERR:null,DEF:null,cTokens:null,Tokens:null,Style:null,dispose:function(){var t=this;return t.ERR=null,t.DEF=null,t.cTokens=null,t.Tokens=null,t.Style=null,t},parse:function(t){t=t||"";var n,e,r=this,l=t.split(Tn),o=l.length,s=[];for(e={state:new Hn,tokens:null},n=0;o>n;n++)e=r.getLineTokens(l[n],e.state,n),s=s.concat(e.tokens),o>n+1&&s.push("\n");return s},getLineTokens:function(t,n){var e,r,l,o,s,u,i,c,a,p,f,h=this,g=h.cTokens,k=h.Tokens,d=k.length,E=null,R=h.Style,m=h.DEF,v=h.ERR;for(u=[],p=new qn(t),f=n.stack,i={type:null,content:""},c=null,a=null,p.sol()&&!f.isEmpty()&&C===f.peek().tt&&f.pop();!p.eol();)if(r=0,m===a||v===a?(i.type&&u.push(i),u.push(p.cur(1)),i={type:null,content:""}):a&&a!==i.type?(i.type&&u.push(i),i={type:a,content:p.cur(1)}):i.type&&(i.content+=p.cur(1)),a=!1,!f.isEmpty()&&b===f.peek().tt||!p.spc()){for(;!f.isEmpty()&&!p.eol();){if(g){for(o=0,l=0;oe;e++)if(s=k[e],n.t=c=s.get(p,n),!1!==c){if(!0!==c){a=R[c]||m,s.ACTER&&(f.empty("sID",s.sID),n.t=c=v,a=v,E=s.err()),r=1;break}}else{if(s.ERR||s.REQ){f.empty("sID",s.sID),p.nxt(),n.t=c=v,a=v,E=s.err(),r=1;break}a=!1}if(!r){if(p.eol())break;p.nxt(),n.t=c=m,a=m}}}else n.t=c=m,a=m;return m===a||v===a?(i.type&&u.push(i),u.push(p.cur(1))):a&&a!==i.type?(i.type&&u.push(i),u.push({type:a,content:p.cur(1)})):i.type&&(i.content+=p.cur(1),u.push(i)),i=null,{state:n,tokens:u}}});t.PrismGrammar={VERSION:"1.0",extend:yn,parse:h,getMode:g}}return t.PrismGrammar}); \ No newline at end of file +**/!function(t,e,n){"use strict";var r,l="object"==typeof module&&module.exports,o="function"==typeof define&&define.amd;l?module.exports=(module.$deps=module.$deps||{})[e]=module.$deps[e]||n.call(t,{NODE:module})||1:o&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(e)?define(e,["require","exports","module"],function(e,r,l){return n.call(t,{AMD:l})}):e in t||(t[e]=r=n.call(t,{})||1)&&o&&define(e,[],function(){return r})}(this,"PrismGrammar",function(t){"use strict";function e(t,e){var n,r=this;return(n=t.chr(r.tp,e))?[r.tk,n]:!1}function n(t,e){var n,r=this;return(n=t.chl(r.tp,e))?[r.tk,n]:!1}function r(t,e){var n,r=this;return(n=t.str(r.tp,r.p,e))?[r.tk,n]:!1}function l(t,e){var n,r=this;return(n=t.rex(r.tp,r.p,r.np,r.tg,e))?[r.tk,n]:!1}function o(t,e){var n=this;return!1!==e&&t.end(),[n.tk,""]}function s(t,e,n,r){var l=he(e);if(Y===l)return e;if(r[t])return r[t];n=n||0;var o,s=0;return e&&e.isCharList&&(s=1,delete e.isCharList),o=ue&l?new qe(ue,t,e,n):te===l?new qe(te,t,e,n):X&l?s?new qe(ee,t,e,n):new qe(X,t,e,n):ne&l?new qe(oe,t,e,n):e,r[t]=o}function u(t,e,n,r,l,o){if(o[t])return o[t];var i,c,a,p,f,h,g,k=0,d=0,E=1;if(i=Ee(e),a=i.length,1===a)g=s(t,De(i[0],n,l),0,o);else if(a>1){for(p=(a>>1)+1,c=0;p>=c;c++)f=he(i[c]),h=he(i[a-1-c]),(te!==f||te!==h)&&(E=0),ne&f||ne&h?k=1:(xe(i[c],n)||xe(i[a-1-c],n))&&(d=1);if(!E||r&&X&he(r))if(!r||k||d){for(c=0;a>c;c++)i[c]=ne&he(i[c])?u(t+"_"+c,i[c],n,r,l,o):s(t+"_"+c,De(i[c],n,l),c,o);g=a>1?new Ve(t,i):i[0]}else g=s(t,je(i,r),0,o);else i=i.slice().join(""),i.isCharList=1,g=s(t,i,0,o)}return o[t]=g}function i(t,e,n,r,l){if(l[t])return l[t];var o,u,i,c,a,p,f;for(c=[],a=[],o=me(e),u=0,i=o.length;i>u;u++)p=s(t+"_0_"+u,De(o[u][0],n,r),u,l),f=o[u].length>1?oe!==p.tt||X!==he(o[u][1])||xe(o[u][1],n)?s(t+"_1_"+u,De(o[u][1],n,r),u,l):o[u][1]:p,c.push(p),a.push(f);return l[t]=new ze(t,c,a)}function c(t,e,n){var r,l,o,s,u,i,c,a,p,f,h,g;if(i=new String(Oe(t)),i.pos=0,1===i.length)f=""+t,e[f]||(e[f]={type:"simple",tokens:t}),t=f;else{for(r=[],l=[],o="",h=[];i.posu[0]&&(u[0]=0),2>u.length?u.push(u[0]):u[1]=u[1].length?parseInt(u[1],10)||R:R,0>u[1]&&(u[1]=0),p=l.pop(),f=""+p+["{",u[0]||"",",",isFinite(u[1])?u[1]||"":"","}"].join(""),n[f]||(n[f]={type:"group",match:[u[0],u[1]],tokens:[p]}),l.push(f)}else{if("}"===a)continue;"|"===a?(l.length>1?(f=""+l.join(" "),n[f]||(n[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(" "),n[f]||(n[f]={type:"group",match:"sequence",tokens:l}),r.push(f)):l.length&&r.push(l[0]),l=[],r.length>1?(f=""+r.join(" | "),n[f]||(n[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+")",n[f]||(n[f]=Re(e[p]||n[p])),l.push(f))}else o+=a;o.length&&(e[o]||n[o]||(e[o]={type:"simple",tokens:o}),l.push(o)),o="",l.length>1?(f=""+l.join(" "),n[f]||(n[f]={type:"group",match:"sequence",tokens:l}),r.push(f)):l.length&&r.push(l[0]),l=[],r.length>1?(f=""+r.join(" | "),n[f]||(n[f]={type:"group",match:"either",tokens:r}),t=f):r.length&&(t=r[0]),r=[]}return t}function a(t,e,n,r,l,o,s,h,g,k,d){var v,y,_,w,x,L,Q,q,F,$,U,Z,H,Y,J,W,te=null;if(null===t)return new Fe(S,"EOL",t);if(""===t)return new Fe(C,"NONSPACE",t);if(!1===t||0===t)return new Fe(O,"EMPTY",t);if(ne&he(t)&&(W=t,t="NGRAM_"+W.join("_"),r[t]||(r[t]={type:"ngram",tokens:W})),t=""+t,h[t])return h[t];for(n[t]?(v=n[t],ae&he(v)&&(v=n[t]={type:"simple",tokens:v})):v=r[t]?r[t]:t,X&he(v)&&(v=c(v,n,r),v=n[v]||r[v]);v.extend;)Y=v.extend,J=n[Y]||r[Y],delete v.extend,J&&(ae&he(J)&&(J={type:"simple",tokens:J}),v=ve(J,v));if("undefined"==typeof v.type&&(v.all||v.sequence?(v.type="group",v.match="sequence",v.tokens=v.all||v.sequence,v.all?delete v.all:delete v.sequence):v.either?(v.type="group",v.match="either",v.tokens=v.either,delete v.either):v.zeroOrMore?(v.type="group",v.match="zeroOrMore",v.tokens=v.zeroOrMore,delete v.zeroOrMore):v.oneOrMore?(v.type="group",v.match="oneOrMore",v.tokens=v.oneOrMore,delete v.oneOrMore):v.zeroOrOne?(v.type="group",v.match="zeroOrOne",v.tokens=v.zeroOrOne,delete v.zeroOrOne):v.comment?(v.type="comment",v.tokens=v.comment,delete v.comment):v.block?(v.type="block",v.tokens=v.block,delete v.block):v["escaped-block"]?(v.type="escaped-block",v.tokens=v["escaped-block"],delete v["escaped-block"]):v.simple?(v.type="simple",v.tokens=v.simple,delete v.simple):v.type="simple"),y=v.type?V[v.type.toUpperCase().replace(Te,"")]:b,b&y){if(""===v.tokens)return te=new Fe(C,t,t),h[t]=te,te;if(null===v.tokens)return te=new Fe(S,t,t),h[t]=te,te;if(!1===v.tokens||0===v.tokens)return te=new Fe(O,t,t),h[t]=te,te}if(v.tokens=Ee(v.tokens),b&y)v.autocomplete&&f(v,t,d),v.push?(v.action||(v.action=["push",v.push]),delete v.push):v[K]("pop")&&(v.action||(v.action=["pop",v.pop]),delete v.pop),w=null,v.action&&v.action[0]&&("push"===v.action[0]?w=[E,v.action[1]]:"pop"===v.action[0]&&(w=[m,v.action[1]])),_="undefined"==typeof v.combine?"\\b":v.combine,te=new Fe(b,t,u(t,v.tokens.slice(),e,_,o,s)),te.ta=w,h[t]=te;else if(A&y)T&y&&p(v,k),te=new $e(y,t,i(t,v.tokens.slice(),e,o,s),v.multiline,v.escape,l[t+".inside"]?1:0),h[t]=te,v.interleave&&g.push(te.clone());else if(P&y){for(L=v.tokens.slice(),ne&he(v.match)?te=new Ke(j,t,null,v.match[0],v.match[1]):(x=z[v.match.toUpperCase()],te=G===x?new Ke(G,t,null,0,1):I===x?new Ke(I,t,null,0,R):N===x?new Ke(N,t,null,1,R):M&x?new Ke(M,t,null):new Ke(D,t,null)),h[t]=te,Q=[],$=0,U=L.length;U>$;$++)Q=Q.concat(a(L[$],e,n,r,l,o,s,h,g,k,d));te.set(Q)}else if(B&y){for(te=me(v.tokens.slice()).slice(),q=[],$=0,U=te.length;U>$;$++)q[$]=te[$].slice(),te[$]=new Ke(B,t+"_NGRAM_"+$,null);for(h[t]=te,$=0,U=te.length;U>$;$++){for(F=q[$],Q=[],Z=0,H=F.length;H>Z;Z++)Q=Q.concat(a(F[Z],e,n,r,l,o,s,h,g,k,d));te[$].set(Q)}}return h[t]}function p(t,e){var n,r,l,o,s,u=me(t.tokens.slice());for(o=0,s=u.length;s>o;o++)n=u[o][0],r=u[o].length>1?u[o][1]:u[o][0],l=u[o].length>2?u[o][2]:"",null===r?(e.line=e.line||[],e.line.push(n)):(e.block=e.block||[],e.block.push([n,r,l]))}function f(t,e,n){var r=[].concat(Ee(t.tokens)).map(function(t){return{word:t,meta:e}});n.autocomplete=(n.autocomplete||[]).concat(r)}function h(t){var e,n,r,l,o,s,u,i,c,p,f,h,g,k,d,E;if(t.__parsed)return t;for(f={},h={},g={},d={},E={},k=[],t=Re(t),e=t.RegExpID||null,t.RegExpID=null,delete t.RegExpID,s=t.Lex||{},t.Lex=null,delete t.Lex,u=t.Syntax||{},t.Syntax=null,delete t.Syntax,o=t.Style||{},l=t.Parser||[],r=l.length,n=[],i=0;r>i;i++)c=l[i],p=a(c,e,s,u,o,f,h,g,k,d,E)||null,p&&(ne&he(p)?n=n.concat(p):n.push(p));return t.Parser=n,t.cTokens=k,t.Style=o,t.Comments=d,t.Keywords=E,t.Extra=t.Extra||{},t.__parsed=1,t}function g(t){var e,n=new He(h(t),{DEFAULT:k,ERROR:d}),r=0,l=null,o={"before-highlight":function(t){l===t.language&&(t._code=t.code,t.code="")},"before-insert":function(t){l===t.language&&(t.code=t._code,t._code="",t.highlightedCode=e.Token.stringify(n.parse(t.code),t.language))}};return{hook:function(t,n){if(!r){e=t,l=n;for(var s in o)o[K](s)&&e.hooks.add(s,o[s]);r=1}},unhook:function(){if(r){var t,n,l=e.hooks.all;for(t in o)l[K](t)&&o[K](t)&&(n=l[t].indexOf(o[t]),n>-1&&l[t].splice(n,1));r=0}}}}var k,d,E=1,m=2,R=1/0,v=2,y=4,_=8,b=16,S=17,C=18,O=20,A=32,w=33,T=34,M=64,x=128,D=x,j=256,G=257,I=258,N=259,P=512,B=1024,L=D|B,Q=2048,q=4096,z={EITHER:M,ALL:x,SEQUENCE:D,ZEROORONE:G,ZEROORMORE:I,ONEORMORE:N,REPEATED:j},V={INDENT:Q,DEDENT:q,BLOCK:A,COMMENT:T,ESCAPEDBLOCK:w,SIMPLE:b,GROUP:P,NGRAM:B},F=void 0,$="prototype",K="hasOwnProperty",U="propertyIsEnumerable",Z=(Object.keys,Array[$],Object[$]),H=(Function[$],Z.toString),Y=4,J=5,W=8,X=16,te=17,ee=18,ne=32,re=64,le=128,oe=256,se=512,ue=1024,ie=2048,ce=4096,ae=X|ne,pe=re|ne,fe={"[object Array]":ne,"[object RegExp]":oe,"[object Date]":se,"[object Number]":Y,"[object String]":X,"[object Function]":le,"[object Object]":re},he=function(t){var e;return null===t?ue:!0===t||!1===t?W:F===t?ie:(e=H.call(t),e=fe[e]||ce,Y===e||t instanceof Number?isNaN(t)?J:Y:X===e||t instanceof String?1===t.length?te:X:ne===e||t instanceof Array?ne:oe===e||t instanceof RegExp?oe:se===e||t instanceof Date?se:le===e||t instanceof Function?le:re===e?re:ce)},ge=function(){var t,e,n,r,l,o,s,u=arguments;for(e=u[0]||{},t=u.length,o=1;t>o;o++)if(n=u[o],re===he(n))for(l in n)n[K](l)&&n[U](l)&&(r=n[l],s=he(r),e[l]=Y&s?0+r:ae&s?r.slice():r);return e},ke=Object.create,de=function(t,e){var n,r=arguments.length,l="constructor";return 0===r?(t=Object,e={}):1===r?(e=t||{},t=Object):(t=t||Object,e=e||{}),e[K](l)||(e[l]=function(){}),n=e[l],delete e[l],n[$]=ge(ke(t[$]),e),n[$][l]=n,n},Ee=function(t,e){return e||ne!==he(t)?[t]:t},me=function(t,e){return t=Ee(t,e),(e||ne!==he(t[0]))&&(t=[t]),t},Re=function(t){var e,n=he(t);if(!(pe&n))return t;var r,l={};for(r in t)t[K](r)&&t[U](r)&&(e=he(t[r]),l[r]=re&e?Re(t[r]):ae&e?t[r].slice():t[r]);return l},ve=function(){var t=arguments,e=t.length;if(1>e)return null;if(2>e)return Re(t[0]);var n,r,l,o,s=t[0],u=Re(s);for(e--,r=1;e>r;r++)if(n=t[r])for(l in n)n[K](l)&&n[U](l)&&(s[K](l)&&s[U](l)?(o=he(s[l]),re&~X&o&&(u[l]=ve(s[l],n[l]))):u[l]=Re(n[l]));return u},ye=/([.*+?^${}()|[\]\/\\\-])/g,_e=function(t){return t.replace(ye,"\\$1")},be=/\$(\d{1,2})/g,Se=function(t,e){var n,r,l,o;for(o=function(t,n){return e[1+parseInt(n,10)]},n=t.split("$$"),l=n.length,r=0;l>r;r++)n[r]=n[r].replace(be,o);return n.join("$")},Ce=/^\s+|\s+$/g,Oe=String[$].trim?function(t){return t.trim()}:function(t){return t.replace(Ce,"")},Ae=function(t,e){return e.length-t.length},we=/\r\n|\r|\n/g,Te=/[\-_]/g,Me=/^([{}()*+?|'"]|\s)/,xe=function(t,e){return X&he(e)&&X&he(t)&&e.length&&e.length<=t.length&&e==t.substr(0,e.length)},De=function(t,e,n){if(!t||Y===he(t))return t;var r,l=e?e.length||0:0;if(l&&e==t.substr(0,l)){var o,s,u,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),s="^("+o+")",n[s]||(u=new RegExp(s,f),i={peek:null,negativepeek:null},n[s]=[u,i]),n[s]}return t},je=function(t,e){var n={},r="",l=he(e);(X===l||te===l)&&(r=e);var o=t.sort(Ae).map(function(t){return n[t.charAt(0)]=1,_e(t)}).join("|");return[new RegExp("^("+o+")"+r),{peek:n,negativepeek:null},1]},Ge=0,Ie=function(){return++Ge},Ne=function(t){return[t||"uuid",++Ge,(new Date).getTime()].join("_")},Pe=(!("undefined"==typeof global||"[object global]"!==H.call(global)),Math.max),Be=/^[\s\u00a0]+/,Le=/[^\s\u00a0]/,Qe=de({constructor:function(t){var e=this;e._=null,e.s=t?""+t:"",e.start=e.pos=0,e.lCP=e.lCV=0,e.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,e){var n=this,r=n.s.charAt(n.pos)||null;return r&&t===r?(!1!==e&&(n.pos+=1,n._&&(n._.pos=n.pos)),r):!1},chl:function(t,e){var n=this,r=n.s.charAt(n.pos)||null;return r&&-10?!1:(!1!==l&&(s.pos+=o[r||0].length,s._&&(s._.pos=s.pos)),o)},spc:function(t){var e,n=this,r=n.pos,l=n.s.slice(r);return(e=l.match(Be))?(!1!==t&&(n.pos+=e[0].length,n._&&(n._.pos=n.pos)),1):0},end:function(){var t=this;return t.pos=t.s.length,t._&&(t._.pos=t.pos),t},nxt:function(){var t,e=this,n=e.s;return e.poso;++o)s+=" "==t.charAt(o)?n-s%n:1;return s},Qe._=function(t){var e=new Qe;return e._=t,e.s=""+t.string,e.start=t.start,e.pos=t.pos,e.lCP=t.lastColumnPos,e.lCV=t.lastColumnValue,e.lS=t.lineStart,e};var qe,ze,Ve,Fe,$e,Ke,Ue=de({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 Ue(this._.slice())},isEmpty:function(){return 0>=this._.length},pos:function(){return this._.length},peek:function(t){var e=this,n=e._;if(t=arguments.length?t:-1,n.length){if(0>t&&0<=n.length+t)return n[n.length+t];if(t>=0&&tn;n++)if(r=o[n].get(t,e))return u?[n,r[1]]:r;return!1}}),ze=de(qe,{constructor:function(t,e,n){var r=this;r.mt=_,r.tn=t,r.s=new Ve(r.tn+"_Start",e,!1),r.e=n},s:null,e:null,get:function(t,e){var n,r=this,l=r.s,o=r.e;if(n=l.get(t,e)){var s,u=o[n[0]],i=he(u),c=l.ms[n[0]].tt;return oe===c&&(Y===i?(s=n[1][u+1],u=new qe(s.length>1?X:te,r.tn+"_End",s)):X===i&&(s=Se(u,n[1]),u=new qe(s.length>1?X:te,r.tn+"_End",s))),u}return!1}}),Fe=de({constructor:function(t,e,n){var r=this;r.tt=t||b,r.id=e,r.tk=n,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,e){var n,r,l=this,o=l.ta||null,s=e.data;if(o)if(n=o[0],r=o[1],m===n)if(r){if(t&&(r=Y===he(r)?t[1][r]:Se(r,t[1])),s.isEmpty()||r!==s.peek())return l.MSG='Token "'+r+'" No Match',s.pop(),1;s.pop()}else s.pop();else E===n&&r&&(t&&(r=Y===he(r)?t[1][r]:Se(r,t[1])),s.push(r));return 0},get:function(t,e){var n=this,r=n.ta,l=n.tk,o=n.tt,s=n.id,u=null;if(n.MSG=null,n.ACTER=0,O===o)return n.ERR=0,n.REQ=0,!0;if(S===o){if(t.spc(),t.eol())return s}else if(C===o)n.ERR=n.REQ&&t.spc()&&!t.eol()?1:0,n.REQ=0;else if(u=l.get(t))return r&&(n.ACTER=n.act(u,e)),s;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,e,n,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(e=0,n=l.length;n>e;e++)t[l[e]]=r[l[e]];return t},toString:function(){var t=this;return["[","Tokenizer: ",t.id,", Matcher: ",t.tk?t.tk.toString():null,"]"].join("")}}),$e=de(Fe,{constructor:function(t,e,n,r,l,o){var s=this;s.tt=t,s.id=e,s.tk=n,s.REQ=0,s.ERR=0,s.ACTER=0,s.MSG=null,s.mline="undefined"==typeof r?1:r,s.esc=l||"\\",s.inter=o,s.CLONE=["tk","mline","esc","inter"]},inter:0,mline:0,esc:null,get:function(t,e){var n,r,l,o,s,u,i,c,a,p=this,f=0,h=0,g="",k=p.mline,d=p.tk,E=p.id,m=p.tt,R=p.inter,v=R?E+".inside":E,y=0,_=w===m,b=p.esc;if(p.MSG=null,p.ACTER=0,T===m&&(p.REQ=0),s=0,e.inBlock===E?(h=1,n=e.endBlock,s=1,u=v):!e.inBlock&&(n=d.get(t))&&(h=1,e.inBlock=E,e.endBlock=n,u=E),h){if(l=e.stack.pos(),o=ue===n.tt,R){if(s&&o&&t.sol())return p.REQ=0,e.inBlock=null,e.endBlock=null,!1;if(!s)return e.stack.pushAt(l,p.clone(),"sID",E),u}if(f=n.get(t),r=k,a=0,f)u=o?v:E;else for(c=t.pos;!t.eol();){if(i=t.pos,!(_&&y||!n.get(t))){R&&t.pos>i&&i>c?(u=v,t.bck2(i),a=1):(u=E,f=1);break}g=t.nxt(),y=!y&&g==b}return r=k||_&&y,f||!r&&!a?(e.inBlock=null,e.endBlock=null):e.stack.pushAt(l,p.clone(),"sID",E),u}return!1}}),Ke=de(Fe,{constructor:function(t,e,n,r,l){var o=this;o.tt=t?t:j,o.id=e||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"],n&&o.set(n)},ts:null,min:0,max:1,found:0,set:function(t){return t&&(this.ts=Ee(t)),this},get:function(t,e){var n,r,l,o,s,u,i,c,a,p,f,h,g=this,k=g.tt,d=g.ts,E=d.length;if(M===k){for(i=0,c=0,g.REQ=1,g.ERR=0,g.ACTER=0,g.MSG=null,a=t.pos,n=0;E>n;n++){if(r=d[n].clone().req(1),l=r.get(t,e),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(L&k){if(h=k&D?1:0,g.REQ=h,g.ERR=0,g.ACTER=0,g.MSG=null,a=t.pos,p=e.stack.pos(),r=d[0].clone().req(h),l=r.get(t,e),f=g.id+"_"+Ie(),!1!==l){if(!0!==l)for(var n=E-1;n>0;n--)e.stack.pushAt(p+E-n-1,d[n].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,s=g.min,u=g.max,g.ERR=0,g.REQ=0,g.ACTER=0,g.MSG=null,a=t.pos,p=e.stack.pos(),f=g.id+"_"+Ie(),n=0;E>n;n++){if(r=d[n].clone().req(1),l=r.get(t,e),!1!==l){if(++o,u>=o)return g.found=o,e.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=s>o,g.ERR=o>u||s>o&&i>0,!1}}),k="",d="";{var He=de({constructor:function(t,e){var n=this;n.DEF=e.DEFAULT,n.ERR=e.ERROR,n.Tokens=t.Parser||[],n.cTokens=t.cTokens.length?t.cTokens:null,n.Style=t.Style},ERR:null,DEF:null,cTokens:null,Tokens:null,Style:null,dispose:function(){var t=this;return t.ERR=null,t.DEF=null,t.cTokens=null,t.Tokens=null,t.Style=null,t},parse:function(t){t=t||"";var e,n,r=this,l=t.split(we),o=l.length,s=[];for(n={state:new Ze,tokens:null},e=0;o>e;e++)n=r.getLineTokens(l[e],n.state,e),s=s.concat(n.tokens),o>e+1&&s.push("\n");return s},getLineTokens:function(t,e){var n,r,l,o,s,u,i,c,a,p,f,h=this,g=h.cTokens,k=h.Tokens,d=k.length,E=null,m=h.Style,R=h.DEF,v=h.ERR;for(u=[],p=new Qe(t),f=e.stack,i={type:null,content:""},c=null,a=null,p.sol()&&!f.isEmpty()&&S===f.peek().tt&&f.pop();!p.eol();)if(r=0,R===a||v===a?(i.type&&u.push(i),u.push(p.cur(1)),i={type:null,content:""}):a&&a!==i.type?(i.type&&u.push(i),i={type:a,content:p.cur(1)}):i.type&&(i.content+=p.cur(1)),a=!1,!f.isEmpty()&&C===f.peek().tt||!p.spc()){for(;!f.isEmpty()&&!p.eol();){if(g){for(o=0,l=0;on;n++)if(s=k[n],e.t=c=s.get(p,e),!1!==c){if(!0!==c){a=m[c]||R,s.ACTER&&(f.empty("sID",s.sID),e.t=c=v,a=v,E=s.err()),r=1;break}}else{if(s.ERR||s.REQ){f.empty("sID",s.sID),p.nxt(),e.t=c=v,a=v,E=s.err(),r=1;break}a=!1}if(!r){if(p.eol())break;p.nxt(),e.t=c=R,a=R}}}else e.t=c=R,a=R;return R===a||v===a?(i.type&&u.push(i),u.push(p.cur(1))):a&&a!==i.type?(i.type&&u.push(i),u.push({type:a,content:p.cur(1)})):i.type&&(i.content+=p.cur(1),u.push(i)),i=null,{state:e,tokens:u}}});t.PrismGrammar={VERSION:"1.0.1",extend:ve,parse:h,getMode:g}}return t.PrismGrammar}); \ 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 c6a32f3..03d6635 100644 --- a/src/main.js +++ b/src/main.js @@ -356,9 +356,9 @@ var PrismGrammar = exports['@@MODULE_NAME@@'] = { * extendedgrammar = PrismGrammar.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, @@ -370,9 +370,9 @@ var PrismGrammar = exports['@@MODULE_NAME@@'] = { * parsedgrammar = PrismGrammar.parse( grammar ); * ``` * - * This is used internally by the PrismGrammar 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 `PrismGrammar` Class + * In order to parse a `JSON grammar` to a form suitable to be used by the syntax-highlighter. + * 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, @@ -385,7 +385,7 @@ var PrismGrammar = exports['@@MODULE_NAME@@'] = { * mode = PrismGrammar.getMode( grammar ); * ``` * - * This is the main method which transforms a JSON grammar into a syntax-highlighter for Prism. + * This is the main method which transforms a `JSON grammar` into a syntax-highlighter for `Prism`. [/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 (