Skip to content

Commit

Permalink
v.4.2.0 (editor-grammar)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikos M committed Dec 1, 2016
1 parent 665538c commit f450f10
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 38 deletions.
57 changes: 21 additions & 36 deletions build/codemirror_grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,35 +562,28 @@ function new_re( re, fl )

function get_delimited( src, delim, esc, collapse_esc )
{
var c, i=src.pos||0, l=src.length, s='', escaped;
var i = src.pos||0, l = src.length, dl = delim.length, s = '', escaped;
if ( !!esc )
{
if ( !!collapse_esc )
{
while ( i<l )
{
escaped = false;
c = src[CHAR](i++);
if ( esc === c )
if ( esc === src[CHAR](i) )
{
escaped = true;
c = src[CHAR](i++);
i += 1;
}
if ( delim === c )
if ( delim === src.substr(i,dl) )
{
if ( escaped )
{
s += c;
continue;
}
else
{
break;
}
i += dl;
if ( escaped ) s += delim;
else break;
}
else
{
s += c;
s += src[CHAR](i++);
}
}
}
Expand All @@ -599,28 +592,21 @@ function get_delimited( src, delim, esc, collapse_esc )
while ( i<l )
{
escaped = false;
c = src[CHAR](i++);
if ( esc === c )
if ( esc === src[CHAR](i) )
{
escaped = true;
s += c;
c = src[CHAR](i++);
i += 1;
s += esc;
}
if ( delim === c )
if ( delim === src.substr(i,dl) )
{
if ( escaped )
{
s += c;
continue;
}
else
{
break;
}
i += dl;
if ( escaped ) s += delim;
else break;
}
else
{
s += c;
s += src[CHAR](i++);
}
}
}
Expand All @@ -629,9 +615,8 @@ function get_delimited( src, delim, esc, collapse_esc )
{
while ( i<l )
{
c = src[CHAR](i++);
if ( delim === c ) break;
s += c;
if ( delim === src.substr(i,dl) ) { i += dl; break; }
s += src[CHAR](i++);
}
}
src.pos = i;
Expand Down Expand Up @@ -1626,12 +1611,12 @@ function parse_peg_bnf_notation( tok, Lex, Syntax )
c = t[CHAR]( t.pos+1 );
if ( '^' === c ) t.pos++;
else c = '';
literal = get_delimited( t, ']', '\\', 1 );
literal = get_delimited( t, ']', '\\', 0 );
curr_token = '[' + c+literal + ']';
if ( !Lex[curr_token] )
Lex[curr_token] = {
type:'simple',
tokens:new_re("^(["+c+esc_re(literal)+"])")
tokens:new_re("^(["+c+/*esc_re(*/literal/*)*/+"])")
// negative match, else positive match
/*literal.split('')*/};
sequence.push( curr_token );
Expand Down Expand Up @@ -1686,7 +1671,7 @@ function parse_peg_bnf_notation( tok, Lex, Syntax )
// literal repeat modifier, applies to token that comes before
if ( sequence.length )
{
repeat = get_delimited( t, '}', 0 );
repeat = get_delimited( t, '}', 0, 0 );
repeat = map( repeat.split( ',' ), trim );

if ( !repeat[0].length ) repeat[0] = 0; // {,m} match 0 times or more
Expand Down
Loading

0 comments on commit f450f10

Please sign in to comment.