From c277129386f1acfe133da11f23a7d730ae48964d Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Tue, 12 Jan 2021 22:06:56 -0500 Subject: Move hilex out of hilex directory --- bin/c11.l | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 bin/c11.l (limited to 'bin/c11.l') diff --git a/bin/c11.l b/bin/c11.l new file mode 100644 index 00000000..d7a80ae2 --- /dev/null +++ b/bin/c11.l @@ -0,0 +1,139 @@ +/* Copyright (C) 2020 June McEnroe + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +%option prefix="c11" +%option noyywrap + +%{ +#include "hilex.h" +%} + +%s MacroLine MacroInclude +%x CharLiteral StringLiteral + +ident [_[:alpha:]][_[:alnum:]]* +width "*"|[0-9]+ + +%% + static int pop = INITIAL; + +[[:blank:]]+ { return Normal; } + +^"%"[%{}]? { + BEGIN(pop = MacroLine); + return Macro; +} + +([-+*/%&|^=!<>]|"<<"|">>")"="? | +[=~.?:]|"++"|"--"|"&&"|"||"|"->" | +sizeof|(_A|alignof) { + return Operator; +} + +([1-9][0-9]*|"0"[0-7]*|"0x"[[:xdigit:]]+)([ulUL]{0,3}) | +[0-9]*("."[0-9]*)?([eE][+-]?[0-9]+)?[flFL]? | +"0x"[[:xdigit:]]*("."[[:xdigit:]]*)?([pP][+-]?[0-9]+)[flFL]? { + return Number; +} + +auto|break|case|const|continue|default|do|else|enum|extern|for|goto|if|inline | +register|restrict|return|static|struct|switch|typedef|union|volatile|while | +(_A|a)lignas|_Atomic|_Generic|(_N|n)oreturn|(_S|s)tatic_assert | +(_T|t)hread_local { + return Keyword; +} + +^"#"[[: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; } + {ident} { return Macro; } +} + +{ident} { return Identifier; } + +"//"([^\n]|"\\\n")* | +"/*"([^*]|"*"[^/])*"*"+"/" { + return Comment; +} + +[LUu]?"'" { + BEGIN(CharLiteral); + return String; +} +([LU]|u8?)?"\"" { + BEGIN(StringLiteral); + return String; +} + +{ + "\\"[''""?\\abfnrtv] | + "\\"([0-7]{1,3}) | + "\\x"([[:xdigit:]]{2}) | + "\\u"([[:xdigit:]]{4}) | + "\\U"([[:xdigit:]]{8}) { + return StringEscape; + } +} +{ + "%%" | + "%"[ #+-0]*{width}?("."{width})?([Lhjltz]|hh|ll)?[AEFGXacdefginopsux] { + return StringFormat; + } +} + +{ + "'" { + BEGIN(pop); + return String; + } + [^\\'']+|. { return String; } +} +{ + "\"" { + BEGIN(pop); + return String; + } + [^%\\""]+|. { return String; } +} + +. { + return Macro; +} + +.|\n { return Normal; } + +%{ + (void)yyunput; + (void)input; +%} + +%% + +const struct Lexer LexC = { yylex, &yyin, &yytext }; -- cgit 1.4.1 efa4b6de4f8d92ceb8769da34dbf6e222f2158b2&follow=1'>Use vi and lessJune McEnroe I haven't used neovim in a couple weeks by now, so I may as well commit this. 2021-01-20Use mtags for sh in source-filterJune McEnroe 2021-01-20Generate tags for sh files in mtagsJune McEnroe Only matches functions declared at the beginnings of lines, but I'm fine with that. 2021-01-20Add messy sh lexerJune McEnroe Surprisingly seems to work for everything I looked at in my repos. 2021-01-20Add all target to git.causal.agency MakefileJune McEnroe 2021-01-20Remove Lua supportJune McEnroe Lua support is unused and the dlsym fwrite/write hacks horrify me. Clean it up. 2021-01-20Fix tests for diff spansJune McEnroe 2021-01-20Avoid matching ':' in make tagsJune McEnroe Otherwise a :: rule includes one of the ':'s in the tag name. 2021-01-19Prefer tag matches not preceded by [[:alnum:]]June McEnroe Otherwise the "id" in "void" matches for "void id". 2021-01-19Escape \ and / in mtags search patternsJune McEnroe 2021-01-20Use mtags in source-filterJune McEnroe 2021-01-19Add mtags to generate tags for make and mdocJune McEnroe 2021-01-19Map tags to IDs using only [[:alnum:]-._]June McEnroe 2021-01-19Don't use a pager if reading standard inputJune McEnroe 2021-01-19Support BSD make syntax and match *.amJune McEnroe These don't really go together, but... 2021-01-19Match tab following escaped newline in make assignmentsJune McEnroe Otherwise it ends up going into Shell state. 2021-01-18Allow matching lexers using first input lineJune McEnroe