-
Notifications
You must be signed in to change notification settings - Fork 1
/
cucumber.flex
81 lines (62 loc) · 2.49 KB
/
cucumber.flex
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
package com.pivotallabs.idea.cucumber;
import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
import com.pivotallabs.idea.cucumber.FeatureTokenTypes;
%%
%class FeatureFlexLexer
%implements FlexLexer
%final
%unicode
%function advance
%type IElementType
%eof{ return;
%eof}
%{
StringBuffer string = new StringBuffer();
StringBuffer fragment = new StringBuffer();
private int braceCounter = 0;
%}
LineTerminator = \r|\n|\r\n
InputCharacter = [^\r\n]
WhiteSpace = {LineTerminator} | [ \t\f]
/* comments */
Comment = {EndOfLineComment}
EndOfLineComment = "#" {InputCharacter}* {LineTerminator}
DecIntegerLiteral = 0 | [1-9][0-9]*
%state STRING
%state SPACES
%%
#.*\n { return FeatureTokenTypes.COMMENT; }
[A-Za-z0-9]+ { return FeatureTokenTypes.WORD; }
{WhiteSpace} { return FeatureTokenTypes.WORD; }
. { return FeatureTokenTypes.WORD; }
/* keywords */
/*
<SPACES> "Feature" { return FeatureTokenTypes.FEATURE; }
<SPACES> "Background" { return FeatureTokenTypes.BACKGROUND; }
<SPACES> "Scenario" { return FeatureTokenTypes.SCENARIO; }
<SPACES> "Scenario Outline" { return FeatureTokenTypes.SCENARIO_OUTLINE; }
<SPACES> "Examples" { return FeatureTokenTypes.EXAMPLES; }
<SPACES> "Scenarios" { return FeatureTokenTypes.SCENARIOS; }
<SPACES> "Given" { return FeatureTokenTypes.GIVEN; }
<SPACES> "Then" { return FeatureTokenTypes.THEN; }
<SPACES> "And" { return FeatureTokenTypes.AND; }
<SPACES> "But" { return FeatureTokenTypes.BUT; }
\w+ { return FeatureTokenTypes.WORD; }
\n { return FeatureTokenTypes.NEWLINE; }
\" { string.setLength(0); yybegin(STRING); }
<SPACES> {
\s* {}
}
<STRING> {
\" { yybegin(YYINITIAL);
return FeatureTokenTypes.STRING_LITERAL; }
[^\n\r\"\\]+ { string.append( yytext() ); }
\\t { string.append('\t'); }
\\n { string.append('\n'); }
\\r { string.append('\r'); }
\\\" { string.append('\"'); }
\\ { string.append('\\'); }
}
. { /* ignored */ }
*/