diff options
Diffstat (limited to 'lua/lexers/lilypond.lua')
| -rw-r--r-- | lua/lexers/lilypond.lua | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/lua/lexers/lilypond.lua b/lua/lexers/lilypond.lua index f7bdf79..9fca571 100644 --- a/lua/lexers/lilypond.lua +++ b/lua/lexers/lilypond.lua @@ -1,40 +1,30 @@ --- Copyright 2006-2017 Robert Gieseke. See LICENSE. +-- Copyright 2006-2022 Robert Gieseke. See LICENSE. -- Lilypond LPeg lexer. -- TODO Embed Scheme; Notes?, Numbers? -local l = require('lexer') -local token, word_match = l.token, l.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local lexer = require('lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S -local M = {_NAME = 'lilypond'} +local lex = lexer.new('lilypond') -- Whitespace. -local ws = token(l.WHITESPACE, l.space^1) - --- Comments. -local line_comment = '%' * l.nonnewline^0 --- TODO: block comment. -local comment = token(l.COMMENT, line_comment) - --- Strings. -local string = token(l.STRING, l.delimited_range('"', false, true)) +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords, commands. -local keyword = token(l.KEYWORD, '\\' * l.word) +lex:add_rule('keyword', token(lexer.KEYWORD, '\\' * lexer.word)) -- Identifiers. -local identifier = token(l.IDENTIFIER, l.word) +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + +-- Strings. +lex:add_rule('string', token(lexer.STRING, lexer.range('"', false, false))) + +-- Comments. +-- TODO: block comment. +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('%'))) -- Operators. -local operator = token(l.OPERATOR, S("{}'~<>|")) - -M._rules = { - {'whitespace', ws}, - {'comment', comment}, - {'string', string}, - {'keyword', keyword}, - {'operator', operator}, - {'identifier', identifier}, -} - -return M +lex:add_rule('operator', token(lexer.OPERATOR, S("{}'~<>|"))) + +return lex |
