@@ -34,8 +34,8 @@ PEGJS_visitor.prototype.end_of_file = function(node) {
34
34
return null ;
35
35
} ;
36
36
37
- function SPEG_actions_visitor ( actions ) {
38
- this . actions = actions ;
37
+ function SPEG_actions_visitor ( ) {
38
+ this . actions = new SPEG_actions ( ) ;
39
39
}
40
40
SPEG_actions_visitor . prototype . visit = function ( node ) {
41
41
if ( node . children ) {
@@ -49,6 +49,99 @@ SPEG_actions_visitor.prototype.visit = function(node) {
49
49
return node ;
50
50
} ;
51
51
52
+ function SPEG_actions ( ) { }
53
+
54
+ SPEG_actions . prototype . noop = function ( node ) {
55
+ return node ;
56
+ } ;
57
+
58
+ SPEG_actions . prototype . peg = function ( node ) {
59
+ return node . children [ 3 ] ;
60
+ } ;
61
+
62
+ SPEG_actions . prototype . parsing_body = function ( node ) {
63
+ node . children = node . children . map ( function ( child ) {
64
+ return child . children [ 0 ] ;
65
+ } ) ;
66
+ return node ;
67
+ } ;
68
+
69
+ SPEG_actions . prototype . parsing_rule = function ( node ) {
70
+ var rule = node . children [ 4 ] ;
71
+ return {
72
+ name : node . children [ 0 ] . match ,
73
+ parser : rule
74
+ }
75
+ } ;
76
+
77
+ SPEG_actions . prototype . parsing_expression = function ( node ) {
78
+ return node . children [ 0 ] ;
79
+ } ;
80
+
81
+ SPEG_actions . prototype . parsing_sequence = function ( node ) {
82
+ var head = [ node . children [ 0 ] . children [ 0 ] ] ;
83
+ var tail = node . children [ 1 ] . children . map ( function ( child ) {
84
+ return child . children [ 1 ] . children [ 0 ] ;
85
+ } ) ;
86
+ return rd . sequence ( head . concat ( tail ) ) ;
87
+ } ;
88
+
89
+ SPEG_actions . prototype . parsing_ordered_choice = function ( node ) {
90
+ var head = [ node . children [ 0 ] ] ;
91
+ var tail = node . children [ 1 ] . children . map ( function ( child ) {
92
+ return child . children [ 3 ] ;
93
+ } ) ;
94
+ return rd . ordered_choice ( head . concat ( tail ) ) ;
95
+ } ;
96
+
97
+ SPEG_actions . prototype . parsing_sub_expression = function ( node ) {
98
+ return node . children [ 0 ] ;
99
+ } ;
100
+
101
+ SPEG_actions . prototype . parsing_group = function ( node ) {
102
+ return node . children [ 2 ] ;
103
+ } ;
104
+
105
+ SPEG_actions . prototype . parsing_atomic_expression = function ( node ) {
106
+ return node . children [ 0 ] ;
107
+ } ;
108
+
109
+ SPEG_actions . prototype . parsing_not_predicate = function ( node ) {
110
+ return rd . not_predicate ( node . children [ 1 ] . children [ 0 ] ) ;
111
+ } ;
112
+
113
+ SPEG_actions . prototype . parsing_and_predicate = function ( node ) {
114
+ return rd . and_predicate ( node . children [ 1 ] . children [ 0 ] ) ;
115
+ } ;
116
+
117
+ SPEG_actions . prototype . parsing_zero_or_more = function ( node ) {
118
+ return rd . zero_or_more ( node . children [ 0 ] . children [ 0 ] ) ;
119
+ } ;
120
+
121
+ SPEG_actions . prototype . parsing_one_or_more = function ( node ) {
122
+ return rd . one_or_more ( node . children [ 0 ] . children [ 0 ] ) ;
123
+ } ;
124
+
125
+ SPEG_actions . prototype . parsing_optional = function ( node ) {
126
+ return rd . optional ( node . children [ 0 ] . children [ 0 ] ) ;
127
+ } ;
128
+
129
+ SPEG_actions . prototype . parsing_string = function ( node ) {
130
+ return rd . string ( node . children [ 1 ] . match ) ;
131
+ } ;
132
+
133
+ SPEG_actions . prototype . parsing_regex_char = function ( node ) {
134
+ return rd . regex_char ( node . children [ 0 ] . match ) ;
135
+ } ;
136
+
137
+ SPEG_actions . prototype . parsing_rule_call = function ( node ) {
138
+ return rd . call_rule_by_name ( node . match ) ;
139
+ } ;
140
+
141
+ SPEG_actions . prototype . parsing_end_of_file = function ( node ) {
142
+ return rd . end_of_file ( ) ;
143
+ } ;
144
+
52
145
module . exports = {
53
146
SPEG_actions_visitor : SPEG_actions_visitor ,
54
147
PEGJS_visitor : PEGJS_visitor
0 commit comments