diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-10-16 12:36:47 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-11-08 13:35:36 +0100 |
| commit | 039042f2e323c1f982f1de61b702c88fb33d6ccb (patch) | |
| tree | 67dea69de9462e0c27ea2a743b4c5d1798eaa057 /lexers/tcl.lua | |
| parent | b1ec60061623601ca6185a16d77c6c6c62135e95 (diff) | |
| download | vis-039042f2e323c1f982f1de61b702c88fb33d6ccb.tar.gz vis-039042f2e323c1f982f1de61b702c88fb33d6ccb.tar.xz | |
Import LPeg based lexers from Scintillua 3.6.1-1
These are Copyright (c) 2007-2015 Mitchell and released under the
MIT license.
Diffstat (limited to 'lexers/tcl.lua')
| -rw-r--r-- | lexers/tcl.lua | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lexers/tcl.lua b/lexers/tcl.lua new file mode 100644 index 0000000..f014c35 --- /dev/null +++ b/lexers/tcl.lua @@ -0,0 +1,59 @@ +-- Copyright 2014-2015 Joshua Krämer. See LICENSE. +-- Tcl LPeg lexer. +-- This lexer follows the TCL dodekalogue (http://wiki.tcl.tk/10259). +-- It is based on the previous lexer by Mitchell. + +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 = 'tcl'} + +-- Whitespace. +local whitespace = token(l.WHITESPACE, l.space^1) + +-- Separator (semicolon). +local separator = token(l.CLASS, P(';')) + +-- Delimiters. +local braces = token(l.KEYWORD, S('{}')) +local quotes = token(l.FUNCTION, '"') +local brackets = token(l.VARIABLE, S('[]')) + +-- Argument expander. +local expander = token(l.LABEL, P('{*}')) + +-- Variable substitution. +local variable = token(l.STRING, '$' * (l.alnum + '_' + P(':')^2)^0) + +-- Backslash substitution. +local backslash = token(l.TYPE, '\\' * ((l.digit * l.digit^-2) + + ('x' * l.xdigit^1) + ('u' * l.xdigit * l.xdigit^-3) + + ('U' * l.xdigit * l.xdigit^-7) + P(1))) + +-- Comment. +local comment = token(l.COMMENT, '#' * P(function(input, index) + local i = index - 2 + while i > 0 and input:find('^[ \t]', i) do i = i - 1 end + if i < 1 or input:find('^[\r\n;]', i) then return index end +end) * l.nonnewline^0) + +M._rules = { + {'whitespace', whitespace}, + {'comment', comment}, + {'separator', separator}, + {'expander', expander}, + {'braces', braces}, + {'quotes', quotes}, + {'brackets', brackets}, + {'variable', variable}, + {'backslash', backslash}, +} + +M._foldsymbols = { + _patterns = {'[{}]', '#'}, + [l.KEYWORD] = {['{'] = 1, ['}'] = -1}, + [l.COMMENT] = {['#'] = l.fold_line_comments('#')} +} + +return M |
