1 -- Copyright 2015-2016 Jason Schindler. See LICENSE.
2 -- Gherkin (https://github.com/cucumber/cucumber/wiki/Gherkin) LPeg lexer.
4 local l
= require('lexer')
5 local token
, word_match
= l
.token
, l
.word_match
6 local P
, R
, S
= lpeg
.P
, lpeg
.R
, lpeg
.S
8 local M
= {_NAME
= 'gherkin'}
11 local ws
= token(l
.WHITESPACE
, l
.space^
1)
14 local tag = token('tag', '@' * l
.word^
0)
17 local comment
= token(l
.COMMENT
, '#' * l
.nonnewline^
0)
20 local doc_str
= '"""' * (l
.any
- '"""')^
0 * P('"""')^
-1
21 local dq_str
= l
.delimited_range('"')
23 local string = token(l
.STRING
, doc_str
+ dq_str
)
26 local placeholder
= token('placeholder', l
.nested_pair('<', '>'))
29 local keyword
= token(l
.KEYWORD
, word_match
{
30 'Given', 'When', 'Then', 'And', 'But'
34 local identifier
= token(l
.KEYWORD
, P('Scenario Outline') + word_match
{
35 'Feature', 'Background', 'Scenario', 'Scenarios', 'Examples'
39 local example
= token('example', '|' * l
.nonnewline^
0)
42 local number = token(l
.NUMBER
, l
.float
+ l
.integer
)
48 {'placeholder', placeholder
},
50 {'identifier', identifier
},
58 placeholder
= l
.STYLE_NUMBER
,
59 example
= l
.STYLE_NUMBER
62 M
._FOLDBYINDENTATION
= true