diff options
author | mitchell <unknown> | 2018-03-11 23:04:41 -0400 |
---|---|---|
committer | mitchell <unknown> | 2018-03-11 23:04:41 -0400 |
commit | 519b7328b66c4c84f03893a31e4be5ba6b1395f2 (patch) | |
tree | 2055cd79006357e94c185f341d0df17b9a8769eb /lexlua/forth.lua | |
parent | c0373e036e965a70045971e2abc582cb4bf12a4e (diff) | |
download | scintilla-mirror-519b7328b66c4c84f03893a31e4be5ba6b1395f2.tar.gz |
Added optional Lua lexer support.
This support is disabled by default and must be enabled via compile-time option.
Diffstat (limited to 'lexlua/forth.lua')
-rw-r--r-- | lexlua/forth.lua | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/lexlua/forth.lua b/lexlua/forth.lua new file mode 100644 index 000000000..086ce780c --- /dev/null +++ b/lexlua/forth.lua @@ -0,0 +1,56 @@ +-- Copyright 2006-2018 Mitchell mitchell.att.foicica.com. See License.txt. +-- Forth LPeg lexer. +-- Contributions from Joseph Eib. + +local lexer = require('lexer') +local token, word_match = lexer.token, lexer.word_match +local P, R, S = lpeg.P, lpeg.R, lpeg.S + +local lex = lexer.new('forth') + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Strings. +local c_str = 'c' * lexer.delimited_range('"', true, true) +local s_str = 's' * lexer.delimited_range('"', true, true) +local s_bs_str = 's\\' * lexer.delimited_range('"', true, false) +local dot_str = '.' * lexer.delimited_range('"', true, true) +local dot_paren_str = '.' * lexer.delimited_range('()', true, true, false) +local abort_str = 'abort' * lexer.delimited_range('"', true, true) +lex:add_rule('string', token(lexer.STRING, c_str + s_str + s_bs_str + dot_str + + dot_paren_str + abort_str)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ + #> #s */ */mod +loop , . .r /mod 0< 0<> 0> 0= 1+ 1- 2! 2* 2/ 2>r 2@ 2drop 2dup + 2over 2r> 2r@ 2swap :noname <# <> >body >in >number >r ?do ?dup @ abort abs + accept action-of again align aligned allot and base begin bl buffer: c! c, c@ + case cell+ cells char char+ chars compile, constant, count cr create decimal + defer defer! defer@ depth do does> drop dup else emit endcase endof + environment? erase evaluate execute exit false fill find fm/mod here hex hold + holds i if immediate invert is j key leave literal loop lshift m* marker max + min mod move negate nip of or over pad parse parse-name pick postpone quit r> + r@ recurse refill restore-input roll rot rshift s>d save-input sign sm/rem + source source-id space spaces state swap to then true tuck type u. u.r u> u< + um* um/mod unloop until unused value variable while within word xor ['] [char] + [compile] +]], true)) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alnum + + S('+-*=<>.?/\'%,_$#'))^1)) + +-- Comments. +local line_comment = S('|\\') * lexer.nonnewline^0 +local block_comment = '(' * (lexer.any - ')')^0 * P(')')^-1 +lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) + +-- Numbers. +lex:add_rule('number', token(lexer.NUMBER, P('-')^-1 * lexer.digit^1 * + (S('./') * lexer.digit^1)^-1)) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S(':;<>+*-/[]#'))) + +return lex |