From 8e0bde3071916eb21230332a1bae1c7b773ae193 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Fri, 11 Jan 2019 02:54:27 -0500 Subject: [PATCH] lang: Move capitalized res identifier into parser This gives us more specificity when trying to match exactly. --- lang/lexer.nex | 7 ------- lang/parser.y | 40 +++++++++++++++------------------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/lang/lexer.nex b/lang/lexer.nex index bb3893e8..255b3330 100644 --- a/lang/lexer.nex +++ b/lang/lexer.nex @@ -369,13 +369,6 @@ lval.str = yylex.Text() return RES_IDENTIFIER } -/[A-Z]([a-z0-9:]*[a-z0-9]+)?/ - { - yylex.pos(lval) // our pos - s := yylex.Text() - lval.str = strings.ToLower(s) // uncapitalize it - return CAPITALIZED_RES_IDENTIFIER - } /#[^\n]*/ { // this matches a (#) pound char followed by any // number of chars that aren't the (\n) newline! diff --git a/lang/parser.y b/lang/parser.y index 3e642fa2..5bc7c13e 100644 --- a/lang/parser.y +++ b/lang/parser.y @@ -85,7 +85,7 @@ func init() { %token STR_IDENTIFIER BOOL_IDENTIFIER INT_IDENTIFIER FLOAT_IDENTIFIER %token MAP_IDENTIFIER STRUCT_IDENTIFIER VARIANT_IDENTIFIER VAR_IDENTIFIER %token VAR_IDENTIFIER_HX -%token RES_IDENTIFIER CAPITALIZED_RES_IDENTIFIER +%token RES_IDENTIFIER %token IDENTIFIER CAPITALIZED_IDENTIFIER %token FUNC_IDENTIFIER %token CLASS_IDENTIFIER INCLUDE_IDENTIFIER @@ -1030,18 +1030,7 @@ edge_half_list: ; edge_half: // eg: Test["t1"] - CAPITALIZED_RES_IDENTIFIER OPEN_BRACK expr CLOSE_BRACK - { - posLast(yylex, yyDollar) // our pos - $$.edgeHalf = &StmtEdgeHalf{ - Kind: $1.str, - Name: $3.expr, - //SendRecv: "", // unused - } - } - // note: this is a simplified version of the above if the lexer picks it - // note: must not include underscores, but that is checked after parsing -| CAPITALIZED_IDENTIFIER OPEN_BRACK expr CLOSE_BRACK + capitalized_res_identifier OPEN_BRACK expr CLOSE_BRACK { posLast(yylex, yyDollar) // our pos $$.edgeHalf = &StmtEdgeHalf{ @@ -1053,18 +1042,7 @@ edge_half: ; edge_half_sendrecv: // eg: Test["t1"].foo_send - CAPITALIZED_RES_IDENTIFIER OPEN_BRACK expr CLOSE_BRACK DOT IDENTIFIER - { - posLast(yylex, yyDollar) // our pos - $$.edgeHalf = &StmtEdgeHalf{ - Kind: $1.str, - Name: $3.expr, - SendRecv: $6.str, - } - } - // note: this is a simplified version of the above if the lexer picks it - // note: must not include underscores, but that is checked after parsing -| CAPITALIZED_IDENTIFIER OPEN_BRACK expr CLOSE_BRACK DOT IDENTIFIER + capitalized_res_identifier OPEN_BRACK expr CLOSE_BRACK DOT IDENTIFIER { posLast(yylex, yyDollar) // our pos $$.edgeHalf = &StmtEdgeHalf{ @@ -1176,6 +1154,18 @@ dotted_var_identifier: $$.str = $2.str } ; +capitalized_res_identifier: + CAPITALIZED_IDENTIFIER + { + posLast(yylex, yyDollar) // our pos + $$.str = $1.str + } +| capitalized_res_identifier COLON IDENTIFIER + { + posLast(yylex, yyDollar) // our pos + $$.str = $1.str + ":" + $3.str + } +; %% // pos is a helper function used to track the position in the parser. func pos(y yyLexer, dollar yySymType) {