1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
-- Copyright 2015-2017 Jason Schindler. See LICENSE.
-- Gherkin (https://github.com/cucumber/cucumber/wiki/Gherkin) LPeg lexer.
local l = require('lexer')
local token, word_match = l.token, l.word_match
local P, R, S = lpeg.P, lpeg.R, lpeg.S
local M = {_NAME = 'gherkin'}
-- Whitespace.
local ws = token(l.WHITESPACE, l.space^1)
-- Tags.
local tag = token('tag', '@' * l.word^0)
-- Comments.
local comment = token(l.COMMENT, '#' * l.nonnewline^0)
-- Strings.
local doc_str = '"""' * (l.any - '"""')^0 * P('"""')^-1
local dq_str = l.delimited_range('"')
local string = token(l.STRING, doc_str + dq_str)
-- Placeholders.
local placeholder = token('placeholder', l.nested_pair('<', '>'))
-- Keywords.
local keyword = token(l.KEYWORD, word_match{
'Given', 'When', 'Then', 'And', 'But'
})
-- Identifiers.
local identifier = token(l.KEYWORD, P('Scenario Outline') + word_match{
'Feature', 'Background', 'Scenario', 'Scenarios', 'Examples'
})
-- Examples.
local example = token('example', '|' * l.nonnewline^0)
-- Numbers.
local number = token(l.NUMBER, l.float + l.integer)
M._rules = {
{'whitespace', ws},
{'comment', comment},
{'tag', tag},
{'placeholder', placeholder},
{'keyword', keyword},
{'identifier', identifier},
{'example', example},
{'string', string},
{'number', number}
}
M._tokenstyles = {
tag = l.STYLE_LABEL,
placeholder = l.STYLE_NUMBER,
example = l.STYLE_NUMBER
}
M._FOLDBYINDENTATION = true
return M
|