diff options
| author | David B. Lamkins <dlamkins@galois.com> | 2015-11-13 13:04:45 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-11-13 13:05:00 +0100 |
| commit | 4e0600b21373829aa3396660d65266ad3407a9b5 (patch) | |
| tree | e127d3af9b0001a529d98ae919a63127947f94c2 /lexers | |
| parent | 43605fded457cec954600b688d54242341eedc7c (diff) | |
| download | vis-4e0600b21373829aa3396660d65266ad3407a9b5.tar.gz vis-4e0600b21373829aa3396660d65266ad3407a9b5.tar.xz | |
lexer: improve pure lexer
Closes #109
Diffstat (limited to 'lexers')
| -rw-r--r-- | lexers/pure.lua | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/lexers/pure.lua b/lexers/pure.lua index a376591..a35b6d1 100644 --- a/lexers/pure.lua +++ b/lexers/pure.lua @@ -10,22 +10,22 @@ local M = {_NAME = 'pure'} local ws = token(l.WHITESPACE, l.space^1) -- Comments. -local line_comment = '//' * l.nonnewline_esc^0 +local line_comment = '//' * l.nonnewline^0 local block_comment = '/*' * (l.any - '*/')^0 * P('*/')^-1 local comment = token(l.COMMENT, line_comment + block_comment) -- Strings. -local sq_str = P('L')^-1 * l.delimited_range("'", true) -local dq_str = P('L')^-1 * l.delimited_range('"', true) -local string = token(l.STRING, sq_str + dq_str) +local string = token(l.STRING, l.delimited_range('"', true)) -- Numbers. local bin = '0' * S('Bb') * S('01')^1 local hex = '0' * S('Xx') * (R('09') + R('af') + R('AF'))^1 -local int = R('09')^1 -local exp = S('Ee') * S('+-')^-1 * int -local flt = int * ('.' * int)^-1 * exp + int^-1 * '.' * int * exp^-1 -local number = token(l.NUMBER, flt + bin + hex + int * P('L')^-1) +local dec = R('09')^1 +local int = (bin + hex + dec) * P('L')^-1 +local rad = P('.') - P('..') +local exp = (S('Ee') * S('+-')^-1 * int)^-1 +local flt = int * (rad * dec)^-1 * exp + int^-1 * rad * dec * exp +local number = token(l.NUMBER, flt + int) -- Keywords. local keyword = token(l.KEYWORD, word_match{ @@ -39,16 +39,23 @@ local keyword = token(l.KEYWORD, word_match{ local identifier = token(l.IDENTIFIER, l.word) -- Operators. -local operator = token(l.OPERATOR, S('+-/*%<>~!=^&|?~:;,.()[]{}@\\')) +local punct = S('+-/*%<>~!=^&|?~:;,.()[]{}@#$`\\\'') +local dots = P('..') +local operator = token(l.OPERATOR, dots + punct) + +-- Pragmas. +local hashbang = l.starts_line('#!') * (l.nonnewline - P('//'))^0 +local pragma = token(l.PREPROCESSOR, hashbang) M._rules = { {'whitespace', ws}, + {'comment', comment}, + {'pragma', pragma}, {'keyword', keyword}, {'number', number}, + {'operator', operator}, {'identifier', identifier}, {'string', string}, - {'comment', comment}, - {'operator', operator}, } return M |
