From b632667ce57af89691407bb8668e1512775278ae Mon Sep 17 00:00:00 2001 From: Calvin Date: Fri, 15 Mar 2013 15:26:20 -0400 Subject: nbc added --- src/nbc/substitution.lex | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/nbc/substitution.lex (limited to 'src/nbc/substitution.lex') diff --git a/src/nbc/substitution.lex b/src/nbc/substitution.lex new file mode 100644 index 0000000..e460121 --- /dev/null +++ b/src/nbc/substitution.lex @@ -0,0 +1,54 @@ +type svalue = Tokens.svalue +type ('a, 'b) token = ('a, 'b) Tokens.token +type pos = int +type lexresult = (svalue, pos) token +type arg = int ref +fun eof _ = Tokens.EOF (~1, ~1) +%% +%full +%header (functor SubstitutionLexFun (structure Tokens: SubstitutionGrm_TOKENS)); +%arg (nesting); +%s VARIABLE PARENTHESIZED BRACED; +text = ([^$] | "\\$")+; +dollar = "$"; +leftparenthesis = "("; +rightparenthesis = ")"; +notparenthesis = [^()]+; +leftbrace = "{"; +rightbrace = "}"; +notbrace = [^{}]+; +other = [A-Za-z0-9_]+; +%% +{text} => (Tokens.TEXT (yytext, yypos, yypos + size yytext)); +{dollar} => (YYBEGIN VARIABLE; Tokens.DOLLAR (yypos, yypos + 1)); +{dollar}{leftparenthesis} => ( + YYBEGIN PARENTHESIZED + ; nesting := !nesting + 1 + ; Tokens.LEFT_PARENTHESIS (yypos, yypos + 1) +); +{dollar}{leftbrace} => ( + YYBEGIN BRACED + ; nesting := !nesting + 1 + ; Tokens.LEFT_BRACE (yypos, yypos + 1) +); +{other} => (YYBEGIN INITIAL; Tokens.TEXT (yytext, yypos, yypos + size yytext)); +{notparenthesis} => (Tokens.TEXT (yytext, yypos, yypos + size yytext)); +{leftparenthesis} => ( + nesting := !nesting + 1 + ; Tokens.LEFT_PARENTHESIS (yypos, yypos + 1) +); +{rightparenthesis} => ( + nesting := !nesting - 1 + ; if !nesting = 0 then YYBEGIN INITIAL else () + ; Tokens.RIGHT_PARENTHESIS (yypos, yypos + 1) +); +{notbrace} => (Tokens.TEXT (yytext, yypos, yypos + size yytext)); +{leftbrace} => ( + nesting := !nesting + 1 + ; Tokens.LEFT_BRACE (yypos, yypos + 1) +); +{rightbrace} => ( + nesting := !nesting - 1 + ; if !nesting = 0 then YYBEGIN INITIAL else () + ; Tokens.RIGHT_BRACE (yypos, yypos + 1) +); -- cgit v1.2.3