new try: optimized yang string parsing
This commit is contained in:
parent
8279c015d8
commit
a20865846e
2 changed files with 20 additions and 16 deletions
|
|
@ -191,14 +191,14 @@ identifier [A-Za-z_][A-Za-z0-9_\-\.]*
|
|||
<KEYWORD>\} { return *yytext; }
|
||||
<KEYWORD>; { return *yytext; }
|
||||
<KEYWORD>. { clixon_yang_parselval.string = strdup(yytext);
|
||||
BEGIN(UNKNOWN); return CHAR; }
|
||||
BEGIN(UNKNOWN); return CHARS; }
|
||||
|
||||
<UNKNOWN>: { return *yytext; }
|
||||
<UNKNOWN>; { BEGIN(KEYWORD); return *yytext; }
|
||||
<UNKNOWN>\" { _YY->yy_lex_string_state =UNKNOWN; BEGIN(STRINGDQ); return *yytext; }
|
||||
<UNKNOWN>\{ { BEGIN(KEYWORD); return *yytext; }
|
||||
<UNKNOWN>. { clixon_yang_parselval.string = strdup(yytext);
|
||||
return CHAR; }
|
||||
return CHARS; }
|
||||
|
||||
<BOOLEAN>true { clixon_yang_parselval.string = strdup(yytext);
|
||||
return BOOL; }
|
||||
|
|
@ -226,22 +226,26 @@ identifier [A-Za-z_][A-Za-z0-9_\-\.]*
|
|||
<STRING>\' { _YY->yy_lex_string_state =STRING; BEGIN(STRINGSQ); return SQ; }
|
||||
<STRING>\+ { return *yytext; }
|
||||
<STRING>. { clixon_yang_parselval.string = strdup(yytext);
|
||||
return CHAR;}
|
||||
return CHARS;}
|
||||
|
||||
<STRINGDQ>\\ { _YY->yy_lex_state = STRINGDQ; BEGIN(ESCAPE); }
|
||||
<STRINGDQ>\" { BEGIN(_YY->yy_lex_string_state); return *yytext; }
|
||||
<STRINGDQ>\n { _YY->yy_linenum++; clixon_yang_parselval.string = strdup(yytext); return CHAR;}
|
||||
<STRINGDQ>. { clixon_yang_parselval.string = strdup(yytext);
|
||||
return CHAR;}
|
||||
<STRINGDQ>\\ { _YY->yy_lex_state = STRINGDQ; BEGIN(ESCAPE); }
|
||||
<STRINGDQ>\" { BEGIN(_YY->yy_lex_string_state); return *yytext; }
|
||||
<STRINGDQ>\n { _YY->yy_linenum++;
|
||||
clixon_yang_parselval.string = strdup(yytext);
|
||||
return CHARS;}
|
||||
<STRINGDQ>[^\\"\n]+ { clixon_yang_parselval.string = strdup(yytext);
|
||||
return CHARS;}
|
||||
|
||||
<STRINGSQ>\' { BEGIN(_YY->yy_lex_string_state); return SQ; }
|
||||
<STRINGSQ>\n { _YY->yy_linenum++; clixon_yang_parselval.string = strdup(yytext); return CHAR;}
|
||||
<STRINGSQ>. { clixon_yang_parselval.string = strdup(yytext);
|
||||
return CHAR;}
|
||||
<STRINGSQ>\' { BEGIN(_YY->yy_lex_string_state); return SQ; }
|
||||
<STRINGSQ>\n { _YY->yy_linenum++;
|
||||
clixon_yang_parselval.string = strdup(yytext);
|
||||
return CHARS;}
|
||||
<STRINGSQ>[^'\n]+ { clixon_yang_parselval.string = strdup(yytext);
|
||||
return CHARS;}
|
||||
|
||||
<ESCAPE>. { BEGIN(_YY->yy_lex_state);
|
||||
clixon_yang_parselval.string = strdup(yytext);
|
||||
return CHAR; }
|
||||
return CHARS; }
|
||||
<COMMENT1>[^*\n]* /* eat anything that's not a '*' */
|
||||
<COMMENT1>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
|
||||
<COMMENT1>"*"+"/" BEGIN(_YY->yy_lex_state);
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
|
||||
%token MY_EOF
|
||||
%token SQ /* Single quote: ' */
|
||||
%token <string> CHAR
|
||||
%token <string> CHARS
|
||||
%token <string> IDENTIFIER
|
||||
%token <string> BOOL
|
||||
%token <string> INT
|
||||
|
|
@ -1726,14 +1726,14 @@ qstring : '"' ustring '"' { $$=$2; clicon_debug(2,"string-> \" ustring \
|
|||
;
|
||||
|
||||
/* unquoted string */
|
||||
ustring : ustring CHAR
|
||||
ustring : ustring CHARS
|
||||
{
|
||||
int len = strlen($1);
|
||||
$$ = realloc($1, len+strlen($2) + 1);
|
||||
sprintf($$+len, "%s", $2);
|
||||
free($2);
|
||||
}
|
||||
| CHAR
|
||||
| CHARS
|
||||
{$$=$1; }
|
||||
;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue