From 04dc80ccbf3ba015483f2237f2b4b5ddde6f35cb Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 28 Dec 2020 22:09:13 -0500 Subject: Lex strings inside macros --- bin/hilex/c.l | 68 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 32 deletions(-) (limited to 'bin/hilex') diff --git a/bin/hilex/c.l b/bin/hilex/c.l index 159980e2..e208d76b 100644 --- a/bin/hilex/c.l +++ b/bin/hilex/c.l @@ -27,9 +27,15 @@ width "*"|[0-9]+ %% + static int pop = INITIAL; [[:space:]]+ { return Normal; } +^"%" { + BEGIN(pop = MacroLine); + return Macro; +} + ([-+*/%&|^=!<>]|"<<"|">>")"="? | [=~.?:]|"++"|"--"|"&&"|"||"|"->" | sizeof|(_A|alignof) { @@ -51,45 +57,22 @@ register|restrict|return|static|struct|switch|typedef|union|volatile|while | [_[:alpha:]][_[:alnum:]]* { return Identifier; } -^"#" { - BEGIN(MacroLine); - return Macro; -} -^"#"[[:blank:]]*"include" { - BEGIN(MacroInclude); - return Macro; -} -{ - "\n" { - BEGIN(0); - return Macro; - } - "\\\n" { return Macro; } - [^\\\n<"]+|. { return Macro; } -} -{ - "<"[^>]+">" | - "\""[^"]+"\"" { - return String; - } -} - -"//"([^\n]|"\\\n")* | -"/*"([^*]|"*"[^/])*"*"+"/" { +"//"([^\n]|"\\\n")* | +"/*"([^*]|"*"[^/])*"*"+"/" { return Comment; } -[LUu]?"'" { +[LUu]?"'" { BEGIN(CharLiteral); return String; } -([LU]|u8?)?"\"" { +([LU]|u8?)?"\"" { BEGIN(StringLiteral); return String; } { - "\\"['""?\\abfnrtv] | + "\\"[''""?\\abfnrtv] | "\\"([0-7]{1,3}) | "\\x"([[:xdigit:]]{2}) | "\\u"([[:xdigit:]]{4}) | @@ -106,17 +89,38 @@ register|restrict|return|static|struct|switch|typedef|union|volatile|while | { "'" { - BEGIN(0); + BEGIN(pop); return String; } - [^\\']+|. { return String; } + [^\\'']+|. { return String; } } { "\"" { - BEGIN(0); + BEGIN(pop); return String; } - [^%\\"]+|. { return String; } + [^%\\""]+|. { return String; } +} + +^"#" { + BEGIN(pop = MacroLine); + return Macro; +} +^"#"[[:blank:]]*"include" { + BEGIN(pop = MacroInclude); + return Macro; +} +"<"[^>]+">" { + BEGIN(pop = MacroLine); + return String; +} +{ + "\n" { + BEGIN(pop = INITIAL); + return Macro; + } + "\\\n" { return Macro; } + [^\\\n/<>''""]+|. { return Macro; } } . { return Normal; } -- cgit 1.4.1 mit message (Expand)Author 2017-07-21Add hnelJune McEnroe 2017-07-19chmod 600 in dtchJune McEnroe -0400'>2020-06-01Allow redirecting input in everJune McEnroe 2020-05-31Add %c conversion to c scriptJune McEnroe 2020-05-31Add c script to READMEJune McEnroe 2020-05-31Add c scriptJune McEnroe 2020-05-31Update mdoc source URLsJune McEnroe 2020-05-26Remove unfinished PSF fontsJune McEnroe