Created
May 21, 2023 13:40
-
-
Save Losiel/fbbefc8a3ac73621da134a2f680b9d0c to your computer and use it in GitHub Desktop.
Fennel support for TextAdept 12.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Copyright 2006-2023 Mitchell. See LICENSE. | |
-- Fennel LPeg lexer. | |
-- Contributed by Momohime Honda. | |
-- Modified by Losiel to properly support folding. | |
local lexer = require('lexer') | |
local token, word_match = lexer.token, lexer.word_match | |
local P, S = lpeg.P, lpeg.S | |
local lex = lexer.new(...) | |
-- Whitespace. | |
lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) | |
-- Keywords. | |
lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ | |
'#', '%', '*', '+', '-', '->>', '->', '-?>>', '-?>', '..', '.', '//', '/', ':', '<=', '<', '=', | |
'>=', '>', '?.', '^', '~=', 'λ', 'accumulate', 'and', 'band', 'bnot', 'bor', 'bxor', 'collect', | |
'comment', 'do', 'doto', 'each', 'eval-compiler', 'fn', 'for', 'global', 'hashfn', 'icollect', | |
'if', 'import-macros', 'include', 'lambda', 'length', 'let', 'local', 'lshift', 'lua', 'macro', | |
'macrodebug', 'macros', 'match', 'not', 'not=', 'or', 'partial', 'pick-args', 'pick-values', | |
'quote', 'require-macros', 'rshift', 'set', 'set-forcibly!', 'tset', 'values', 'var', 'when', | |
'while', 'with-open' | |
})) | |
-- Identifiers. | |
local initial = lexer.alpha + S('|$%&#*+-/<=>?~^_λ!') | |
local subsequent = initial + lexer.digit | |
lex:add_rule('identifier', token(lexer.IDENTIFIER, initial * subsequent^0 * P('#')^-1)) | |
-- Strings. | |
local dq_str = lexer.range('"') | |
local kw_str = lpeg.B(1 - subsequent) * ':' * subsequent^1 | |
lex:add_rule('string', token(lexer.STRING, dq_str + kw_str)) | |
-- Operators. | |
lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('#{}[]()'))) | |
-- Comments. | |
lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol(';'))) | |
-- Ignore these rules. | |
-- lex:modify_rule('longstring', P(false)) | |
-- lex:add_rule('label', P(false)) | |
-- lex:add_rule('operator', P(false)) | |
lexer.property['scintillua.comment'] = ';' | |
-- Fold points | |
lex:add_fold_point(lexer.OPERATOR, '(', ')') | |
lex:add_fold_point(lexer.OPERATOR, '[', ']') | |
lex:add_fold_point(lexer.OPERATOR, '{', '}') | |
return lex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment