From 9f01c475421ccfcad25607773e2d9b72a002bce3 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 20 Apr 2017 16:23:36 -0500 Subject: [PATCH] Allow whitespace before comments in AS config files Fixes lp: #1677302 Makes the lexer patterns more like dbStatic. Handle non-printable invalid characters in input properly. --- src/as/asLib_lex.l | 52 ++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/as/asLib_lex.l b/src/as/asLib_lex.l index 5e0451925..924105c14 100644 --- a/src/as/asLib_lex.l +++ b/src/as/asLib_lex.l @@ -3,18 +3,21 @@ * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found -* in file LICENSE that is included with this distribution. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. \*************************************************************************/ -digit [0-9] -name [a-zA-Z0-9_\-:\.\[\]<>;] -notquote [^\"] -escapequote \\\" -string {notquote}|{escapequote} +newline "\n" +backslash "\\" +doublequote "\"" +comment "#" whitespace [ \t\r] +escape {backslash}. +stringchar [^"\n\\] + +name [a-zA-Z0-9_\-+:.\[\]<>;] +digit [0-9] punctuation [(){},] -link [A-L] +link [A-L] %{ static ASINPUTFUNCPTR *my_yyinput; @@ -37,46 +40,55 @@ HAG { return(tokenHAG); } ASG { return(tokenASG); } RULE { return(tokenRULE); } CALC { return(tokenCALC); } + INP{link} { yylval.Int = (unsigned char)yytext[3]; yylval.Int -= 'A'; return(tokenINP); - } +} {digit}+ { /*integer*/ yylval.Int = atoi((char *)yytext); return(tokenINTEGER); - } +} {name}+ { /*unquoted string*/ yylval.Str=asStrdup(yytext); return(tokenSTRING); - } +} -\"{string}*\" { /*quoted string*/ - /* making sure that neither double quote gets passed back */ +{doublequote}({stringchar}|{escape})*{doublequote} { /* quoted string */ yylval.Str=asStrdup(yytext+1); yylval.Str[strlen(yylval.Str)-1] = '\0'; return(tokenSTRING); - } +} + +{doublequote}({stringchar}|{escape})*{newline} { /* bad string */ + yyerror("Newline in quoted string, closing quote missing"); +} {punctuation} { return(yytext[0]); } -^#.* -{whitespace} ; +{newline} { line_num++; } -\n { line_num ++;} +{comment}.* ; +{whitespace} ; . { char message[40]; YY_BUFFER_STATE *dummy=0; - sprintf(message,"invalid character '%c'",yytext[0]); + if (isprint((int) yytext[0])) { + sprintf(message, "Invalid character '%c'", yytext[0]); + } + else { + sprintf(message, "Invalid character 0x%2.2x", yytext[0]); + } yyerror(message); /*The following suppress compiler warning messages*/ if (0) yyunput('c',(unsigned char *) message); if (0) yy_switch_to_buffer(*dummy); - } +} %%