build: set version to 0.5
[vis.git] / lua / lexers / gherkin.lua
blobfa7d898e88c17c9934eaef92dd6e126900274f15
1 -- Copyright 2015-2017 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'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Tags.
14 local tag = token('tag', '@' * l.word^0)
16 -- Comments.
17 local comment = token(l.COMMENT, '#' * l.nonnewline^0)
19 -- Strings.
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)
25 -- Placeholders.
26 local placeholder = token('placeholder', l.nested_pair('<', '>'))
28 -- Keywords.
29 local keyword = token(l.KEYWORD, word_match{
30 'Given', 'When', 'Then', 'And', 'But'
33 -- Identifiers.
34 local identifier = token(l.KEYWORD, P('Scenario Outline') + word_match{
35 'Feature', 'Background', 'Scenario', 'Scenarios', 'Examples'
38 -- Examples.
39 local example = token('example', '|' * l.nonnewline^0)
41 -- Numbers.
42 local number = token(l.NUMBER, l.float + l.integer)
44 M._rules = {
45 {'whitespace', ws},
46 {'comment', comment},
47 {'tag', tag},
48 {'placeholder', placeholder},
49 {'keyword', keyword},
50 {'identifier', identifier},
51 {'example', example},
52 {'string', string},
53 {'number', number}
56 M._tokenstyles = {
57 tag = l.STYLE_LABEL,
58 placeholder = l.STYLE_NUMBER,
59 example = l.STYLE_NUMBER
62 M._FOLDBYINDENTATION = true
64 return M