Thrift compiler frontend support for constants
Summary: The parser now accepts constants and adds them into the parse tree
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664880 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/thrift.l b/compiler/cpp/src/thrift.l
index e93bd26..0c113cb 100644
--- a/compiler/cpp/src/thrift.l
+++ b/compiler/cpp/src/thrift.l
@@ -27,14 +27,16 @@
* Helper definitions, comments, constants, and whatnot
*/
-intconstant ([0-9]+)
+intconstant ([+-]?[0-9]+)
+dubconstant ([+-]?[0-9]*(\.[0-9]+)?([eE][+-]?[0-9]+)?)
identifier ([a-zA-Z_][\.a-zA-Z_0-9]*)
whitespace ([ \t\r\n]*)
multicomm ("/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/")
comment ("//"[^\n]*)
unixcomment ("#"[^\n]*)
symbol ([:;\,\{\}\(\)\=<>\[\]])
-literal ("\""[^"]*"\"")
+dliteral ("\""[^"]*"\"")
+sliteral ("'"[^']*"'")
%%
@@ -71,18 +73,30 @@
"throws" { return tok_throws; }
"service" { return tok_service; }
"enum" { return tok_enum; }
+"const" { return tok_const; }
{intconstant} {
yylval.iconst = atoi(yytext);
return tok_int_constant;
}
+{dubconstant} {
+ yylval.dconst = atof(yytext);
+ return tok_dub_constant;
+}
+
{identifier} {
yylval.id = strdup(yytext);
return tok_identifier;
}
-{literal} {
+{dliteral} {
+ yylval.id = strdup(yytext+1);
+ yylval.id[strlen(yylval.id)-1] = '\0';
+ return tok_literal;
+}
+
+{sliteral} {
yylval.id = strdup(yytext+1);
yylval.id[strlen(yylval.id)-1] = '\0';
return tok_literal;