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/wsf.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/wsf.lua')
| -rw-r--r-- | lexlua/wsf.lua | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/lexlua/wsf.lua b/lexlua/wsf.lua index 2d64356cc..dfa14b1eb 100644 --- a/lexlua/wsf.lua +++ b/lexlua/wsf.lua @@ -13,12 +13,11 @@ local ws = token(lexer.WHITESPACE, lexer.space^1) lex:add_rule('whitespace', ws) -- Comments. -lex:add_rule('comment', token(lexer.COMMENT, '<!--' * (lexer.any - '-->')^0 * - P('-->')^-1)) +lex:add_rule('comment', token(lexer.COMMENT, lexer.range('<!--', '-->'))) local alpha = R('az', 'AZ', '\127\255') -local word_char = lexer.alnum + S('_-:.??') -local identifier = (alpha + S('_-:.??')) * word_char^0 +local word_char = lexer.alnum + S('_-:.?') +local identifier = (alpha + S('_-:.?')) * word_char^0 -- Elements. local element = token('element', '<' * P('/')^-1 * identifier) @@ -47,14 +46,15 @@ local equals = token(lexer.OPERATOR, '=') * in_tag lex:add_rule('equals', equals) -- Strings. +local sq_str = lexer.range("'", false, false) +local dq_str = lexer.range('"', false, false) local string = #S('\'"') * lexer.last_char_includes('=') * - token(lexer.STRING, lexer.delimited_range("'", false, true) + - lexer.delimited_range('"', false, true)) + token(lexer.STRING, sq_str + dq_str) lex:add_rule('string', string) -- Numbers. lex:add_rule('number', #lexer.digit * lexer.last_char_includes('=') * - token(lexer.NUMBER, lexer.digit^1 * P('%')^-1) * in_tag) + token(lexer.NUMBER, lexer.digit^1 * P('%')^-1) * in_tag) -- Entities. lex:add_rule('entity', token('entity', '&' * word_match[[ @@ -74,8 +74,7 @@ lex:add_fold_point(lexer.COMMENT, '<!--', '-->') -- Tags that start embedded languages. local embed_start_tag = element * - (ws^1 * attribute * ws^0 * equals * ws^0 * string)^0 * - ws^0 * tag_close + (ws^1 * attribute * ws^0 * equals * ws^0 * string)^0 * ws^0 * tag_close local embed_end_tag = element * tag_close -- Embedded JavaScript. |
