File tree Expand file tree Collapse file tree 11 files changed +101
-10
lines changed
speg_grammar_fixtures/valid Expand file tree Collapse file tree 11 files changed +101
-10
lines changed Original file line number Diff line number Diff line change @@ -82,14 +82,27 @@ function parsing_ordered_choice() {
8282}
8383
8484function parsing_sub_expression ( ) {
85- return rd . action ( 'parsing_sub_expression' , rd . ordered_choice ( [
86- parsing_not_predicate ( ) ,
87- parsing_and_predicate ( ) ,
88- parsing_optional ( ) ,
89- parsing_one_or_more ( ) ,
90- parsing_zero_or_more ( ) ,
91- parsing_group ( ) ,
92- parsing_atomic_expression ( )
85+ return rd . action ( 'parsing_sub_expression' , rd . sequence ( [
86+ rd . zero_or_more ( rd . sequence ( [
87+ tag ( ) ,
88+ rd . string ( ':' )
89+ ] ) ) ,
90+ rd . ordered_choice ( [
91+ parsing_not_predicate ( ) ,
92+ parsing_and_predicate ( ) ,
93+ parsing_optional ( ) ,
94+ parsing_one_or_more ( ) ,
95+ parsing_zero_or_more ( ) ,
96+ parsing_group ( ) ,
97+ parsing_atomic_expression ( )
98+ ] )
99+ ] ) ) ;
100+ }
101+
102+ function tag ( ) {
103+ return rd . action ( 'noop' , rd . sequence ( [
104+ rd . regex_char ( '[a-zA-Z_]' ) ,
105+ rd . zero_or_more ( rd . regex_char ( '[a-zA-Z_0-9]' ) )
93106 ] ) ) ;
94107}
95108
Original file line number Diff line number Diff line change @@ -61,7 +61,23 @@ SPEG_actions.prototype.parsing_ordered_choice = function(node) {
6161} ;
6262
6363SPEG_actions . prototype . parsing_sub_expression = function ( node ) {
64- return node . children [ 0 ] ;
64+ return function ( ) {
65+ var result = node . children [ 1 ] . children [ 0 ] . apply ( this , arguments ) ;
66+ if ( result ) {
67+ var tags = node . children [ 0 ] . children . map ( function ( tag_node ) {
68+ return tag_node . children [ 0 ] . match ;
69+ } ) ;
70+ if ( tags . length > 0 ) {
71+ if ( result . tags ) {
72+ result . tags = tags . concat ( result . tags ) ;
73+ } else {
74+ result . tags = tags ;
75+ }
76+ }
77+ }
78+ return result ;
79+ }
80+ return node . children [ 1 ] . children [ 0 ] ;
6581} ;
6682
6783SPEG_actions . prototype . parsing_group = function ( node ) {
Original file line number Diff line number Diff line change 1+ GRAMMAR test
2+
3+ a -> tag:"A";
Original file line number Diff line number Diff line change 1+ {
2+ "type" : " string" ,
3+ "start_position" : 0 ,
4+ "match" : " A" ,
5+ "tags" : [
6+ " tag"
7+ ],
8+ "end_position" : 1
9+ }
Original file line number Diff line number Diff line change 1+ A
Original file line number Diff line number Diff line change 1+ GRAMMAR test
2+
3+ a -> tag1:tag2:b ctag:c;
4+ b -> c;
5+ c -> last:"A";
Original file line number Diff line number Diff line change 1+ {
2+ "type" : " sequence" ,
3+ "start_position" : 0 ,
4+ "match" : " AA" ,
5+ "children" : [
6+ {
7+ "end_position" : 1 ,
8+ "match" : " A" ,
9+ "start_position" : 0 ,
10+ "tags" : [
11+ " tag1" ,
12+ " tag2" ,
13+ " last"
14+ ],
15+ "type" : " string"
16+ },
17+ {
18+ "end_position" : 2 ,
19+ "match" : " A" ,
20+ "start_position" : 1 ,
21+ "tags" : [
22+ " ctag" ,
23+ " last"
24+ ],
25+ "type" : " string"
26+ }
27+ ],
28+ "end_position" : 2
29+ }
Original file line number Diff line number Diff line change 1+ AA
Original file line number Diff line number Diff line change 1+ GRAMMAR tag
2+
3+ tag -> tag:"tag";
Original file line number Diff line number Diff line change 1+ GRAMMAR url
2+
3+ url -> scheme "://" host pathname search hash?;
4+ scheme -> "http" "s"?;
5+ host -> hostname port?;
6+ hostname -> segment ("." segment)*;
7+ segment -> [a-z0-9-]+;
8+ port -> ":" [0-9]+;
9+ pathname -> "/" [^ ?]*;
10+ search -> ("?" [^ #]*)?;
11+ hash -> "#" [^ ]*;
You can’t perform that action at this time.
0 commit comments