diff options
author | June McEnroe <june@causal.agency> | 2020-12-28 22:09:13 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-12-28 22:09:13 -0500 |
commit | 8bf1b67b430ae02cd8b7414f250fc450c2c20db3 (patch) | |
tree | a2ae8545bc1eb2cd3ddfc1f8710817263ed5269e | |
parent | Set H_SETUNIQUE (diff) | |
download | src-8bf1b67b430ae02cd8b7414f250fc450c2c20db3.tar.gz src-8bf1b67b430ae02cd8b7414f250fc450c2c20db3.zip |
Lex strings inside macros
-rw-r--r-- | bin/hilex/c.l | 68 |
1 files changed, 36 insertions, 32 deletions
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; -} -<MacroLine,MacroInclude>{ - "\n" { - BEGIN(0); - return Macro; - } - "\\\n" { return Macro; } - [^\\\n<"]+|. { return Macro; } -} -<MacroInclude>{ - "<"[^>]+">" | - "\""[^"]+"\"" { - return String; - } -} - -"//"([^\n]|"\\\n")* | -"/*"([^*]|"*"[^/])*"*"+"/" { +<INITIAL,MacroLine>"//"([^\n]|"\\\n")* | +<INITIAL,MacroLine>"/*"([^*]|"*"[^/])*"*"+"/" { return Comment; } -[LUu]?"'" { +<INITIAL,MacroLine>[LUu]?"'" { BEGIN(CharLiteral); return String; } -([LU]|u8?)?"\"" { +<INITIAL,MacroLine,MacroInclude>([LU]|u8?)?"\"" { BEGIN(StringLiteral); return String; } <CharLiteral,StringLiteral>{ - "\\"['""?\\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 | <CharLiteral>{ "'" { - BEGIN(0); + BEGIN(pop); return String; } - [^\\']+|. { return String; } + [^\\'']+|. { return String; } } <StringLiteral>{ "\"" { - BEGIN(0); + BEGIN(pop); return String; } - [^%\\"]+|. { return String; } + [^%\\""]+|. { return String; } +} + +^"#" { + BEGIN(pop = MacroLine); + return Macro; +} +^"#"[[:blank:]]*"include" { + BEGIN(pop = MacroInclude); + return Macro; +} +<MacroInclude>"<"[^>]+">" { + BEGIN(pop = MacroLine); + return String; +} +<MacroLine,MacroInclude>{ + "\n" { + BEGIN(pop = INITIAL); + return Macro; + } + "\\\n" { return Macro; } + [^\\\n/<>''""]+|. { return Macro; } } . { return Normal; } |