summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-12-29 15:05:39 -0500
committerJune McEnroe <june@causal.agency>2020-12-29 15:05:39 -0500
commit9c54e90449677f6ea47dfd5b02d77385f87ade3c (patch)
treeae63370d874797d85985836f1db5a820dcb0cbb5
parentReconfigure C macro start conditions (diff)
downloadsrc-9c54e90449677f6ea47dfd5b02d77385f87ade3c.tar.gz
src-9c54e90449677f6ea47dfd5b02d77385f87ade3c.zip
Match function-like macro definitions as IdentifierTag
Diffstat (limited to '')
-rw-r--r--bin/hilex/c.l23
1 files changed, 19 insertions, 4 deletions
diff --git a/bin/hilex/c.l b/bin/hilex/c.l
index 056867ce..3b0bcab3 100644
--- a/bin/hilex/c.l
+++ b/bin/hilex/c.l
@@ -21,7 +21,7 @@
 #include "hilex.h"
 %}
 
-%s MacroLine MacroInclude
+%s MacroLine MacroInclude MacroDefine
 %x CharLiteral StringLiteral
 
 ident [_[:alpha:]][_[:alnum:]]*
@@ -36,6 +36,10 @@ width "*"|[0-9]+
 	BEGIN(pop = MacroInclude);
 	return Macro;
 }
+^"#"[[:blank:]]*"define" {
+	BEGIN(pop = MacroDefine);
+	return Macro;
+}
 ^[#%][[:blank:]]*{ident} {
 	BEGIN(pop = MacroLine);
 	return Macro;
@@ -43,7 +47,18 @@ width "*"|[0-9]+
 
 <MacroInclude>"<"[^>]+">" { return String; }
 
-<MacroLine,MacroInclude>{
+<MacroDefine>{
+	{ident}/"(" {
+		BEGIN(pop = MacroLine);
+		return IdentifierTag;
+	}
+	{ident} {
+		BEGIN(pop = MacroLine);
+		return Macro;
+	}
+}
+
+<MacroLine,MacroInclude,MacroDefine>{
 	"\n" {
 		BEGIN(pop = INITIAL);
 		return Normal;
@@ -70,7 +85,7 @@ register|restrict|return|static|struct|switch|typedef|union|volatile|while |
 	return Keyword;
 }
 
-<MacroLine,MacroInclude>{ident} { return Macro; }
+<MacroLine>{ident} { return Macro; }
 {ident} { return Identifier; }
 
 "//"([^\n]|"\\\n")* |
@@ -118,7 +133,7 @@ register|restrict|return|static|struct|switch|typedef|union|volatile|while |
 	[^%\\""]+|. { return String; }
 }
 
-<MacroLine,MacroInclude>. { return Macro; }
+<MacroLine,MacroInclude,MacroDefine>. { return Macro; }
 
 .|\n { return Normal; }