forked from bmabey/gherkin-pygments-lexer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlexer.erb.py
84 lines (80 loc) · 3.03 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pygments.lexer import RegexLexer, bygroups, include
from pygments.token import \
Text, Comment, Literal, Operator, Keyword, Name, String
class GherkinLexer(RegexLexer):
name = 'Gherkin'
aliases = ['Cucumber', 'cucumber', 'Gherkin', 'gherkin']
filenames = ['*.feature', '*.story']
feature_keywords_regexp = ur'^(<%= feature_keywords %>)(:)(.*)$'
scenario_sections_regexp = ur'^(\s*)(<%= scenario_keywords %>)(:)(.*)$'
examples_regexp = ur'^(\s*)(<%= examples_keywords %>)(:)(.*)$'
step_keywords_regexp = ur'^(\s*)(<%= step_keywords %>)'
tokens = {
'comments': [
(r'#.*$', Comment),
],
'multiline_descriptions' : [
(step_keywords_regexp, Keyword, "#pop"),
include('comments'),
(r"(\s|.)", Name.Constant),
],
'multiline_descriptions_on_stack' : [
(step_keywords_regexp, Keyword, "#pop:2"),
include('comments'),
(r"(\s|.)", Name.Constant),
],
'scenario_table_description': [
(r"\s+\|", Text, 'scenario_table_header'),
include('comments'),
(r"(\s|.)", Name.Constant),
],
'scenario_table_header': [
(r"\s+\|\s*$", Text, "#pop:2"),
(r"(\s+\|\s*)(#.*)$", bygroups(Text, Comment), "#pop:2"),
include('comments'),
(r"\s+\|", Text),
(r"[^\|]", Literal.String.Symbol),
],
'scenario_sections_on_stack': [
(scenario_sections_regexp, bygroups(Text, Name.Class, Name.Class, Name.Constant), "multiline_descriptions_on_stack"),
],
'narrative': [
include('scenario_sections_on_stack'),
(r"(\s|.)", Name.Builtin),
],
'table_vars': [
(r'(<[^>]*>)', bygroups(Literal.String.Symbol)),
],
'string': [
include('table_vars'),
(r'(\s|.)', String),
],
'py_string': [
(r'"""', String, "#pop"),
include('string'),
],
'double_string': [
(r'"', String, "#pop"),
include('string'),
],
'single_string': [
(r"'", String, "#pop"),
include('string'),
],
'root': [
(r'\n', Text),
include('comments'),
(r'"""', String, "py_string"),
(r'"', String, "double_string"),
(r"'", String, "single_string"),
include('table_vars'),
(r'@[^@\s]+', Name.Namespace),
(step_keywords_regexp, bygroups(Text, Keyword)),
(feature_keywords_regexp, bygroups(Name.Class, Name.Class, Name.Constant), 'narrative'),
(scenario_sections_regexp, bygroups(Text, Name.Class, Name.Class, Name.Constant), "multiline_descriptions"),
(examples_regexp, bygroups(Text, Name.Class, Name.Class, Name.Constant), "scenario_table_description"),
(r'(\s|.)', Text),
]
}