diff options
author | mitchell <unknown> | 2020-04-25 16:26:31 -0400 |
---|---|---|
committer | mitchell <unknown> | 2020-04-25 16:26:31 -0400 |
commit | fad15f79b1230b3076be515d6894c8919562809b (patch) | |
tree | 72c848ef02c3331de5ca54eff7adaea3a9a6fb88 /lexlua/php.lua | |
parent | 1fd02a367dec125c0b49dd9246a0928433866b96 (diff) | |
download | scintilla-mirror-fad15f79b1230b3076be515d6894c8919562809b.tar.gz |
Reformatted Lua LPeg lexers and added new convenience functions and pattern.
`lexer.range()` replaces `lexer.delimited_range()` and `lexer.nested_pair()`.
`lexer.to_eol()` replaces `patt * lexer.nonnewline^0` constructs.
`lexer.number` replaces `lexer.float + lexer.integer`.
Also added unit tests for lexer functions.
Diffstat (limited to 'lexlua/php.lua')
-rw-r--r-- | lexlua/php.lua | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lexlua/php.lua b/lexlua/php.lua index adf7ef432..257bc955d 100644 --- a/lexlua/php.lua +++ b/lexlua/php.lua @@ -22,7 +22,7 @@ lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ ]])) local word = (lexer.alpha + '_' + R('\127\255')) * - (lexer.alnum + '_' + R('\127\255'))^0 + (lexer.alnum + '_' + R('\127\255'))^0 -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, word)) @@ -31,26 +31,26 @@ lex:add_rule('identifier', token(lexer.IDENTIFIER, word)) lex:add_rule('variable', token(lexer.VARIABLE, '$' * word)) -- Strings. -local sq_str = lexer.delimited_range("'") -local dq_str = lexer.delimited_range('"') -local bt_str = lexer.delimited_range('`') +local sq_str = lexer.range("'") +local dq_str = lexer.range('"') +local bq_str = lexer.range('`') local heredoc = '<<<' * P(function(input, index) local _, e, delimiter = input:find('([%a_][%w_]*)[\n\r\f]+', index) if delimiter then - local _, e = input:find('[\n\r\f]+'..delimiter, e) + local _, e = input:find('[\n\r\f]+' .. delimiter, e) return e and e + 1 end end) -lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + bt_str + heredoc)) +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + bq_str + heredoc)) -- TODO: interpolated code. -- Comments. -local line_comment = (P('//') + '#') * lexer.nonnewline^0 -local block_comment = '/*' * (lexer.any - '*/')^0 * P('*/')^-1 +local line_comment = lexer.to_eol(P('//') + '#') +local block_comment = lexer.range('/*', '*/') lex:add_rule('comment', token(lexer.COMMENT, block_comment + line_comment)) -- Numbers. -lex:add_rule('number', token(lexer.NUMBER, lexer.float + lexer.integer)) +lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('!@%^*&()-+=|/?.,;:<>[]{}'))) |