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 message (Expand)Author 2018-02-13Add PNG stream splitterJune McEnroe 2018-02-12Dump gfxx screen to PNG on stdout with xJune McEnroe 2018-02-12Add PNG encoder to gfxxJune McEnroe 2018-02-12Only list first space of tabsJune McEnroe 2018-02-12Use Intel syntax in LLDBJune McEnroe 2018-02-11Add "Close Window" menu item to gfx/cocoaJune McEnroe 2018-02-11Tweak gfxx code styleJune McEnroe 2018-02-11Avoid xres/yres names in gfxxJune McEnroe 2018-02-11Only set GFX if unsetJune McEnroe 2018-02-09Link -lncursesJune McEnroe 2018-02-09Fix X11 KeySym lookup with modifiersJune McEnroe 2018-02-09Clean up bin/gfx/x11.cJune McEnroe 2018-02-09Move gfx interface to header fileJune McEnroe 2018-02-09Silence BSD ctags warningsJune McEnroe 2018-02-09Link LDLIBS regardless of GFXJune McEnroe 2018-02-09Move gfx frontends around to simplify buildJune McEnroe 2018-02-07Add janky X11 graphics frontendJune McEnroe 2018-02-07Include stdio.h in gfb.cJune McEnroe 2018-02-07Exit by returning false from input to gf{b,cocoa}June McEnroe 2018-02-07Rename title to status in gfcocoaJune McEnroe 2018-02-06Require 4 bit counts on gfxx command lineJune McEnroe 2018-02-06Add gfxx controls for custom bitsJune McEnroe 2018-02-06Add gfxx palette loading and dumpingJune McEnroe 2018-02-06Add tags targetJune McEnroe 2018-02-06Replace gfxx SCALE macro with interp functionJune McEnroe 2018-02-05Rename gfxx space indexed and add palette samplingJune McEnroe 2018-02-05Take scale into account for when to stop drawing in gfxxJune McEnroe 2018-02-05Always skip most significant bits in gfxxJune McEnroe 2018-02-05Set title in gfcocoaJune McEnroe 2018-02-05Double-buffer gfb frontendJune McEnroe 2018-02-05Rewrite gfxx bit handlingJune McEnroe 2018-02-05Add flip option to gfxxJune McEnroe 2018-02-05Remove gfxx reverse optionJune McEnroe 2018-02-04Fix gfxx draw stop conditionJune McEnroe 2018-02-04Reuse CGColorSpace and CGDataProvider in gfcocoaJune McEnroe 2018-02-04Mark mac target phonyJune McEnroe 2018-02-04Set up Makefile for gfxx-cocoa or gfxx-fbJune McEnroe 2018-02-04Avoid doing excessive work in gfxxJune McEnroe 2018-02-04Handle window resizing in gfcocoaJune McEnroe 2018-02-04Set cinoptionsJune McEnroe 2018-02-04Tweak colorscheme moreJune McEnroe 2018-02-04Color MatchParen DarkYellowJune McEnroe 2018-02-04Add palette sampling to gfxxJune McEnroe 2018-02-04Add 4-bit RGB to gfxxJune McEnroe 2018-02-04Add Quit menu item to gfcocoaJune McEnroe 2018-02-04Switch back to sane Objective-C styleJune McEnroe 2018-02-04Quit gfcocoa when window closesJune McEnroe 2018-02-03Apparently this is how people write Objective-CJune McEnroe