X-Git-Url: http://nitlanguage.org diff --git a/contrib/nitcc/src/nitcc.sablecc b/contrib/nitcc/src/nitcc.sablecc index 130743a..d435c77 100644 --- a/contrib/nitcc/src/nitcc.sablecc +++ b/contrib/nitcc/src/nitcc.sablecc @@ -7,7 +7,7 @@ Lexer id = ('a'..'z')('a'..'z'|'0'..'9'|'_')*; // A printable character (inside strings) -ch = ' ' .. '~'; +ch = ' ' ...; // Literal strings str = '\'' (ch-'\\'-'\''|'\\'ch)* '\''; @@ -15,10 +15,13 @@ str = '\'' (ch-'\\'-'\''|'\\'ch)* '\''; // A char by decimal ascii ch_dec = '#' ('0'..'9')+ ; +// A char by hexadecimal ascii +ch_hex = '#' ('x'|'X') ('0'..'9'|'a'..'z'|'A'..'Z')+ ; + // A single-line comment comment = '//' ch* '\n'?; -any = '\t'..'~'; +any = '\t' ...; not_star = any - '*'; not_star_not_slash = not_star - '/'; @@ -27,14 +30,14 @@ ccomment = '/*' not_star* ('*' (not_star_not_slash not_star*)?)* '*/'; unknown_keyword = 'A'..'Z'('A'..'Z'|'a'..'z'|'0'..'9'|'_')*; // Igndored stufs -blank = '\n' | '\t' | ' ' | comment | ccomment; +blank = '\r' | '\n' | '\t' | ' ' | comment | ccomment; Parser Ignored blank; Rejected unknown_keyword; -grammar = 'Grammar' id ';' lexer_part? parser_part?; +grammar = 'Grammar' id ';' lexer_part? parser_part? tree_part?; lexer_part = 'Lexer' expr*; @@ -59,21 +62,29 @@ re3 {-> re} = {ques:} re3 '?' | {star:} re3 '*' | {plus:} re3 '+' | + {shortest:} 'Shortest' '(' re ')' | + {longest:} 'Longest' '(' re ')' | + {prefixes:} 'Prefixes' '(' re ')' | {id:} id | - {str:} str | {par:} '(' re ')' | - {class:} str '.' '.' str | + {class:} text '.' '.' text | + {openclass:} text '.' '.' '.' | {any:} 'Any' | - {ch_dec:} ch_dec ; + {end:} 'End' | + {text:} text ; +text {-> re} = + {str:} str | + {ch_dec:} ch_dec | + {ch_hex:} ch_hex ; parser_part = 'Parser' ign? rej? prod*; -ign = 'Ignored' id ';' ; +ign = 'Ignored' elem_list ';' ; rej = 'Rejected' elem_list ';' ; -prod = id ptrans? '=' alts ';'; +prod = id ptrans? '=' alts priority* ';'; ptrans = '{' '->' id '}'; atrans = '{' '->' '}'; @@ -96,7 +107,15 @@ elem_list = elem = {id:} id | - {str:} str | + {str:} text | {star:} elem '*' | {ques:} elem '?' | - {plus:} elem '+' ; + {plus:} elem '+' | + {empty:} 'Empty' ; + +priority = + {left:} 'Left' alts | + {right:} 'Right' alts | + {unary:} 'Unary' alts ; + +tree_part = 'Tree' prod*;