aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-05-30 15:06:01 +0200
committerMarc André Tanner <mat@brain-dump.org>2017-05-30 15:07:19 +0200
commit61ff2920bad08c10a4c53e3d93fa152721b348fc (patch)
tree90b42f5e441373da72454f86751d5ab21fee3108 /lua/lexers
parent554d6b887d1d56de330f63bf735ef96ab10cacd2 (diff)
downloadvis-61ff2920bad08c10a4c53e3d93fa152721b348fc.tar.gz
vis-61ff2920bad08c10a4c53e3d93fa152721b348fc.tar.xz
lexer: add simple strace(1) output lexer
Diffstat (limited to 'lua/lexers')
-rw-r--r--lua/lexers/strace.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/lua/lexers/strace.lua b/lua/lexers/strace.lua
new file mode 100644
index 0000000..deb8fb7
--- /dev/null
+++ b/lua/lexers/strace.lua
@@ -0,0 +1,31 @@
+-- strace(1) output lexer
+
+local l = require('lexer')
+local token, word_match = l.token, l.word_match
+local S = lpeg.S
+
+local M = {_NAME = 'strace'}
+
+local ws = token(l.WHITESPACE, l.space^1)
+local string = token(l.STRING, l.delimited_range('"', true) + l.delimited_range("'", true))
+local number = token(l.NUMBER, l.float + l.integer)
+local constant = token(l.CONSTANT, (l.upper + '_') * (l.upper + l.digit + '_')^0)
+local syscall = token(l.KEYWORD, l.starts_line(l.word))
+local operator = token(l.OPERATOR, S('+-/*%<>~!=^&|?~:;,.()[]{}'))
+local comment = token(l.COMMENT, l.nested_pair('/*', '*/') + ('(' * (l.alpha + ' ')^1 * ')\n'))
+local result = token(l.TYPE, '= ' * l.integer)
+
+M._rules = {
+ {'whitespace', ws},
+ {'keyword', syscall},
+ {'constant', constant},
+ {'string', string},
+ {'comment', comment},
+ {'type', result},
+ {'number', number},
+ {'operator', operator},
+}
+
+M._LEXBYLINE = true
+
+return M