-- Copyright 2006-2010 Mitchell Foral mitchellcaladbolg.net. See LICENSE. -- Makefile LPeg Lexer module(..., package.seeall) local P, R, S = lpeg.P, lpeg.R, lpeg.S local nonnewline = nonnewline_esc -- local ws = token('whitespace', S('\r\n\f\t ')^1) local nl = P('\r')^-1*P('\n') local ws = token('whitespace', (S('\f\t ')+P'\\'*nl)^1) local nl = token('whitespace', S('\r\n')^1) -- nl = nil local assign = token('operator', P(':')^-1 * '=') local colon = token('operator', ':') * -P('=') -- comments local comment = token('comment', '#' * nonnewline^0) -- preprocessor local preproc = token('preprocessor', '!' * nonnewline^0) -- targets local target = token('target', (nonnewline - ':')^1) * colon -- commands -- local command = #P('\t') * token('command', nonnewline^1) -- keywords local keyword = token('keyword', word_match(word_list{ 'ifdef', 'ifndef', 'ifeq', 'ifneq', 'else', 'endif', 'include', 'vpath', })) -- lines local var_char = any - space - S(':#=') local nonws = (nonnewline - space)^1 local identifier = token('identifier', var_char^1) * ws^0 * assign * ws^0 local macro = token('macro', '$' * (delimited_range('()', nil, nil, true) + S('<@^'))) local in_line = ws + identifier + keyword + macro local regular_line = (in_line + token('line', nonws))^1 local command = #P('\t') * (in_line + token('command', nonws))^1 target = target * in_line^0 function LoadTokens() local makefile = makefile add_token(makefile, 'comment', comment) add_token(makefile, 'preprocessor', preproc) add_token(makefile, 'target', target) add_token(makefile, 'command', command) add_token(makefile, 'regular_line', regular_line) add_token(makefile, 'whitespace', nl) end function LoadStyles() add_style('line', style_nothing) add_style('target', style_definition) add_style('command', style_string) add_style('identifier', style_nothing..{ bold = true }) add_style('macro', style_keyword..{ bold = false }) end