Skip to content

Commit 93cdb64

Browse files
committed
Merge commit '47086ce3704f917700a229a1b8afcae4d24117a3' into merger
Conflicts: lex.l lex.y
2 parents e6d66eb + 47086ce commit 93cdb64

File tree

3 files changed

+79
-70
lines changed

3 files changed

+79
-70
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
lex-parser.js
22
node_modules/
3+
4+
# Editor bak files
5+
*~
6+
*.bak
7+
*.orig

lex.l

+54-54
Original file line numberDiff line numberDiff line change
@@ -17,73 +17,73 @@ BR \r\n|\n|\r
1717
<action>"{" yy.depth++; return '{'
1818
<action>"}" yy.depth == 0 ? this.begin('trail') : yy.depth--; return '}'
1919

20-
<conditions>{NAME} return 'NAME'
21-
<conditions>">" this.popState(); return '>'
22-
<conditions>"," return ','
23-
<conditions>"*" return '*'
20+
<conditions>{NAME} return 'NAME';
21+
<conditions>">" this.popState(); return '>';
22+
<conditions>"," return ',';
23+
<conditions>"*" return '*';
2424

25-
<rules>{BR}+ /* */
26-
<rules>\s+ this.begin('indented')
27-
<rules>"%%" this.begin('code'); return '%%'
28-
<rules>[a-zA-Z0-9_]+ return 'CHARACTER_LIT'
25+
<rules>{BR}+ /* */
26+
<rules>\s+ this.begin('indented')
27+
<rules>"%%" this.begin('code'); return '%%'
28+
<rules>[a-zA-Z0-9_]+ return 'CHARACTER_LIT'
2929

30-
<options>{NAME} yy.options[yytext] = true
31-
<options>{BR}+ this.begin('INITIAL')
32-
<options>\s+{BR}+ this.begin('INITIAL')
33-
<options>\s+ /* empty */
30+
<options>{NAME} yy.options[yytext] = true
31+
<options>{BR}+ this.begin('INITIAL')
32+
<options>\s+{BR}+ this.begin('INITIAL')
33+
<options>\s+ /* empty */
3434

35-
<start_condition>{NAME} return 'START_COND'
36-
<start_condition>{BR}+ this.begin('INITIAL')
37-
<start_condition>\s+{BR}+ this.begin('INITIAL')
38-
<start_condition>\s+ /* empty */
35+
<start_condition>{NAME} return 'START_COND'
36+
<start_condition>{BR}+ this.begin('INITIAL')
37+
<start_condition>\s+{BR}+ this.begin('INITIAL')
38+
<start_condition>\s+ /* empty */
3939

40-
<trail>.*{BR}+ this.begin('rules')
40+
<trail>.*{BR}+ this.begin('rules')
4141

42-
<indented>"{" yy.depth = 0; this.begin('action'); return '{'
43-
<indented>"%{"(.|{BR})*?"%}" this.begin('trail'); yytext = yytext.substr(2, yytext.length-4);return 'ACTION'
44-
"%{"(.|{BR})*?"%}" yytext = yytext.substr(2, yytext.length-4); return 'ACTION'
45-
<indented>.+ this.begin('rules'); return 'ACTION'
42+
<indented>"{" yy.depth = 0; this.begin('action'); return '{'
43+
<indented>"%{"(.|{BR})*?"%}" this.begin('trail'); yytext = yytext.substr(2, yytext.length-4);return 'ACTION'
44+
"%{"(.|{BR})*?"%}" yytext = yytext.substr(2, yytext.length-4); return 'ACTION'
45+
<indented>.+ this.begin('rules'); return 'ACTION'
4646
4747
"/*"(.|\n|\r)*?"*/" /* ignore */
4848
"//".* /* ignore */
4949
5050
{BR}+ /* */
5151
\s+ /* */
52-
{NAME} return 'NAME'
53-
\"("\\\\"|'\"'|[^"])*\" yytext = yytext.replace(/\\"/g,'"');return 'STRING_LIT'
54-
"'"("\\\\"|"\'"|[^'])*"'" yytext = yytext.replace(/\\'/g,"'");return 'STRING_LIT'
55-
"|" return '|'
56-
"["("\\\\"|"\]"|[^\]])*"]" return 'ANY_GROUP_REGEX'
57-
"(?:" return 'SPECIAL_GROUP'
58-
"(?=" return 'SPECIAL_GROUP'
59-
"(?!" return 'SPECIAL_GROUP'
60-
"(" return '('
61-
")" return ')'
62-
"+" return '+'
63-
"*" return '*'
64-
"?" return '?'
65-
"^" return '^'
66-
"," return ','
67-
"<<EOF>>" return '$'
68-
"<" this.begin('conditions'); return '<'
69-
"/!" return '/!'
70-
"/" return '/'
71-
"\\"([0-7]{1,3}|[rfntvsSbBwWdD\\*+()${}|[\]\/.^?]|"c"[A-Z]|"x"[0-9A-F]{2}|"u"[a-fA-F0-9]{4}) return 'ESCAPE_CHAR'
72-
"\\". yytext = yytext.replace(/^\\/g,''); return 'ESCAPE_CHAR'
73-
"$" return '$'
74-
"." return '.'
75-
"%options" yy.options = {}; this.begin('options')
76-
"%s" this.begin('start_condition');return 'START_INC'
77-
"%x" this.begin('start_condition');return 'START_EXC'
78-
"%%" this.begin('rules'); return '%%'
79-
"{"\d+(","\s?\d+|",")?"}" return 'RANGE_REGEX'
80-
"{"{NAME}"}" return 'NAME_BRACE'
81-
"{" return '{'
82-
"}" return '}'
52+
{NAME} return 'NAME';
53+
\"("\\\\"|'\"'|[^"])*\" yytext = yytext.replace(/\\"/g,'"'); return 'STRING_LIT';
54+
"'"("\\\\"|"\'"|[^'])*"'" yytext = yytext.replace(/\\'/g,"'"); return 'STRING_LIT';
55+
"|" return '|';
56+
"["("\\\\"|"\]"|[^\]])*"]" return 'ANY_GROUP_REGEX';
57+
"(?:" return 'SPECIAL_GROUP';
58+
"(?=" return 'SPECIAL_GROUP';
59+
"(?!" return 'SPECIAL_GROUP';
60+
"(" return '(';
61+
")" return ')';
62+
"+" return '+';
63+
"*" return '*';
64+
"?" return '?';
65+
"^" return '^';
66+
"," return ',';
67+
"<<EOF>>" return '$';
68+
"<" this.begin('conditions'); return '<';
69+
"/!" return '/!';
70+
"/" return '/';
71+
"\\"([0-7]{1,3}|[rfntvsSbBwWdD\\*+()${}|[\]\/.^?]|"c"[A-Z]|"x"[0-9A-F]{2}|"u"[a-fA-F0-9]{4}) return 'ESCAPE_CHAR';
72+
"\\". yytext = yytext.replace(/^\\/g,''); return 'ESCAPE_CHAR';
73+
"$" return '$';
74+
"." return '.';
75+
"%options" yy.options = {}; this.begin('options');
76+
"%s" this.begin('start_condition'); return 'START_INC';
77+
"%x" this.begin('start_condition'); return 'START_EXC';
78+
"%%" this.begin('rules'); return '%%';
79+
"{"\d+(","\s?\d+|",")?"}" return 'RANGE_REGEX';
80+
"{"{NAME}"}" return 'NAME_BRACE';
81+
"{" return '{';
82+
"}" return '}';
8383
. /* ignore bad characters */
84-
<*><<EOF>> return 'EOF'
84+
<*><<EOF>> return 'EOF';
8585
86-
<code>(.|{BR})+ return 'CODE'
86+
<code>(.|{BR})+ return 'CODE';
8787
8888
%%
8989

lex.y

+20-16
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010

1111
lex
1212
: definitions '%%' rules epilogue
13-
{ $$ = {rules: $rules};
13+
{
14+
$$ = { rules: $rules };
1415
if ($definitions[0]) $$.macros = $definitions[0];
1516
if ($definitions[1]) $$.startConditions = $definitions[1];
1617
if ($epilogue) $$.moduleInclude = $epilogue;
1718
if (yy.options) $$.options = yy.options;
1819
if (yy.actionInclude) $$.actionInclude = yy.actionInclude;
1920
delete yy.options;
2021
delete yy.actionInclude;
21-
return $$; }
22+
return $$;
23+
}
2224
;
2325

2426
epilogue
@@ -100,7 +102,7 @@ action_body
100102
| action_body '{' action_body '}' action_comments_body
101103
{$$ = $1+$2+$3+$4+$5;}
102104
| action_body '{' action_body '}'
103-
{$$ = $1+$2+$3+$4;}
105+
{$$ = $1 + $2 + $3 + $4;}
104106
;
105107

106108
action_comments_body
@@ -128,46 +130,48 @@ name_list
128130

129131
regex
130132
: regex_list
131-
{ $$ = $1;
132-
if (!(yy.options && yy.options.flex) && $$.match(/[\w\d]$/) && !$$.match(/\\(r|f|n|t|v|s|b|c[A-Z]|x[0-9A-F]{2}|u[a-fA-F0-9]{4}|[0-7]{1,3})$/))
133+
{
134+
$$ = $1;
135+
if (!(yy.options && yy.options.flex) && $$.match(/[\w\d]$/) && !$$.match(/\\(r|f|n|t|v|s|b|c[A-Z]|x[0-9A-F]{2}|u[a-fA-F0-9]{4}|[0-7]{1,3})$/)) {
133136
$$ += "\\b";
137+
}
134138
}
135139
;
136140

137141
regex_list
138142
: regex_list '|' regex_concat
139-
{ $$ = $1+'|'+$3; }
143+
{ $$ = $1 + '|' + $3; }
140144
| regex_list '|'
141-
{ $$ = $1+'|'; }
145+
{ $$ = $1 + '|'; }
142146
| regex_concat
143147
|
144148
{ $$ = '' }
145149
;
146150

147151
regex_concat
148152
: regex_concat regex_base
149-
{ $$ = $1+$2; }
153+
{ $$ = $1 + $2; }
150154
| regex_base
151155
;
152156

153157
regex_base
154158
: '(' regex_list ')'
155-
{ $$ = '('+$2+')'; }
159+
{ $$ = '(' + $2 + ')'; }
156160
| SPECIAL_GROUP regex_list ')'
157-
{ $$ = $1+$2+')'; }
161+
{ $$ = $1 + $2 + ')'; }
158162
| regex_base '+'
159-
{ $$ = $1+'+'; }
163+
{ $$ = $1 + '+'; }
160164
| regex_base '*'
161-
{ $$ = $1+'*'; }
165+
{ $$ = $1 + '*'; }
162166
| regex_base '?'
163-
{ $$ = $1+'?'; }
167+
{ $$ = $1 + '?'; }
164168
| '/' regex_base
165-
{ $$ = '(?='+$2+')'; }
169+
{ $$ = '(?=' + $2 + ')'; }
166170
| '/!' regex_base
167-
{ $$ = '(?!'+$2+')'; }
171+
{ $$ = '(?!' + $2 + ')'; }
168172
| name_expansion
169173
| regex_base range_regex
170-
{ $$ = $1+$2; }
174+
{ $$ = $1 + $2; }
171175
| any_group_regex
172176
| '.'
173177
{ $$ = '.'; }

0 commit comments

Comments
 (0)