From 8bf1b67b430ae02cd8b7414f250fc450c2c20db3 Mon Sep 17 00:00:00 2001 From: June 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 95cb499f..d8508c36 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