aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid B. Lamkins <dlamkins@galois.com>2015-10-29 13:19:16 +0100
committerMarc André Tanner <mat@brain-dump.org>2015-11-08 13:37:24 +0100
commitf81e0f2c7b690070675a443ce4a141f776a5561e (patch)
treefb58dddcb08a25b3b080ca80bc3f645baaf89077
parent38a0041bd5e46a53ec4d7356e2cc624aee071518 (diff)
downloadvis-f81e0f2c7b690070675a443ce4a141f776a5561e.tar.gz
vis-f81e0f2c7b690070675a443ce4a141f776a5561e.tar.xz
lexer: new APL lexer
-rw-r--r--lexers/apl.lua68
-rw-r--r--lexers/lexer.lua1
2 files changed, 69 insertions, 0 deletions
diff --git a/lexers/apl.lua b/lexers/apl.lua
new file mode 100644
index 0000000..4e718cd
--- /dev/null
+++ b/lexers/apl.lua
@@ -0,0 +1,68 @@
+-- APL 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 = 'apl'}
+
+-- Whitespace.
+local ws = token(l.WHITESPACE, l.space^1)
+
+-- Comments.
+local comment = token(l.COMMENT, (P('⍝') + P('#')) * l.nonnewline^0)
+
+-- Strings.
+local sq_str = l.delimited_range("'", false, true)
+local dq_str = l.delimited_range('"')
+
+local string = token(l.STRING, sq_str + dq_str)
+
+-- Numbers.
+local dig = R('09')
+local rad = P('.')
+local exp = S('eE')
+local img = S('jJ')
+local sgn = P('¯')^-1
+local float = sgn * (dig^0 * rad * dig^1 + dig^1 * rad * dig^0 + dig^1)
+ * (exp * sgn *dig^1)^-1
+local number = token(l.NUMBER, float * img * float + float)
+
+-- Keywords.
+local keyword = token(l.KEYWORD, P('⍞') + P('χ') + P('⍺') + P('⍶')
+ + P('⍵') + P('⍹') + P('⎕') * R('AZ', 'az')^0)
+
+-- Names.
+local n1l = R('AZ', 'az')
+local n1b = P('_') + P('∆') + P('⍙')
+local n2l = n1l + R('09')
+local n2b = n1b + P('¯')
+local n1 = n1l + n1b
+local n2 = n2l + n2b
+local name = n1 * n2^0
+
+-- Labels.
+local label = token(l.LABEL, name * P(':'))
+
+-- Variables.
+local variable = token(l.VARIABLE, name)
+
+-- Special.
+local special = token(l.TYPE, S('{}[]();') + P('←') + P('→') + P('◊'))
+
+-- Nabla.
+local nabla = token(l.PREPROCESSOR, P('∇') + P('⍫'))
+
+M._rules = {
+ {'whitespace', ws},
+ {'comment', comment},
+ {'string', string},
+ {'number', number},
+ {'keyword', keyword},
+ {'label', label},
+ {'variable', variable},
+ {'special', special},
+ {'nabla', nabla},
+}
+
+return M
diff --git a/lexers/lexer.lua b/lexers/lexer.lua
index 371a226..871bd1d 100644
--- a/lexers/lexer.lua
+++ b/lexers/lexer.lua
@@ -1599,6 +1599,7 @@ local files = {
[".adb|.ads"] = "ada",
[".g|.g4"] = "antlr",
[".ans|.inp|.mac"] = "apdl",
+ [".apl"] = "apl",
[".applescript"] = "applescript",
[".asm|.ASM|.s|.S"] = "asm",
[".asa|.asp|.hta"] = "asp",