diff options
| author | David B. Lamkins <dlamkins@galois.com> | 2015-11-11 22:19:30 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-11-11 22:23:02 +0100 |
| commit | 131a635c94c2db293a11aa9fbe5f1c2877623964 (patch) | |
| tree | 3ebf9c7aa73ffab66ec062921791c7af2630665c | |
| parent | b9add01697676f876d9c931601f3356306425f4b (diff) | |
| download | vis-131a635c94c2db293a11aa9fbe5f1c2877623964.tar.gz vis-131a635c94c2db293a11aa9fbe5f1c2877623964.tar.xz | |
lexer: add lexer for pure
Ref: http://purelang.bitbucket.org/
Closes #106
| -rw-r--r-- | lexers/lexer.lua | 1 | ||||
| -rw-r--r-- | lexers/pure.lua | 54 |
2 files changed, 55 insertions, 0 deletions
diff --git a/lexers/lexer.lua b/lexers/lexer.lua index 2cb7ad0..a6b27bd 100644 --- a/lexers/lexer.lua +++ b/lexers/lexer.lua @@ -1668,6 +1668,7 @@ local files = { [".eps|.ps"] = "ps", [".prolog"] = "prolog", [".props|.properties"] = "props", + [".pure"] = "pure", [".sc|.py|.pyw"] = "python", [".R|.Rout|.Rhistory|.Rt|Rout.save|Rout.fail"] = "rstats", [".r|.reb"] = "rebol", diff --git a/lexers/pure.lua b/lexers/pure.lua new file mode 100644 index 0000000..a376591 --- /dev/null +++ b/lexers/pure.lua @@ -0,0 +1,54 @@ +-- pure LPeg lexer. + +local l = require('lexer') +local token, word_match = l.token, l.word_match +local P, R, S = lpeg.P, lpeg.R, lpeg.S + +local M = {_NAME = 'pure'} + +-- Whitespace. +local ws = token(l.WHITESPACE, l.space^1) + +-- Comments. +local line_comment = '//' * l.nonnewline_esc^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) + +-- 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) + +-- Keywords. +local keyword = token(l.KEYWORD, word_match{ + 'namespace', 'with', 'end', 'using', 'interface', 'extern', 'let', + 'const', 'def', 'type', 'public', 'private', 'nonfix', 'outfix', + 'infix', 'infixl', 'infixr', 'prefix', 'postfix', 'if', 'otherwise', + 'when', 'case', 'of', 'then', 'else' +}) + +-- Identifiers. +local identifier = token(l.IDENTIFIER, l.word) + +-- Operators. +local operator = token(l.OPERATOR, S('+-/*%<>~!=^&|?~:;,.()[]{}@\\')) + +M._rules = { + {'whitespace', ws}, + {'keyword', keyword}, + {'number', number}, + {'identifier', identifier}, + {'string', string}, + {'comment', comment}, + {'operator', operator}, +} + +return M |
