X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fmetadata%2Fctf-lexer.l;h=6b605a0fe583dab98eb6c59feaad0e8b259d7245;hb=4cb26dfbd763c06d99bf1069e2d1f3a569858e32;hp=c79b6c83b5491cc0df9ecd023cd824c715c7c10e;hpb=d4050a6975dffde3b369258ef7d2d9f32371ace9;p=babeltrace.git diff --git a/formats/ctf/metadata/ctf-lexer.l b/formats/ctf/metadata/ctf-lexer.l index c79b6c83..6b605a0f 100644 --- a/formats/ctf/metadata/ctf-lexer.l +++ b/formats/ctf/metadata/ctf-lexer.l @@ -26,11 +26,22 @@ */ #include +#include #include #include "ctf-scanner.h" #include "ctf-parser.h" #include "ctf-ast.h" +#define PARSE_INTEGER_LITERAL(base) \ + do { \ + errno = 0; \ + yylval->ull = strtoull(yytext, NULL, base); \ + if (errno) { \ + printfl_perror(yylineno, "Integer literal"); \ + return ERROR; \ + } \ + } while (0) + BT_HIDDEN void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src); @@ -38,13 +49,16 @@ static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner) __attribute__((unused)); static int input (yyscan_t yyscanner) __attribute__((unused)); +BT_HIDDEN +int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src, char delim); + %} %x comment_ml comment_sl string_lit char_const %option reentrant yylineno noyywrap bison-bridge %option extra-type="struct ctf_scanner *" /* bison-locations */ -INTEGER_SUFFIX [ \n\t]*(U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu) +INTEGER_SUFFIX (U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu) DIGIT [0-9] NONDIGIT [a-zA-Z_] HEXDIGIT [0-9A-Fa-f] @@ -53,7 +67,6 @@ UCHARLOWERCASE \\u{HEXDIGIT}{4} UCHARUPPERCASE \\U{HEXDIGIT}{8} ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE} IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})* -ESCSEQ \\(\'|\"|\?|\\|a|b|f|n|r|t|v|{OCTALDIGIT}{1,3}|u{HEXDIGIT}{4}|U{HEXDIGIT}{8}|x{HEXDIGIT}+) %% /* @@ -67,20 +80,10 @@ ESCSEQ \\(\'|\"|\?|\\|a|b|f|n|r|t|v|{OCTALDIGIT}{1,3}|u{HEXDIGIT}{4}|U{HEXDIG \n "*"+"/" BEGIN(INITIAL); -"//" BEGIN(comment_sl); -[^\n]*\n BEGIN(INITIAL); +"//"[^\n]*\n /* skip comment */ -L\' BEGIN(char_const); return CHARACTER_CONSTANT_START; -\' BEGIN(char_const); return CHARACTER_CONSTANT_START; -\' BEGIN(INITIAL); return SQUOTE; - -L\" BEGIN(string_lit); return STRING_LITERAL_START; -\" BEGIN(string_lit); return STRING_LITERAL_START; -\" BEGIN(INITIAL); return DQUOTE; - -ESCSEQ return ESCSEQ; -\n ; /* ignore */ -. setstring(yyextra, yylval, yytext); return CHAR_STRING_TOKEN; +L?\"(\\.|[^\\"])*\" { if (import_string(yyextra, yylval, yytext, '\"') < 0) return ERROR; else return STRING_LITERAL; } +L?\'(\\.|[^\\'])*\' { if (import_string(yyextra, yylval, yytext, '\'') < 0) return ERROR; else return CHARACTER_LITERAL; } "[" return LSBRAC; "]" return RSBRAC; @@ -129,9 +132,10 @@ void setstring(yyextra, yylval, yytext); return VOID; _Bool setstring(yyextra, yylval, yytext); return _BOOL; _Complex setstring(yyextra, yylval, yytext); return _COMPLEX; _Imaginary setstring(yyextra, yylval, yytext); return _IMAGINARY; -[1-9]{DIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return DECIMAL_CONSTANT; -0{OCTALDIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return OCTAL_CONSTANT; -0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return HEXADECIMAL_CONSTANT; +[1-9]{DIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(10); return INTEGER_LITERAL; +0{OCTALDIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(8); return INTEGER_LITERAL; +0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(16); return INTEGER_LITERAL; + {IDENTIFIER} printf_debug("\n", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER; [ \t\r\n] ; /* ignore */ . printfl_error(yylineno, "invalid character '0x%02X'", yytext[0]); return ERROR;