forked from cucumber-attic/gherkin-pygments-lexer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.erb.py
107 lines (104 loc) · 3.79 KB
/
lexer.erb.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pygments.lexer import RegexLexer, bygroups, include
from pygments.token import \
Comment, Operator, Keyword, Name, String
class GherkinLexer(RegexLexer):
"""
For `Gherkin <http://cukes.info/>` syntax.
"""
name = 'Gherkin'
aliases = ['Cucumber', 'cucumber', 'Gherkin', 'gherkin']
filenames = ['*.feature']
mimetypes = ['text/x-gherkin']
feature_keywords = ur'^(<%= gherkin_keywords(:feature) %>)(:)(.*)$'
feature_element_keywords = ur'^(\s*)(<%= gherkin_keywords(:background, :scenario, :scenario_outline) %>)(:)(.*)$'
examples_keywords = ur'^(\s*)(<%= gherkin_keywords(:examples) %>)(:)(.*)$'
step_keywords = ur'^(\s*)(<%= gherkin_keywords(:step) %>)'
tokens = {
'comments': [
(r'#.*$', Comment),
],
'feature_elements' : [
(step_keywords, Keyword, "step_content_stack"),
include('comments'),
(r"(\s|.)", Name.Function),
],
'feature_elements_on_stack' : [
(step_keywords, Keyword, "#pop:2"),
include('comments'),
(r"(\s|.)", Name.Function),
],
'examples_table': [
(r"\s+\|", Keyword, 'examples_table_header'),
include('comments'),
(r"(\s|.)", Name.Function),
],
'examples_table_header': [
(r"\s+\|\s*$", Keyword, "#pop:2"),
include('comments'),
(r"\s*\|", Keyword),
(r"[^\|]", Name.Variable),
],
'scenario_sections_on_stack': [
(feature_element_keywords, bygroups(Name.Function, Keyword, Keyword, Name.Function), "feature_elements_on_stack"),
],
'narrative': [
include('scenario_sections_on_stack'),
(r"(\s|.)", Name.Function),
],
'table_vars': [
(r'(<[^>]+>)', Name.Variable),
],
'numbers': [
(r'([+-]?\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', String),
],
'string': [
include('table_vars'),
(r'(\s|.)', String),
],
'py_string': [
(r'"""', Keyword, "#pop"),
include('string'),
],
'step_content_root':[
(r"$", Keyword, "#pop"),
include('step_content'),
],
'step_content_stack':[
(r"$", Keyword, "#pop:2"),
include('step_content'),
],
'step_content':[
(r'"', Name.Function, "double_string"),
include('table_vars'),
include('numbers'),
include('comments'),
(r'(\s|.)', Name.Function),
],
'table_content': [
(r"\s+\|\s*$", Keyword, "#pop"),
include('comments'),
(r"\s*\|", Keyword),
include('string'),
],
'double_string': [
(r'"', Name.Function, "#pop"),
include('string'),
],
'root': [
(r'\n', Name.Function),
include('comments'),
(r'"""', Keyword, "py_string"),
(r'\s+\|', Keyword, 'table_content'),
(r'"', Name.Function, "double_string"),
include('table_vars'),
include('numbers'),
(r'(\s*)(@[^@\r\n\t ]+)', bygroups(Name.Function, Name.Tag)),
(step_keywords, bygroups(Name.Function, Keyword), "step_content_root"),
(feature_keywords, bygroups(Keyword, Keyword, Name.Function), 'narrative'),
(feature_element_keywords, bygroups(Name.Function, Keyword, Keyword, Name.Function), "feature_elements"),
(examples_keywords, bygroups(Name.Function, Keyword, Keyword, Name.Function), "examples_table"),
(r'(\s|.)', Name.Function),
]
}