From 6de9bdf4c5b7361c445ab984cf0258442d3bd9db Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Tue, 29 Dec 2020 15:00:43 -0500 Subject: Reconfigure C macro start conditions --- bin/hilex/c.l | 55 ++++++++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/bin/hilex/c.l b/bin/hilex/c.l index e6bd9ad0..056867ce 100644 --- a/bin/hilex/c.l +++ b/bin/hilex/c.l @@ -21,21 +21,36 @@ #include "hilex.h" %} -%x MacroLine MacroInclude +%s MacroLine MacroInclude %x CharLiteral StringLiteral +ident [_[:alpha:]][_[:alnum:]]* width "*"|[0-9]+ %% static int pop = INITIAL; -[[:space:]]+ { return Normal; } +[[:blank:]]+ { return Normal; } -^"%" { +^"#"[[:blank:]]*("include"|"import") { + BEGIN(pop = MacroInclude); + return Macro; +} +^[#%][[:blank:]]*{ident} { BEGIN(pop = MacroLine); return Macro; } +"<"[^>]+">" { return String; } + +{ + "\n" { + BEGIN(pop = INITIAL); + return Normal; + } + "\\\n" { return Macro; } +} + ([-+*/%&|^=!<>]|"<<"|">>")"="? | [=~.?:]|"++"|"--"|"&&"|"||"|"->" | sizeof|(_A|alignof) { @@ -55,18 +70,19 @@ register|restrict|return|static|struct|switch|typedef|union|volatile|while | return Keyword; } -[_[:alpha:]][_[:alnum:]]* { return Identifier; } +{ident} { return Macro; } +{ident} { return Identifier; } -"//"([^\n]|"\\\n")* | -"/*"([^*]|"*"[^/])*"*"+"/" { +"//"([^\n]|"\\\n")* | +"/*"([^*]|"*"[^/])*"*"+"/" { return Comment; } -[LUu]?"'" { +[LUu]?"'" { BEGIN(CharLiteral); return String; } -([LU]|u8?)?"\"" { +([LU]|u8?)?"\"" { BEGIN(StringLiteral); return String; } @@ -102,28 +118,9 @@ register|restrict|return|static|struct|switch|typedef|union|volatile|while | [^%\\""]+|. { return String; } } -^"#" { - BEGIN(pop = MacroLine); - return Macro; -} -^"#"[[:blank:]]*("include"|"import") { - BEGIN(pop = MacroInclude); - return Macro; -} -"<"[^>]+">" { - BEGIN(pop = MacroLine); - return String; -} -{ - "\n" { - BEGIN(pop = INITIAL); - return Macro; - } - "\\\n" { return Macro; } - [^\\\n/<>''""]+|. { return Macro; } -} +. { return Macro; } -. { return Normal; } +.|\n { return Normal; } %{ (void)yyunput; -- cgit 1.4.1 atsh?id=05a6358cf5be03769b4b14f8ee9d3c57437dc86a&showmsg=1&follow=1'>catsh/libedit/filecomplete.c (unfollow)
Commit message (Collapse)Author
2019-05-10Use val instead of suboptargJune McEnroe
suboptarg doesn't exist in GNU. Hopefully BSD getsubopt also sets val on failure?
2019-05-09Add Parable of the SowerJune McEnroe
2019-05-07Add bit without buildJune McEnroe
Need to do some stuff in the Makefile for lex and yacc and generating HTML pages for it.
2019-05-04Fix MANDIR typoJune McEnroe
2019-05-04Move relay to binJune McEnroe