@@ -362,3 +362,34 @@ def lex(self):
362362
363363 return simple_lexer (rules , self .code )
364364
365+
366+ # https://www.gnu.org/software/make/manual/make.html
367+ class MakefileLexer :
368+ # https://pubs.opengroup.org/onlinepubs/007904975/utilities/make.html
369+
370+ # NOTE same as in KConfig, we only care about screaming case names
371+ make_identifier = r'[A-Z0-9_]+'
372+ make_minor_identifier = r'[a-zA-Z0-9_][a-zA-Z0-9-_]*'
373+ make_variable = r'(\$\([a-zA-Z0-9_-]\)|\$\{[a-zA-Z0-9_-]\})'
374+ make_single_quote_string = r"'*?'"
375+ make_string = f'(({ make_single_quote_string } )|({ shared .double_quote_string_with_escapes } ))'
376+ make_escape = r'\\[#"\']'
377+ make_punctuation = r'[~\\`\[\](){}<>.,:;|%$^@&?!+*/=-]'
378+ make_comment = r'(?<!\\)#(\\\s*\n|[^\n])*\n'
379+
380+ rules = [
381+ (shared .whitespace , TokenType .WHITESPACE ),
382+ (make_escape , TokenType .PUNCTUATION ),
383+ (make_comment , TokenType .COMMENT ),
384+ (make_string , TokenType .STRING ),
385+ (make_identifier , TokenType .IDENTIFIER ),
386+ (make_minor_identifier , TokenType .SPECIAL ),
387+ (make_punctuation , TokenType .PUNCTUATION ),
388+ ]
389+
390+ def __init__ (self , code ):
391+ self .code = code
392+
393+ def lex (self ):
394+ return simple_lexer (self .rules , self .code )
395+
0 commit comments