vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
gherkin.lua
(1159B)
1 -- Copyright 2015-2025 Jason Schindler. See LICENSE.
2 -- Gherkin (https://github.com/cucumber/cucumber/wiki/Gherkin) LPeg lexer.
3
4 local lexer = require('lexer')
5 local token, word_match = lexer.token, lexer.word_match
6 local P, S = lpeg.P, lpeg.S
7
8 local lex = lexer.new('gherkin', {fold_by_indentation = true})
9
10 -- Whitespace.
11 lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
12
13 -- Keywords.
14 lex:add_rule('keyword', token(lexer.KEYWORD, word_match(
15 'And Background But Examples Feature Given Outline Scenario Scenarios Then When')))
16
17 -- Strings.
18 local doc_str = lexer.range('"""')
19 local dq_str = lexer.range('"')
20 lex:add_rule('string', token(lexer.STRING, doc_str + dq_str))
21
22 -- Comments.
23 lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#')))
24
25 -- Numbers.
26 -- lex:add_rule('number', token(lexer.NUMBER, lexer.number))
27
28 -- Tags.
29 lex:add_rule('tag', token(lexer.LABEL, '@' * lexer.word^0))
30
31 -- Placeholders.
32 lex:add_rule('placeholder', token(lexer.VARIABLE, lexer.range('<', '>', false, false, true)))
33
34 -- Examples.
35 lex:add_rule('example', token(lexer.DEFAULT, lexer.to_eol('|')))
36
37 lexer.property['scintillua.comment'] = '#'
38
39 return lex