kpeg 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +95 -9
- data/Rakefile +1 -0
- data/kpeg.gemspec +1 -1
- data/lib/kpeg/code_generator.rb +124 -117
- data/lib/kpeg/format_parser.rb +198 -25
- data/lib/kpeg/grammar.rb +20 -3
- data/lib/kpeg/version.rb +1 -1
- data/test/test_kpeg_code_generator.rb +182 -155
- data/test/test_kpeg_format.rb +25 -1
- data/test/test_kpeg_grammar_renderer.rb +12 -0
- metadata +4 -5
- data/LICENSE +0 -25
data/lib/kpeg/format_parser.rb
CHANGED
@@ -334,6 +334,48 @@ class KPeg::FormatParser
|
|
334
334
|
return _tmp
|
335
335
|
end
|
336
336
|
|
337
|
+
# eof_comment = "#" (!eof .)*
|
338
|
+
def _eof_comment
|
339
|
+
|
340
|
+
_save = self.pos
|
341
|
+
while true # sequence
|
342
|
+
_tmp = match_string("#")
|
343
|
+
unless _tmp
|
344
|
+
self.pos = _save
|
345
|
+
break
|
346
|
+
end
|
347
|
+
while true
|
348
|
+
|
349
|
+
_save2 = self.pos
|
350
|
+
while true # sequence
|
351
|
+
_save3 = self.pos
|
352
|
+
_tmp = apply(:_eof)
|
353
|
+
_tmp = _tmp ? nil : true
|
354
|
+
self.pos = _save3
|
355
|
+
unless _tmp
|
356
|
+
self.pos = _save2
|
357
|
+
break
|
358
|
+
end
|
359
|
+
_tmp = get_byte
|
360
|
+
unless _tmp
|
361
|
+
self.pos = _save2
|
362
|
+
end
|
363
|
+
break
|
364
|
+
end # end sequence
|
365
|
+
|
366
|
+
break unless _tmp
|
367
|
+
end
|
368
|
+
_tmp = true
|
369
|
+
unless _tmp
|
370
|
+
self.pos = _save
|
371
|
+
end
|
372
|
+
break
|
373
|
+
end # end sequence
|
374
|
+
|
375
|
+
set_failed_rule :_eof_comment unless _tmp
|
376
|
+
return _tmp
|
377
|
+
end
|
378
|
+
|
337
379
|
# comment = "#" (!eol .)* eol
|
338
380
|
def _comment
|
339
381
|
|
@@ -424,6 +466,13 @@ class KPeg::FormatParser
|
|
424
466
|
return _tmp
|
425
467
|
end
|
426
468
|
|
469
|
+
# kleene = "*"
|
470
|
+
def _kleene
|
471
|
+
_tmp = match_string("*")
|
472
|
+
set_failed_rule :_kleene unless _tmp
|
473
|
+
return _tmp
|
474
|
+
end
|
475
|
+
|
427
476
|
# var = < ("-" | /[a-zA-Z][\-_a-zA-Z0-9]*/) > { text }
|
428
477
|
def _var
|
429
478
|
|
@@ -1073,13 +1122,50 @@ class KPeg::FormatParser
|
|
1073
1122
|
return _tmp
|
1074
1123
|
end
|
1075
1124
|
|
1076
|
-
#
|
1125
|
+
# range_num = < /[1-9][0-9]*/ > { text }
|
1126
|
+
def _range_num
|
1127
|
+
|
1128
|
+
_save = self.pos
|
1129
|
+
while true # sequence
|
1130
|
+
_text_start = self.pos
|
1131
|
+
_tmp = scan(/\A(?-mix:[1-9][0-9]*)/)
|
1132
|
+
if _tmp
|
1133
|
+
text = get_text(_text_start)
|
1134
|
+
end
|
1135
|
+
unless _tmp
|
1136
|
+
self.pos = _save
|
1137
|
+
break
|
1138
|
+
end
|
1139
|
+
@result = begin; text ; end
|
1140
|
+
_tmp = true
|
1141
|
+
unless _tmp
|
1142
|
+
self.pos = _save
|
1143
|
+
end
|
1144
|
+
break
|
1145
|
+
end # end sequence
|
1146
|
+
|
1147
|
+
set_failed_rule :_range_num unless _tmp
|
1148
|
+
return _tmp
|
1149
|
+
end
|
1150
|
+
|
1151
|
+
# range_elem = < (range_num | kleene) > { text }
|
1077
1152
|
def _range_elem
|
1078
1153
|
|
1079
1154
|
_save = self.pos
|
1080
1155
|
while true # sequence
|
1081
1156
|
_text_start = self.pos
|
1082
|
-
|
1157
|
+
|
1158
|
+
_save1 = self.pos
|
1159
|
+
while true # choice
|
1160
|
+
_tmp = apply(:_range_num)
|
1161
|
+
break if _tmp
|
1162
|
+
self.pos = _save1
|
1163
|
+
_tmp = apply(:_kleene)
|
1164
|
+
break if _tmp
|
1165
|
+
self.pos = _save1
|
1166
|
+
break
|
1167
|
+
end # end choice
|
1168
|
+
|
1083
1169
|
if _tmp
|
1084
1170
|
text = get_text(_text_start)
|
1085
1171
|
end
|
@@ -1099,66 +1185,113 @@ class KPeg::FormatParser
|
|
1099
1185
|
return _tmp
|
1100
1186
|
end
|
1101
1187
|
|
1102
|
-
# mult_range = "[" - range_elem:l - "," - range_elem:r - "]" { [l == "*" ? nil : l.to_i, r == "*" ? nil : r.to_i] }
|
1188
|
+
# mult_range = ("[" - range_elem:l - "," - range_elem:r - "]" { [l == "*" ? nil : l.to_i, r == "*" ? nil : r.to_i] } | "[" - range_num:e - "]" { [e.to_i, e.to_i] })
|
1103
1189
|
def _mult_range
|
1104
1190
|
|
1105
1191
|
_save = self.pos
|
1192
|
+
while true # choice
|
1193
|
+
|
1194
|
+
_save1 = self.pos
|
1106
1195
|
while true # sequence
|
1107
1196
|
_tmp = match_string("[")
|
1108
1197
|
unless _tmp
|
1109
|
-
self.pos =
|
1198
|
+
self.pos = _save1
|
1110
1199
|
break
|
1111
1200
|
end
|
1112
1201
|
_tmp = apply(:__hyphen_)
|
1113
1202
|
unless _tmp
|
1114
|
-
self.pos =
|
1203
|
+
self.pos = _save1
|
1115
1204
|
break
|
1116
1205
|
end
|
1117
1206
|
_tmp = apply(:_range_elem)
|
1118
1207
|
l = @result
|
1119
1208
|
unless _tmp
|
1120
|
-
self.pos =
|
1209
|
+
self.pos = _save1
|
1121
1210
|
break
|
1122
1211
|
end
|
1123
1212
|
_tmp = apply(:__hyphen_)
|
1124
1213
|
unless _tmp
|
1125
|
-
self.pos =
|
1214
|
+
self.pos = _save1
|
1126
1215
|
break
|
1127
1216
|
end
|
1128
1217
|
_tmp = match_string(",")
|
1129
1218
|
unless _tmp
|
1130
|
-
self.pos =
|
1219
|
+
self.pos = _save1
|
1131
1220
|
break
|
1132
1221
|
end
|
1133
1222
|
_tmp = apply(:__hyphen_)
|
1134
1223
|
unless _tmp
|
1135
|
-
self.pos =
|
1224
|
+
self.pos = _save1
|
1136
1225
|
break
|
1137
1226
|
end
|
1138
1227
|
_tmp = apply(:_range_elem)
|
1139
1228
|
r = @result
|
1140
1229
|
unless _tmp
|
1141
|
-
self.pos =
|
1230
|
+
self.pos = _save1
|
1142
1231
|
break
|
1143
1232
|
end
|
1144
1233
|
_tmp = apply(:__hyphen_)
|
1145
1234
|
unless _tmp
|
1146
|
-
self.pos =
|
1235
|
+
self.pos = _save1
|
1147
1236
|
break
|
1148
1237
|
end
|
1149
1238
|
_tmp = match_string("]")
|
1150
1239
|
unless _tmp
|
1151
|
-
self.pos =
|
1240
|
+
self.pos = _save1
|
1152
1241
|
break
|
1153
1242
|
end
|
1154
1243
|
@result = begin; [l == "*" ? nil : l.to_i, r == "*" ? nil : r.to_i] ; end
|
1155
1244
|
_tmp = true
|
1156
1245
|
unless _tmp
|
1157
|
-
self.pos =
|
1246
|
+
self.pos = _save1
|
1247
|
+
end
|
1248
|
+
break
|
1249
|
+
end # end sequence
|
1250
|
+
|
1251
|
+
break if _tmp
|
1252
|
+
self.pos = _save
|
1253
|
+
|
1254
|
+
_save2 = self.pos
|
1255
|
+
while true # sequence
|
1256
|
+
_tmp = match_string("[")
|
1257
|
+
unless _tmp
|
1258
|
+
self.pos = _save2
|
1259
|
+
break
|
1260
|
+
end
|
1261
|
+
_tmp = apply(:__hyphen_)
|
1262
|
+
unless _tmp
|
1263
|
+
self.pos = _save2
|
1264
|
+
break
|
1265
|
+
end
|
1266
|
+
_tmp = apply(:_range_num)
|
1267
|
+
e = @result
|
1268
|
+
unless _tmp
|
1269
|
+
self.pos = _save2
|
1270
|
+
break
|
1271
|
+
end
|
1272
|
+
_tmp = apply(:__hyphen_)
|
1273
|
+
unless _tmp
|
1274
|
+
self.pos = _save2
|
1275
|
+
break
|
1276
|
+
end
|
1277
|
+
_tmp = match_string("]")
|
1278
|
+
unless _tmp
|
1279
|
+
self.pos = _save2
|
1280
|
+
break
|
1281
|
+
end
|
1282
|
+
@result = begin; [e.to_i, e.to_i] ; end
|
1283
|
+
_tmp = true
|
1284
|
+
unless _tmp
|
1285
|
+
self.pos = _save2
|
1158
1286
|
end
|
1159
1287
|
break
|
1160
1288
|
end # end sequence
|
1161
1289
|
|
1290
|
+
break if _tmp
|
1291
|
+
self.pos = _save
|
1292
|
+
break
|
1293
|
+
end # end choice
|
1294
|
+
|
1162
1295
|
set_failed_rule :_mult_range unless _tmp
|
1163
1296
|
return _tmp
|
1164
1297
|
end
|
@@ -2427,7 +2560,7 @@ class KPeg::FormatParser
|
|
2427
2560
|
return _tmp
|
2428
2561
|
end
|
2429
2562
|
|
2430
|
-
# root = statements -
|
2563
|
+
# root = statements - eof_comment? eof
|
2431
2564
|
def _root
|
2432
2565
|
|
2433
2566
|
_save = self.pos
|
@@ -2443,7 +2576,7 @@ class KPeg::FormatParser
|
|
2443
2576
|
break
|
2444
2577
|
end
|
2445
2578
|
_save1 = self.pos
|
2446
|
-
_tmp =
|
2579
|
+
_tmp = apply(:_eof_comment)
|
2447
2580
|
unless _tmp
|
2448
2581
|
_tmp = true
|
2449
2582
|
self.pos = _save1
|
@@ -2608,50 +2741,89 @@ class KPeg::FormatParser
|
|
2608
2741
|
return _tmp
|
2609
2742
|
end
|
2610
2743
|
|
2611
|
-
# ast_root = ast_constant:c "(" ast_words:w ")" { [c, w] }
|
2744
|
+
# ast_root = (ast_constant:c "(" ast_words:w ")" { [c, w] } | ast_constant:c "()"? { [c, []] })
|
2612
2745
|
def _ast_root
|
2613
2746
|
|
2614
2747
|
_save = self.pos
|
2748
|
+
while true # choice
|
2749
|
+
|
2750
|
+
_save1 = self.pos
|
2615
2751
|
while true # sequence
|
2616
2752
|
_tmp = apply(:_ast_constant)
|
2617
2753
|
c = @result
|
2618
2754
|
unless _tmp
|
2619
|
-
self.pos =
|
2755
|
+
self.pos = _save1
|
2620
2756
|
break
|
2621
2757
|
end
|
2622
2758
|
_tmp = match_string("(")
|
2623
2759
|
unless _tmp
|
2624
|
-
self.pos =
|
2760
|
+
self.pos = _save1
|
2625
2761
|
break
|
2626
2762
|
end
|
2627
2763
|
_tmp = apply(:_ast_words)
|
2628
2764
|
w = @result
|
2629
2765
|
unless _tmp
|
2630
|
-
self.pos =
|
2766
|
+
self.pos = _save1
|
2631
2767
|
break
|
2632
2768
|
end
|
2633
2769
|
_tmp = match_string(")")
|
2634
2770
|
unless _tmp
|
2635
|
-
self.pos =
|
2771
|
+
self.pos = _save1
|
2636
2772
|
break
|
2637
2773
|
end
|
2638
2774
|
@result = begin; [c, w] ; end
|
2639
2775
|
_tmp = true
|
2640
2776
|
unless _tmp
|
2641
|
-
self.pos =
|
2777
|
+
self.pos = _save1
|
2778
|
+
end
|
2779
|
+
break
|
2780
|
+
end # end sequence
|
2781
|
+
|
2782
|
+
break if _tmp
|
2783
|
+
self.pos = _save
|
2784
|
+
|
2785
|
+
_save2 = self.pos
|
2786
|
+
while true # sequence
|
2787
|
+
_tmp = apply(:_ast_constant)
|
2788
|
+
c = @result
|
2789
|
+
unless _tmp
|
2790
|
+
self.pos = _save2
|
2791
|
+
break
|
2792
|
+
end
|
2793
|
+
_save3 = self.pos
|
2794
|
+
_tmp = match_string("()")
|
2795
|
+
unless _tmp
|
2796
|
+
_tmp = true
|
2797
|
+
self.pos = _save3
|
2798
|
+
end
|
2799
|
+
unless _tmp
|
2800
|
+
self.pos = _save2
|
2801
|
+
break
|
2802
|
+
end
|
2803
|
+
@result = begin; [c, []] ; end
|
2804
|
+
_tmp = true
|
2805
|
+
unless _tmp
|
2806
|
+
self.pos = _save2
|
2642
2807
|
end
|
2643
2808
|
break
|
2644
2809
|
end # end sequence
|
2645
2810
|
|
2811
|
+
break if _tmp
|
2812
|
+
self.pos = _save
|
2813
|
+
break
|
2814
|
+
end # end choice
|
2815
|
+
|
2646
2816
|
set_failed_rule :_ast_root unless _tmp
|
2647
2817
|
return _tmp
|
2648
2818
|
end
|
2649
2819
|
|
2650
2820
|
Rules = {}
|
2651
2821
|
Rules[:_eol] = rule_info("eol", "\"\\n\"")
|
2822
|
+
Rules[:_eof_comment] = rule_info("eof_comment", "\"\#\" (!eof .)*")
|
2652
2823
|
Rules[:_comment] = rule_info("comment", "\"\#\" (!eol .)* eol")
|
2653
2824
|
Rules[:_space] = rule_info("space", "(\" \" | \"\\t\" | eol)")
|
2654
2825
|
Rules[:__hyphen_] = rule_info("-", "(space | comment)*")
|
2826
|
+
Rules[:_kleene] = rule_info("kleene", "\"*\"")
|
2655
2827
|
Rules[:_var] = rule_info("var", "< (\"-\" | /[a-zA-Z][\\-_a-zA-Z0-9]*/) > { text }")
|
2656
2828
|
Rules[:_method] = rule_info("method", "< /[a-zA-Z_][a-zA-Z0-9_]*/ > { text }")
|
2657
2829
|
Rules[:_dbl_escapes] = rule_info("dbl_escapes", "(\"\\\\\\\"\" { '\"' } | \"\\\\n\" { \"\\n\" } | \"\\\\t\" { \"\\t\" } | \"\\\\b\" { \"\\b\" } | \"\\\\\\\\\" { \"\\\\\" })")
|
@@ -2668,8 +2840,9 @@ class KPeg::FormatParser
|
|
2668
2840
|
Rules[:_regexp] = rule_info("regexp", "\"/\" not_slash:body \"/\" regexp_opts:opts { @g.reg body, opts }")
|
2669
2841
|
Rules[:_char] = rule_info("char", "< /[a-zA-Z0-9]/ > { text }")
|
2670
2842
|
Rules[:_char_range] = rule_info("char_range", "\"[\" char:l \"-\" char:r \"]\" { @g.range(l,r) }")
|
2671
|
-
Rules[:
|
2672
|
-
Rules[:
|
2843
|
+
Rules[:_range_num] = rule_info("range_num", "< /[1-9][0-9]*/ > { text }")
|
2844
|
+
Rules[:_range_elem] = rule_info("range_elem", "< (range_num | kleene) > { text }")
|
2845
|
+
Rules[:_mult_range] = rule_info("mult_range", "(\"[\" - range_elem:l - \",\" - range_elem:r - \"]\" { [l == \"*\" ? nil : l.to_i, r == \"*\" ? nil : r.to_i] } | \"[\" - range_num:e - \"]\" { [e.to_i, e.to_i] })")
|
2673
2846
|
Rules[:_curly_block] = rule_info("curly_block", "curly")
|
2674
2847
|
Rules[:_curly] = rule_info("curly", "\"{\" < (/[^{}]+/ | curly)* > \"}\" { @g.action(text) }")
|
2675
2848
|
Rules[:_nested_paren] = rule_info("nested_paren", "\"(\" (/[^()]+/ | nested_paren)* \")\"")
|
@@ -2682,10 +2855,10 @@ class KPeg::FormatParser
|
|
2682
2855
|
Rules[:_statement] = rule_info("statement", "(- var:v \"(\" args:a \")\" - \"=\" - expression:o { @g.set(v, o, a) } | - var:v - \"=\" - expression:o { @g.set(v, o) } | - \"%\" var:name - \"=\" - < /[::A-Za-z0-9_]+/ > { @g.add_foreign_grammar(name, text) } | - \"%%\" - curly:act { @g.add_setup act } | - \"%%\" - var:name - \"=\" - < (!\"\\n\" .)+ > { @g.set_variable(name, text) })")
|
2683
2856
|
Rules[:_statements] = rule_info("statements", "statement (- statements)?")
|
2684
2857
|
Rules[:_eof] = rule_info("eof", "!.")
|
2685
|
-
Rules[:_root] = rule_info("root", "statements -
|
2858
|
+
Rules[:_root] = rule_info("root", "statements - eof_comment? eof")
|
2686
2859
|
Rules[:_ast_constant] = rule_info("ast_constant", "< /[A-Z][A-Za-z0-9_]*/ > { text }")
|
2687
2860
|
Rules[:_ast_word] = rule_info("ast_word", "< /[A-Za-z_][A-Za-z0-9_]*/ > { text }")
|
2688
2861
|
Rules[:_ast_sp] = rule_info("ast_sp", "(\" \" | \"\\t\")*")
|
2689
2862
|
Rules[:_ast_words] = rule_info("ast_words", "(ast_words:r ast_sp \",\" ast_sp ast_word:w { r + [w] } | ast_word:w { [w] })")
|
2690
|
-
Rules[:_ast_root] = rule_info("ast_root", "ast_constant:c \"(\" ast_words:w \")\" { [c, w] }")
|
2863
|
+
Rules[:_ast_root] = rule_info("ast_root", "(ast_constant:c \"(\" ast_words:w \")\" { [c, w] } | ast_constant:c \"()\"? { [c, []] })")
|
2691
2864
|
end
|
data/lib/kpeg/grammar.rb
CHANGED
@@ -111,8 +111,15 @@ module KPeg
|
|
111
111
|
if opts
|
112
112
|
opts.split("").each do |o|
|
113
113
|
case o
|
114
|
-
when "n", "N", "e", "E", "s", "S"
|
115
|
-
lang = o
|
114
|
+
when "n", "N", "e", "E", "s", "S"
|
115
|
+
lang = o.downcase
|
116
|
+
when "u", "U"
|
117
|
+
if RUBY_VERSION > "1.8.7"
|
118
|
+
# Ruby 1.9 defaults to UTF-8 for string matching
|
119
|
+
lang = ""
|
120
|
+
else
|
121
|
+
lang = "u"
|
122
|
+
end
|
116
123
|
when "m"
|
117
124
|
flags |= Regexp::MULTILINE
|
118
125
|
when "x"
|
@@ -785,7 +792,17 @@ module KPeg
|
|
785
792
|
def invoke(name, args=nil)
|
786
793
|
InvokeRule.new name.to_s, args
|
787
794
|
end
|
788
|
-
|
795
|
+
|
796
|
+
# Invoke a rule defined on a foreign grammar
|
797
|
+
# == Parameters:
|
798
|
+
# gram::
|
799
|
+
# The name of the grammar that the rule will be reference from
|
800
|
+
# name::
|
801
|
+
# The name of the rule that will be invoked
|
802
|
+
# args::
|
803
|
+
# Any arguements that should be passed to the rule
|
804
|
+
# == Returns:
|
805
|
+
# A new ForeignInvokeRule
|
789
806
|
def foreign_invoke(gram, name, args=nil)
|
790
807
|
ForeignInvokeRule.new gram, name.to_s, args
|
791
808
|
end
|
data/lib/kpeg/version.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'test/unit'
|
2
3
|
require 'kpeg'
|
3
4
|
require 'kpeg/code_generator'
|
@@ -97,7 +98,25 @@ end
|
|
97
98
|
gram = KPeg.grammar do |g|
|
98
99
|
g.root = g.reg(/./u)
|
99
100
|
end
|
101
|
+
|
102
|
+
if RUBY_VERSION > "1.8.7"
|
103
|
+
str = <<-STR
|
104
|
+
require 'kpeg/compiled_parser'
|
105
|
+
|
106
|
+
class Test < KPeg::CompiledParser
|
100
107
|
|
108
|
+
# root = /./
|
109
|
+
def _root
|
110
|
+
_tmp = scan(/\\A(?-mix:.)/)
|
111
|
+
set_failed_rule :_root unless _tmp
|
112
|
+
return _tmp
|
113
|
+
end
|
114
|
+
|
115
|
+
Rules = {}
|
116
|
+
Rules[:_root] = rule_info("root", "/./")
|
117
|
+
end
|
118
|
+
STR
|
119
|
+
else
|
101
120
|
str = <<-STR
|
102
121
|
require 'kpeg/compiled_parser'
|
103
122
|
|
@@ -114,7 +133,7 @@ class Test < KPeg::CompiledParser
|
|
114
133
|
Rules[:_root] = rule_info("root", "/./u")
|
115
134
|
end
|
116
135
|
STR
|
117
|
-
|
136
|
+
end
|
118
137
|
cg = KPeg::CodeGenerator.new "Test", gram
|
119
138
|
|
120
139
|
assert_equal str, cg.output
|
@@ -176,23 +195,23 @@ class Test < KPeg::CompiledParser
|
|
176
195
|
|
177
196
|
_save = self.pos
|
178
197
|
while true # sequence
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
198
|
+
_save1 = self.pos
|
199
|
+
_tmp = get_byte
|
200
|
+
if _tmp
|
201
|
+
unless _tmp >= 97 and _tmp <= 122
|
202
|
+
self.pos = _save1
|
203
|
+
_tmp = nil
|
204
|
+
end
|
205
|
+
end
|
206
|
+
unless _tmp
|
207
|
+
self.pos = _save
|
208
|
+
break
|
209
|
+
end
|
210
|
+
_tmp = match_string("hello")
|
211
|
+
unless _tmp
|
212
|
+
self.pos = _save
|
185
213
|
end
|
186
|
-
end
|
187
|
-
unless _tmp
|
188
|
-
self.pos = _save
|
189
214
|
break
|
190
|
-
end
|
191
|
-
_tmp = match_string("hello")
|
192
|
-
unless _tmp
|
193
|
-
self.pos = _save
|
194
|
-
end
|
195
|
-
break
|
196
215
|
end # end sequence
|
197
216
|
|
198
217
|
set_failed_rule :_root unless _tmp
|
@@ -229,13 +248,13 @@ class Test < KPeg::CompiledParser
|
|
229
248
|
|
230
249
|
_save = self.pos
|
231
250
|
while true # choice
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
251
|
+
_tmp = match_string("hello")
|
252
|
+
break if _tmp
|
253
|
+
self.pos = _save
|
254
|
+
_tmp = match_string("world")
|
255
|
+
break if _tmp
|
256
|
+
self.pos = _save
|
257
|
+
break
|
239
258
|
end # end choice
|
240
259
|
|
241
260
|
set_failed_rule :_root unless _tmp
|
@@ -332,8 +351,8 @@ class Test < KPeg::CompiledParser
|
|
332
351
|
# root = "hello"*
|
333
352
|
def _root
|
334
353
|
while true
|
335
|
-
|
336
|
-
|
354
|
+
_tmp = match_string("hello")
|
355
|
+
break unless _tmp
|
337
356
|
end
|
338
357
|
_tmp = true
|
339
358
|
set_failed_rule :_root unless _tmp
|
@@ -492,16 +511,16 @@ class Test < KPeg::CompiledParser
|
|
492
511
|
|
493
512
|
_save = self.pos
|
494
513
|
while true # sequence
|
495
|
-
|
496
|
-
|
497
|
-
|
514
|
+
_tmp = match_string("hello")
|
515
|
+
unless _tmp
|
516
|
+
self.pos = _save
|
517
|
+
break
|
518
|
+
end
|
519
|
+
_tmp = match_string("world")
|
520
|
+
unless _tmp
|
521
|
+
self.pos = _save
|
522
|
+
end
|
498
523
|
break
|
499
|
-
end
|
500
|
-
_tmp = match_string("world")
|
501
|
-
unless _tmp
|
502
|
-
self.pos = _save
|
503
|
-
end
|
504
|
-
break
|
505
524
|
end # end sequence
|
506
525
|
|
507
526
|
set_failed_rule :_root unless _tmp
|
@@ -821,10 +840,6 @@ class Test < KPeg::CompiledParser
|
|
821
840
|
@_grammar_blah = TestKPegCodeGenerator::TestParser.new(nil)
|
822
841
|
end
|
823
842
|
|
824
|
-
def invoke_blah(*args)
|
825
|
-
@_grammar_blah.external_invoke(self, :_root, *args)
|
826
|
-
end
|
827
|
-
|
828
843
|
# root = %blah.greeting
|
829
844
|
def _root
|
830
845
|
_tmp = @_grammar_blah.external_invoke(self, :_greeting)
|
@@ -858,10 +873,6 @@ class Test < KPeg::CompiledParser
|
|
858
873
|
@_grammar_blah = TestKPegCodeGenerator::TestParser.new(nil)
|
859
874
|
end
|
860
875
|
|
861
|
-
def invoke_blah(*args)
|
862
|
-
@_grammar_blah.external_invoke(self, :_root, *args)
|
863
|
-
end
|
864
|
-
|
865
876
|
# root = %blah.greeting2(1,2)
|
866
877
|
def _root
|
867
878
|
_tmp = @_grammar_blah.external_invoke(self, :_greeting2, 1,2)
|
@@ -952,21 +963,21 @@ class Test < KPeg::CompiledParser
|
|
952
963
|
|
953
964
|
_save = self.pos
|
954
965
|
while true # sequence
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
966
|
+
_text_start = self.pos
|
967
|
+
_tmp = match_string("hello")
|
968
|
+
if _tmp
|
969
|
+
text = get_text(_text_start)
|
970
|
+
end
|
971
|
+
unless _tmp
|
972
|
+
self.pos = _save
|
973
|
+
break
|
974
|
+
end
|
975
|
+
@result = begin; text; end
|
976
|
+
_tmp = true
|
977
|
+
unless _tmp
|
978
|
+
self.pos = _save
|
979
|
+
end
|
962
980
|
break
|
963
|
-
end
|
964
|
-
@result = begin; text; end
|
965
|
-
_tmp = true
|
966
|
-
unless _tmp
|
967
|
-
self.pos = _save
|
968
|
-
end
|
969
|
-
break
|
970
981
|
end # end sequence
|
971
982
|
|
972
983
|
set_failed_rule :_hello unless _tmp
|
@@ -978,24 +989,24 @@ class Test < KPeg::CompiledParser
|
|
978
989
|
|
979
990
|
_save = self.pos
|
980
991
|
while true # sequence
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
992
|
+
_save1 = self.pos
|
993
|
+
_tmp = apply(:_hello)
|
994
|
+
@result = nil unless _tmp
|
995
|
+
unless _tmp
|
996
|
+
_tmp = true
|
997
|
+
self.pos = _save1
|
998
|
+
end
|
999
|
+
lots = @result
|
1000
|
+
unless _tmp
|
1001
|
+
self.pos = _save
|
1002
|
+
break
|
1003
|
+
end
|
1004
|
+
@result = begin; lots; end
|
985
1005
|
_tmp = true
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
unless _tmp
|
990
|
-
self.pos = _save
|
1006
|
+
unless _tmp
|
1007
|
+
self.pos = _save
|
1008
|
+
end
|
991
1009
|
break
|
992
|
-
end
|
993
|
-
@result = begin; lots; end
|
994
|
-
_tmp = true
|
995
|
-
unless _tmp
|
996
|
-
self.pos = _save
|
997
|
-
end
|
998
|
-
break
|
999
1010
|
end # end sequence
|
1000
1011
|
|
1001
1012
|
set_failed_rule :_root unless _tmp
|
@@ -1038,21 +1049,21 @@ class Test < KPeg::CompiledParser
|
|
1038
1049
|
|
1039
1050
|
_save = self.pos
|
1040
1051
|
while true # sequence
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1052
|
+
_text_start = self.pos
|
1053
|
+
_tmp = match_string("hello")
|
1054
|
+
if _tmp
|
1055
|
+
text = get_text(_text_start)
|
1056
|
+
end
|
1057
|
+
unless _tmp
|
1058
|
+
self.pos = _save
|
1059
|
+
break
|
1060
|
+
end
|
1061
|
+
@result = begin; text; end
|
1062
|
+
_tmp = true
|
1063
|
+
unless _tmp
|
1064
|
+
self.pos = _save
|
1065
|
+
end
|
1048
1066
|
break
|
1049
|
-
end
|
1050
|
-
@result = begin; text; end
|
1051
|
-
_tmp = true
|
1052
|
-
unless _tmp
|
1053
|
-
self.pos = _save
|
1054
|
-
end
|
1055
|
-
break
|
1056
1067
|
end # end sequence
|
1057
1068
|
|
1058
1069
|
set_failed_rule :_hello unless _tmp
|
@@ -1064,25 +1075,25 @@ class Test < KPeg::CompiledParser
|
|
1064
1075
|
|
1065
1076
|
_save = self.pos
|
1066
1077
|
while true # sequence
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
+
_ary = []
|
1079
|
+
while true
|
1080
|
+
_tmp = apply(:_hello)
|
1081
|
+
_ary << @result if _tmp
|
1082
|
+
break unless _tmp
|
1083
|
+
end
|
1084
|
+
_tmp = true
|
1085
|
+
@result = _ary
|
1086
|
+
lots = @result
|
1087
|
+
unless _tmp
|
1088
|
+
self.pos = _save
|
1089
|
+
break
|
1090
|
+
end
|
1091
|
+
@result = begin; lots; end
|
1092
|
+
_tmp = true
|
1093
|
+
unless _tmp
|
1094
|
+
self.pos = _save
|
1095
|
+
end
|
1078
1096
|
break
|
1079
|
-
end
|
1080
|
-
@result = begin; lots; end
|
1081
|
-
_tmp = true
|
1082
|
-
unless _tmp
|
1083
|
-
self.pos = _save
|
1084
|
-
end
|
1085
|
-
break
|
1086
1097
|
end # end sequence
|
1087
1098
|
|
1088
1099
|
set_failed_rule :_root unless _tmp
|
@@ -1128,21 +1139,21 @@ class Test < KPeg::CompiledParser
|
|
1128
1139
|
|
1129
1140
|
_save = self.pos
|
1130
1141
|
while true # sequence
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1142
|
+
_text_start = self.pos
|
1143
|
+
_tmp = match_string("hello")
|
1144
|
+
if _tmp
|
1145
|
+
text = get_text(_text_start)
|
1146
|
+
end
|
1147
|
+
unless _tmp
|
1148
|
+
self.pos = _save
|
1149
|
+
break
|
1150
|
+
end
|
1151
|
+
@result = begin; text; end
|
1152
|
+
_tmp = true
|
1153
|
+
unless _tmp
|
1154
|
+
self.pos = _save
|
1155
|
+
end
|
1138
1156
|
break
|
1139
|
-
end
|
1140
|
-
@result = begin; text; end
|
1141
|
-
_tmp = true
|
1142
|
-
unless _tmp
|
1143
|
-
self.pos = _save
|
1144
|
-
end
|
1145
|
-
break
|
1146
1157
|
end # end sequence
|
1147
1158
|
|
1148
1159
|
set_failed_rule :_hello unless _tmp
|
@@ -1154,32 +1165,32 @@ class Test < KPeg::CompiledParser
|
|
1154
1165
|
|
1155
1166
|
_save = self.pos
|
1156
1167
|
while true # sequence
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1168
|
+
_save1 = self.pos
|
1169
|
+
_ary = []
|
1170
|
+
_tmp = apply(:_hello)
|
1171
|
+
if _tmp
|
1172
|
+
_ary << @result
|
1173
|
+
while true
|
1174
|
+
_tmp = apply(:_hello)
|
1175
|
+
_ary << @result if _tmp
|
1176
|
+
break unless _tmp
|
1177
|
+
end
|
1178
|
+
_tmp = true
|
1179
|
+
@result = _ary
|
1180
|
+
else
|
1181
|
+
self.pos = _save1
|
1182
|
+
end
|
1183
|
+
lots = @result
|
1184
|
+
unless _tmp
|
1185
|
+
self.pos = _save
|
1186
|
+
break
|
1166
1187
|
end
|
1188
|
+
@result = begin; lots; end
|
1167
1189
|
_tmp = true
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
end
|
1172
|
-
lots = @result
|
1173
|
-
unless _tmp
|
1174
|
-
self.pos = _save
|
1190
|
+
unless _tmp
|
1191
|
+
self.pos = _save
|
1192
|
+
end
|
1175
1193
|
break
|
1176
|
-
end
|
1177
|
-
@result = begin; lots; end
|
1178
|
-
_tmp = true
|
1179
|
-
unless _tmp
|
1180
|
-
self.pos = _save
|
1181
|
-
end
|
1182
|
-
break
|
1183
1194
|
end # end sequence
|
1184
1195
|
|
1185
1196
|
set_failed_rule :_root unless _tmp
|
@@ -1255,21 +1266,21 @@ class Test < KPeg::CompiledParser
|
|
1255
1266
|
|
1256
1267
|
_save = self.pos
|
1257
1268
|
while true # sequence
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1269
|
+
_text_start = self.pos
|
1270
|
+
_tmp = match_string("hello")
|
1271
|
+
if _tmp
|
1272
|
+
text = get_text(_text_start)
|
1273
|
+
end
|
1274
|
+
unless _tmp
|
1275
|
+
self.pos = _save
|
1276
|
+
break
|
1277
|
+
end
|
1278
|
+
@result = begin; text ; end
|
1279
|
+
_tmp = true
|
1280
|
+
unless _tmp
|
1281
|
+
self.pos = _save
|
1282
|
+
end
|
1265
1283
|
break
|
1266
|
-
end
|
1267
|
-
@result = begin; text ; end
|
1268
|
-
_tmp = true
|
1269
|
-
unless _tmp
|
1270
|
-
self.pos = _save
|
1271
|
-
end
|
1272
|
-
break
|
1273
1284
|
end # end sequence
|
1274
1285
|
|
1275
1286
|
set_failed_rule :_root unless _tmp
|
@@ -1346,6 +1357,8 @@ end
|
|
1346
1357
|
gram = KPeg.grammar do |g|
|
1347
1358
|
g.root = g.dot
|
1348
1359
|
g.set_variable "bracket", "ast BracketOperator(receiver, argument)"
|
1360
|
+
g.set_variable "simple", "ast Simple()"
|
1361
|
+
g.set_variable "simple2", "ast Simple2"
|
1349
1362
|
end
|
1350
1363
|
|
1351
1364
|
str = <<-STR
|
@@ -1363,10 +1376,24 @@ class Test < KPeg::CompiledParser
|
|
1363
1376
|
attr_reader :receiver
|
1364
1377
|
attr_reader :argument
|
1365
1378
|
end
|
1379
|
+
class Simple < Node
|
1380
|
+
def initialize()
|
1381
|
+
end
|
1382
|
+
end
|
1383
|
+
class Simple2 < Node
|
1384
|
+
def initialize()
|
1385
|
+
end
|
1386
|
+
end
|
1366
1387
|
end
|
1367
1388
|
def bracket(receiver, argument)
|
1368
1389
|
AST::BracketOperator.new(receiver, argument)
|
1369
1390
|
end
|
1391
|
+
def simple()
|
1392
|
+
AST::Simple.new()
|
1393
|
+
end
|
1394
|
+
def simple2()
|
1395
|
+
AST::Simple2.new()
|
1396
|
+
end
|
1370
1397
|
|
1371
1398
|
# root = .
|
1372
1399
|
def _root
|