myco 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/lib/myco/bootstrap/component.rb +6 -7
  3. data/lib/myco/bootstrap/instance.rb +14 -9
  4. data/lib/myco/bootstrap/meme.rb +34 -3
  5. data/lib/myco/code_loader.rb +17 -34
  6. data/lib/myco/code_tools/AST/ArgumentAssembly.my +60 -0
  7. data/lib/myco/code_tools/AST/ArgumentAssembly.my.rb +55 -0
  8. data/lib/myco/code_tools/AST/ArrayAssembly.my +43 -0
  9. data/lib/myco/code_tools/AST/ArrayAssembly.my.rb +37 -0
  10. data/lib/myco/code_tools/AST/BlockArgument.my +25 -0
  11. data/lib/myco/code_tools/AST/BlockArgument.my.rb +26 -0
  12. data/lib/myco/code_tools/AST/BlockLiteral.my +104 -0
  13. data/lib/myco/code_tools/AST/BlockLiteral.my.rb +126 -0
  14. data/lib/myco/code_tools/AST/BlockParameter.my +25 -0
  15. data/lib/myco/code_tools/AST/BlockParameter.my.rb +24 -0
  16. data/lib/myco/code_tools/AST/Body.my +18 -0
  17. data/lib/myco/code_tools/AST/Body.my.rb +20 -0
  18. data/lib/myco/code_tools/AST/BranchOperator.my +59 -0
  19. data/lib/myco/code_tools/AST/BranchOperator.my.rb +87 -0
  20. data/lib/myco/code_tools/AST/ConstantAccess.my +30 -0
  21. data/lib/myco/code_tools/AST/ConstantAccess.my.rb +32 -0
  22. data/lib/myco/code_tools/AST/ConstantAssignment.my +40 -0
  23. data/lib/myco/code_tools/AST/ConstantAssignment.my.rb +45 -0
  24. data/lib/myco/code_tools/AST/ConstantDefine.my +30 -0
  25. data/lib/myco/code_tools/AST/ConstantDefine.my.rb +36 -0
  26. data/lib/myco/code_tools/AST/ConstantReopen.my +29 -0
  27. data/lib/myco/code_tools/AST/ConstantReopen.my.rb +35 -0
  28. data/lib/myco/code_tools/AST/DeclareCategory.my +35 -0
  29. data/lib/myco/code_tools/AST/DeclareCategory.my.rb +40 -0
  30. data/lib/myco/code_tools/AST/DeclareDecorator.my +20 -0
  31. data/lib/myco/code_tools/AST/DeclareDecorator.my.rb +28 -0
  32. data/lib/myco/code_tools/AST/DeclareFile.my +38 -0
  33. data/lib/myco/code_tools/AST/DeclareFile.my.rb +53 -0
  34. data/lib/myco/code_tools/AST/DeclareMeme.my +79 -0
  35. data/lib/myco/code_tools/AST/DeclareMeme.my.rb +90 -0
  36. data/lib/myco/code_tools/AST/DeclareObject.my +58 -0
  37. data/lib/myco/code_tools/AST/DeclareObject.my.rb +67 -0
  38. data/lib/myco/code_tools/AST/DeclareString.my +26 -0
  39. data/lib/myco/code_tools/AST/DeclareString.my.rb +30 -0
  40. data/lib/myco/code_tools/AST/DynamicString.my +21 -0
  41. data/lib/myco/code_tools/AST/DynamicString.my.rb +22 -0
  42. data/lib/myco/code_tools/AST/DynamicSymbol.my +22 -0
  43. data/lib/myco/code_tools/AST/DynamicSymbol.my.rb +26 -0
  44. data/lib/myco/code_tools/AST/Invoke.my +37 -0
  45. data/lib/myco/code_tools/AST/Invoke.my.rb +58 -0
  46. data/lib/myco/code_tools/AST/InvokeMethod.my +19 -0
  47. data/lib/myco/code_tools/AST/InvokeMethod.my.rb +25 -0
  48. data/lib/myco/code_tools/AST/KeywordAssembly.my +30 -0
  49. data/lib/myco/code_tools/AST/KeywordAssembly.my.rb +36 -0
  50. data/lib/myco/code_tools/AST/LocalVariableAccessAmbiguous.my +22 -0
  51. data/lib/myco/code_tools/AST/LocalVariableAccessAmbiguous.my.rb +22 -0
  52. data/lib/myco/code_tools/AST/LocalVariableAssignment.my +20 -0
  53. data/lib/myco/code_tools/AST/LocalVariableAssignment.my.rb +20 -0
  54. data/lib/myco/{parser/ast/myco_module_scope.rb → code_tools/AST/MycoModuleScope.my} +32 -39
  55. data/lib/myco/code_tools/AST/MycoModuleScope.my.rb +82 -0
  56. data/lib/myco/code_tools/AST/Node.my +67 -0
  57. data/lib/myco/code_tools/AST/Node.my.rb +84 -0
  58. data/lib/myco/code_tools/AST/ParameterAssembly.my +248 -0
  59. data/lib/myco/code_tools/AST/ParameterAssembly.my.rb +314 -0
  60. data/lib/myco/code_tools/AST/Quest.my +61 -0
  61. data/lib/myco/code_tools/AST/Quest.my.rb +51 -0
  62. data/lib/myco/code_tools/AST/Script.my +27 -0
  63. data/lib/myco/code_tools/AST/Script.my.rb +33 -0
  64. data/lib/myco/code_tools/AST/SplatValue.my +23 -0
  65. data/lib/myco/code_tools/AST/SplatValue.my.rb +25 -0
  66. data/lib/myco/code_tools/AST/StringLiteral.my +17 -0
  67. data/lib/myco/code_tools/AST/StringLiteral.my.rb +16 -0
  68. data/lib/myco/code_tools/AST/SymbolLiteral.my +16 -0
  69. data/lib/myco/code_tools/AST/SymbolLiteral.my.rb +15 -0
  70. data/lib/myco/{parser/ast → code_tools/AST}/ToRuby.my +89 -90
  71. data/lib/myco/{parser/ast → code_tools/AST}/ToRuby.my.rb +89 -101
  72. data/lib/myco/code_tools/AST/misc.my +57 -0
  73. data/lib/myco/code_tools/AST/misc.my.rb +81 -0
  74. data/lib/myco/code_tools/AST.my +52 -0
  75. data/lib/myco/code_tools/AST.my.rb +40 -0
  76. data/lib/myco/{parser → code_tools/parser}/peg_parser.rb +107 -199
  77. data/lib/myco/{parser.rb → code_tools/parser.rb} +0 -17
  78. data/lib/myco/code_tools.rb +5 -0
  79. data/lib/myco/core/BasicDecorators.my +47 -0
  80. data/lib/myco/core/BasicDecorators.my.rb +66 -0
  81. data/lib/myco/core/FileToplevel.my +14 -3
  82. data/lib/myco/core/FileToplevel.my.rb +27 -12
  83. data/lib/myco/eval.rb +7 -37
  84. data/lib/myco/version.rb +1 -4
  85. data/lib/myco.rb +20 -22
  86. metadata +74 -66
  87. data/lib/myco/parser/ast/argument_assembly.rb +0 -76
  88. data/lib/myco/parser/ast/array_assembly.rb +0 -57
  89. data/lib/myco/parser/ast/branch_operator.rb +0 -73
  90. data/lib/myco/parser/ast/constant_access.rb +0 -15
  91. data/lib/myco/parser/ast/constant_define.rb +0 -40
  92. data/lib/myco/parser/ast/constant_reopen.rb +0 -46
  93. data/lib/myco/parser/ast/declare_category.rb +0 -53
  94. data/lib/myco/parser/ast/declare_decorator.rb +0 -35
  95. data/lib/myco/parser/ast/declare_file.rb +0 -54
  96. data/lib/myco/parser/ast/declare_meme.rb +0 -86
  97. data/lib/myco/parser/ast/declare_object.rb +0 -77
  98. data/lib/myco/parser/ast/declare_string.rb +0 -37
  99. data/lib/myco/parser/ast/invoke.rb +0 -48
  100. data/lib/myco/parser/ast/invoke_method.rb +0 -28
  101. data/lib/myco/parser/ast/local_variable_access_ambiguous.rb +0 -34
  102. data/lib/myco/parser/ast/misc.rb +0 -156
  103. data/lib/myco/parser/ast/quest.rb +0 -82
  104. data/lib/myco/parser/ast.rb +0 -21
@@ -549,20 +549,9 @@ class CodeTools::PegParser
549
549
  return _tmp
550
550
  end
551
551
 
552
- # meme_expr = (return_arg_expr | arg_expr)
552
+ # meme_expr = arg_expr
553
553
  def _meme_expr
554
-
555
- _save = self.pos
556
- while true # choice
557
- _tmp = apply(:_return_arg_expr)
558
- break if _tmp
559
- self.pos = _save
560
- _tmp = apply(:_arg_expr)
561
- break if _tmp
562
- self.pos = _save
563
- break
564
- end # end choice
565
-
554
+ _tmp = apply(:_arg_expr)
566
555
  set_failed_rule :_meme_expr unless _tmp
567
556
  return _tmp
568
557
  end
@@ -1828,32 +1817,6 @@ class CodeTools::PegParser
1828
1817
  return _tmp
1829
1818
  end
1830
1819
 
1831
- # t_JUMP = < "->" > {token(:t_JUMP, text)}
1832
- def _t_JUMP
1833
-
1834
- _save = self.pos
1835
- while true # sequence
1836
- _text_start = self.pos
1837
- _tmp = match_string("->")
1838
- if _tmp
1839
- text = get_text(_text_start)
1840
- end
1841
- unless _tmp
1842
- self.pos = _save
1843
- break
1844
- end
1845
- @result = begin; token(:t_JUMP, text); end
1846
- _tmp = true
1847
- unless _tmp
1848
- self.pos = _save
1849
- end
1850
- break
1851
- end # end sequence
1852
-
1853
- set_failed_rule :_t_JUMP unless _tmp
1854
- return _tmp
1855
- end
1856
-
1857
1820
  # t_DOT = < "." > {token(:t_DOT, text)}
1858
1821
  def _t_DOT
1859
1822
 
@@ -3157,30 +3120,7 @@ class CodeTools::PegParser
3157
3120
  return _tmp
3158
3121
  end
3159
3122
 
3160
- # expr_atom_evstr = expr_atom_not_string:n0 {node(:evstr, n0, n0)}
3161
- def _expr_atom_evstr
3162
-
3163
- _save = self.pos
3164
- while true # sequence
3165
- _tmp = apply(:_expr_atom_not_string)
3166
- n0 = @result
3167
- unless _tmp
3168
- self.pos = _save
3169
- break
3170
- end
3171
- @result = begin; node(:evstr, n0, n0); end
3172
- _tmp = true
3173
- unless _tmp
3174
- self.pos = _save
3175
- end
3176
- break
3177
- end # end sequence
3178
-
3179
- set_failed_rule :_expr_atom_evstr unless _tmp
3180
- return _tmp
3181
- end
3182
-
3183
- # dyn_string_parts = (c_spc* expr_atom_evstr:n0 c_spc* lit_string:n1 {[n0,n1]})+:nlist { nlist.flatten }
3123
+ # dyn_string_parts = (c_spc* expr_atom_not_string:n0 c_spc* lit_string:n1 {[n0,n1]})+:nlist { nlist.flatten }
3184
3124
  def _dyn_string_parts
3185
3125
 
3186
3126
  _save = self.pos
@@ -3199,7 +3139,7 @@ class CodeTools::PegParser
3199
3139
  self.pos = _save2
3200
3140
  break
3201
3141
  end
3202
- _tmp = apply(:_expr_atom_evstr)
3142
+ _tmp = apply(:_expr_atom_not_string)
3203
3143
  n0 = @result
3204
3144
  unless _tmp
3205
3145
  self.pos = _save2
@@ -3243,7 +3183,7 @@ class CodeTools::PegParser
3243
3183
  self.pos = _save5
3244
3184
  break
3245
3185
  end
3246
- _tmp = apply(:_expr_atom_evstr)
3186
+ _tmp = apply(:_expr_atom_not_string)
3247
3187
  n0 = @result
3248
3188
  unless _tmp
3249
3189
  self.pos = _save5
@@ -3297,7 +3237,7 @@ class CodeTools::PegParser
3297
3237
  return _tmp
3298
3238
  end
3299
3239
 
3300
- # dyn_string = lit_string:n0 dyn_string_parts:nrest {node(:dstr, n0, n0.value, nrest)}
3240
+ # dyn_string = lit_string:n0 dyn_string_parts:nrest {node(:dstr, n0, [n0] + nrest)}
3301
3241
  def _dyn_string
3302
3242
 
3303
3243
  _save = self.pos
@@ -3314,7 +3254,7 @@ class CodeTools::PegParser
3314
3254
  self.pos = _save
3315
3255
  break
3316
3256
  end
3317
- @result = begin; node(:dstr, n0, n0.value, nrest); end
3257
+ @result = begin; node(:dstr, n0, [n0] + nrest); end
3318
3258
  _tmp = true
3319
3259
  unless _tmp
3320
3260
  self.pos = _save
@@ -3326,7 +3266,7 @@ class CodeTools::PegParser
3326
3266
  return _tmp
3327
3267
  end
3328
3268
 
3329
- # dyn_symstr = lit_symstr:n0 dyn_string_parts:nrest {node(:dsym, n0, n0.value.to_s, nrest)}
3269
+ # dyn_symstr = lit_symstr:n0 dyn_string_parts:nrest {node(:dsym, n0, [n0] + nrest)}
3330
3270
  def _dyn_symstr
3331
3271
 
3332
3272
  _save = self.pos
@@ -3343,7 +3283,7 @@ class CodeTools::PegParser
3343
3283
  self.pos = _save
3344
3284
  break
3345
3285
  end
3346
- @result = begin; node(:dsym, n0, n0.value.to_s, nrest); end
3286
+ @result = begin; node(:dsym, n0, [n0] + nrest); end
3347
3287
  _tmp = true
3348
3288
  unless _tmp
3349
3289
  self.pos = _save
@@ -3355,88 +3295,92 @@ class CodeTools::PegParser
3355
3295
  return _tmp
3356
3296
  end
3357
3297
 
3358
- # constant = (constant:n0 t_SCOPE:ts t_CONSTANT:tc {node(:colon2, ts, n0, tc.sym)} | t_SCOPE:ts t_CONSTANT:tc {node(:colon3, ts, tc.sym)} | t_CONSTANT:tc {node(:const, tc, tc.sym)})
3359
- def _constant
3298
+ # colon_const = t_SCOPE t_CONSTANT:tc { tc }
3299
+ def _colon_const
3360
3300
 
3361
3301
  _save = self.pos
3362
- while true # choice
3363
-
3364
- _save1 = self.pos
3365
- while true # sequence
3366
- _tmp = apply(:_constant)
3367
- n0 = @result
3368
- unless _tmp
3369
- self.pos = _save1
3370
- break
3371
- end
3372
- _tmp = apply(:_t_SCOPE)
3373
- ts = @result
3374
- unless _tmp
3375
- self.pos = _save1
3376
- break
3377
- end
3378
- _tmp = apply(:_t_CONSTANT)
3379
- tc = @result
3380
- unless _tmp
3381
- self.pos = _save1
3382
- break
3383
- end
3384
- @result = begin; node(:colon2, ts, n0, tc.sym); end
3385
- _tmp = true
3386
- unless _tmp
3387
- self.pos = _save1
3388
- end
3302
+ while true # sequence
3303
+ _tmp = apply(:_t_SCOPE)
3304
+ unless _tmp
3305
+ self.pos = _save
3389
3306
  break
3390
- end # end sequence
3307
+ end
3308
+ _tmp = apply(:_t_CONSTANT)
3309
+ tc = @result
3310
+ unless _tmp
3311
+ self.pos = _save
3312
+ break
3313
+ end
3314
+ @result = begin; tc ; end
3315
+ _tmp = true
3316
+ unless _tmp
3317
+ self.pos = _save
3318
+ end
3319
+ break
3320
+ end # end sequence
3391
3321
 
3392
- break if _tmp
3393
- self.pos = _save
3322
+ set_failed_rule :_colon_const unless _tmp
3323
+ return _tmp
3324
+ end
3394
3325
 
3395
- _save2 = self.pos
3396
- while true # sequence
3397
- _tmp = apply(:_t_SCOPE)
3398
- ts = @result
3399
- unless _tmp
3400
- self.pos = _save2
3401
- break
3402
- end
3403
- _tmp = apply(:_t_CONSTANT)
3404
- tc = @result
3405
- unless _tmp
3406
- self.pos = _save2
3407
- break
3408
- end
3409
- @result = begin; node(:colon3, ts, tc.sym); end
3326
+ # constant = t_SCOPE?:ts t_CONSTANT:tc (t_SCOPE t_CONSTANT:tx)*:trest {node(:const, (ts||tc), !!ts, [tc.sym, *trest.map(&:sym)])}
3327
+ def _constant
3328
+
3329
+ _save = self.pos
3330
+ while true # sequence
3331
+ _save1 = self.pos
3332
+ _tmp = apply(:_t_SCOPE)
3333
+ @result = nil unless _tmp
3334
+ unless _tmp
3410
3335
  _tmp = true
3411
- unless _tmp
3412
- self.pos = _save2
3413
- end
3336
+ self.pos = _save1
3337
+ end
3338
+ ts = @result
3339
+ unless _tmp
3340
+ self.pos = _save
3414
3341
  break
3415
- end # end sequence
3416
-
3417
- break if _tmp
3418
- self.pos = _save
3342
+ end
3343
+ _tmp = apply(:_t_CONSTANT)
3344
+ tc = @result
3345
+ unless _tmp
3346
+ self.pos = _save
3347
+ break
3348
+ end
3349
+ _ary = []
3350
+ while true
3419
3351
 
3420
- _save3 = self.pos
3421
- while true # sequence
3422
- _tmp = apply(:_t_CONSTANT)
3423
- tc = @result
3424
- unless _tmp
3425
- self.pos = _save3
3352
+ _save3 = self.pos
3353
+ while true # sequence
3354
+ _tmp = apply(:_t_SCOPE)
3355
+ unless _tmp
3356
+ self.pos = _save3
3357
+ break
3358
+ end
3359
+ _tmp = apply(:_t_CONSTANT)
3360
+ tx = @result
3361
+ unless _tmp
3362
+ self.pos = _save3
3363
+ end
3426
3364
  break
3427
- end
3428
- @result = begin; node(:const, tc, tc.sym); end
3429
- _tmp = true
3430
- unless _tmp
3431
- self.pos = _save3
3432
- end
3433
- break
3434
- end # end sequence
3365
+ end # end sequence
3435
3366
 
3436
- break if _tmp
3437
- self.pos = _save
3367
+ _ary << @result if _tmp
3368
+ break unless _tmp
3369
+ end
3370
+ _tmp = true
3371
+ @result = _ary
3372
+ trest = @result
3373
+ unless _tmp
3374
+ self.pos = _save
3375
+ break
3376
+ end
3377
+ @result = begin; node(:const, (ts||tc), !!ts, [tc.sym, *trest.map(&:sym)]); end
3378
+ _tmp = true
3379
+ unless _tmp
3380
+ self.pos = _save
3381
+ end
3438
3382
  break
3439
- end # end choice
3383
+ end # end sequence
3440
3384
 
3441
3385
  set_failed_rule :_constant unless _tmp
3442
3386
  return _tmp
@@ -3816,7 +3760,7 @@ class CodeTools::PegParser
3816
3760
  return _tmp
3817
3761
  end
3818
3762
 
3819
- # category = category_name:n0 category_sepd_exprs?:nlist &(arg_sep_opt (t_CATGRY_BEGIN | t_DECLARE_END)) {node(:category, n0, n0, (nlist ? node(:block, nlist.first, nlist) : node(:null, n0)))}
3763
+ # category = category_name:n0 category_sepd_exprs?:nlist &(arg_sep_opt (t_CATGRY_BEGIN | t_DECLARE_END)) {node(:category, n0, n0.value, (nlist ? node(:block, nlist.first, nlist) : node(:null, n0)))}
3820
3764
  def _category
3821
3765
 
3822
3766
  _save = self.pos
@@ -3871,7 +3815,7 @@ class CodeTools::PegParser
3871
3815
  self.pos = _save
3872
3816
  break
3873
3817
  end
3874
- @result = begin; node(:category, n0, n0,
3818
+ @result = begin; node(:category, n0, n0.value,
3875
3819
  (nlist ? node(:block, nlist.first, nlist) : node(:null, n0))); end
3876
3820
  _tmp = true
3877
3821
  unless _tmp
@@ -4247,44 +4191,6 @@ class CodeTools::PegParser
4247
4191
  return _tmp
4248
4192
  end
4249
4193
 
4250
- # return_arg_expr = arg_expr:n0 c_spc* t_JUMP:to {node(:return, to, n0)}
4251
- def _return_arg_expr
4252
-
4253
- _save = self.pos
4254
- while true # sequence
4255
- _tmp = apply(:_arg_expr)
4256
- n0 = @result
4257
- unless _tmp
4258
- self.pos = _save
4259
- break
4260
- end
4261
- while true
4262
- _tmp = apply(:_c_spc)
4263
- break unless _tmp
4264
- end
4265
- _tmp = true
4266
- unless _tmp
4267
- self.pos = _save
4268
- break
4269
- end
4270
- _tmp = apply(:_t_JUMP)
4271
- to = @result
4272
- unless _tmp
4273
- self.pos = _save
4274
- break
4275
- end
4276
- @result = begin; node(:return, to, n0); end
4277
- _tmp = true
4278
- unless _tmp
4279
- self.pos = _save
4280
- end
4281
- break
4282
- end # end sequence
4283
-
4284
- set_failed_rule :_return_arg_expr unless _tmp
4285
- return _tmp
4286
- end
4287
-
4288
4194
  # assignment = (local_assignment | invoke_assignment)
4289
4195
  def _assignment
4290
4196
 
@@ -5069,7 +4975,7 @@ class CodeTools::PegParser
5069
4975
  return _tmp
5070
4976
  end
5071
4977
 
5072
- # in_arg_block = t_OP_TOPROC:to expr_atom:n0 {node(:block_pass, to, nil, n0)}
4978
+ # in_arg_block = t_OP_TOPROC:to expr_atom:n0 {node(:blkarg, to, n0)}
5073
4979
  def _in_arg_block
5074
4980
 
5075
4981
  _save = self.pos
@@ -5086,7 +4992,7 @@ class CodeTools::PegParser
5086
4992
  self.pos = _save
5087
4993
  break
5088
4994
  end
5089
- @result = begin; node(:block_pass, to, nil, n0); end
4995
+ @result = begin; node(:blkarg, to, n0); end
5090
4996
  _tmp = true
5091
4997
  unless _tmp
5092
4998
  self.pos = _save
@@ -5778,7 +5684,7 @@ class CodeTools::PegParser
5778
5684
  return _tmp
5779
5685
  end
5780
5686
 
5781
- # param_list = (t_PARAMS_BEGIN:tb t_PARAMS_END { node(:args, tb, nil, nil, nil, nil, nil, nil, nil) } | t_PARAMS_BEGIN:tb param_sepds:plist t_PARAMS_END { required, optional, rest, kwargs, kwrest, block = 6.times.map { [] } required << plist.shift[1] while plist[0] && plist[0][0] == :required optional << plist.shift[1] while plist[0] && plist[0][0] == :optional rest << plist.shift[1] while plist[0] && plist[0][0] == :rest kwargs << plist.shift[1] while plist[0] && plist[0][0] == :kwargs kwrest << plist.shift[1] while plist[0] && plist[0][0] == :kwrest block << plist.shift[1] while plist[0] && plist[0][0] == :block required = required optional = optional.empty? ? nil : node(:block, tb, optional) rest = rest.first post = nil kwargs = kwargs.empty? ? nil : node(:block, tb, kwargs) kwrest = kwrest.first block = block.first node(:args, tb, required, optional, rest, post, kwargs, kwrest, block) })
5687
+ # param_list = (t_PARAMS_BEGIN:tb t_PARAMS_END { node(:args, tb, [], [], nil, [], [], nil, nil) } | t_PARAMS_BEGIN:tb param_sepds:plist t_PARAMS_END { required, optional, rest, post, kwargs, kwrest, block = 7.times.map { [] } required << plist.shift[1] while plist[0] && plist[0][0] == :required optional << plist.shift[1] while plist[0] && plist[0][0] == :optional rest << plist.shift[1] while plist[0] && plist[0][0] == :rest post << plist.shift[1] while plist[0] && plist[0][0] == :required kwargs << plist.shift[1] while plist[0] && plist[0][0] == :kwargs kwrest << plist.shift[1] while plist[0] && plist[0][0] == :kwrest block << plist.shift[1] while plist[0] && plist[0][0] == :block required = required optional = optional rest = rest.first post = post kwargs = kwargs kwrest = kwrest.first block = block.first # TODO: move these conversions to their respective reductions block = block && node(:blkprm, tb, block) node(:args, tb, required, optional, rest, post, kwargs, kwrest, block) })
5782
5688
  def _param_list
5783
5689
 
5784
5690
  _save = self.pos
@@ -5797,7 +5703,7 @@ class CodeTools::PegParser
5797
5703
  self.pos = _save1
5798
5704
  break
5799
5705
  end
5800
- @result = begin; node(:args, tb, nil, nil, nil, nil, nil, nil, nil) ; end
5706
+ @result = begin; node(:args, tb, [], [], nil, [], [], nil, nil) ; end
5801
5707
  _tmp = true
5802
5708
  unless _tmp
5803
5709
  self.pos = _save1
@@ -5828,23 +5734,27 @@ class CodeTools::PegParser
5828
5734
  break
5829
5735
  end
5830
5736
  @result = begin;
5831
- required, optional, rest, kwargs, kwrest, block = 6.times.map { [] }
5737
+ required, optional, rest, post, kwargs, kwrest, block = 7.times.map { [] }
5832
5738
 
5833
5739
  required << plist.shift[1] while plist[0] && plist[0][0] == :required
5834
5740
  optional << plist.shift[1] while plist[0] && plist[0][0] == :optional
5835
5741
  rest << plist.shift[1] while plist[0] && plist[0][0] == :rest
5742
+ post << plist.shift[1] while plist[0] && plist[0][0] == :required
5836
5743
  kwargs << plist.shift[1] while plist[0] && plist[0][0] == :kwargs
5837
5744
  kwrest << plist.shift[1] while plist[0] && plist[0][0] == :kwrest
5838
5745
  block << plist.shift[1] while plist[0] && plist[0][0] == :block
5839
5746
 
5840
5747
  required = required
5841
- optional = optional.empty? ? nil : node(:block, tb, optional)
5748
+ optional = optional
5842
5749
  rest = rest.first
5843
- post = nil
5844
- kwargs = kwargs.empty? ? nil : node(:block, tb, kwargs)
5750
+ post = post
5751
+ kwargs = kwargs
5845
5752
  kwrest = kwrest.first
5846
5753
  block = block.first
5847
5754
 
5755
+ # TODO: move these conversions to their respective reductions
5756
+ block = block && node(:blkprm, tb, block)
5757
+
5848
5758
  node(:args, tb, required, optional, rest, post, kwargs, kwrest, block)
5849
5759
  ; end
5850
5760
  _tmp = true
@@ -7112,7 +7022,7 @@ class CodeTools::PegParser
7112
7022
  Rules[:_decl] = rule_info("decl", "(declobj | declstr | copen)")
7113
7023
  Rules[:_declobj_expr] = rule_info("declobj_expr", "(category | declobj_expr_not_category)")
7114
7024
  Rules[:_declobj_expr_not_category] = rule_info("declobj_expr_not_category", "(decl | cdefn | cmeme | constant | meme)")
7115
- Rules[:_meme_expr] = rule_info("meme_expr", "(return_arg_expr | arg_expr)")
7025
+ Rules[:_meme_expr] = rule_info("meme_expr", "arg_expr")
7116
7026
  Rules[:_arg_expr] = rule_info("arg_expr", "(assignment | left_chained_atoms | dyn_string | dyn_symstr | expr_atom)")
7117
7027
  Rules[:_expr_atom] = rule_info("expr_atom", "(decl | left_chained_invocations | lit_string | lit_symstr | unary_operation | paren_expr | constant | lit_simple | lit_array | invoke)")
7118
7028
  Rules[:_expr_atom_not_chained] = rule_info("expr_atom_not_chained", "(decl | lit_string | lit_symstr | unary_operation | paren_expr | constant | lit_simple | lit_array | invoke)")
@@ -7158,7 +7068,6 @@ class CodeTools::PegParser
7158
7068
  Rules[:_t_SELF] = rule_info("t_SELF", "< \"self\" > {token(:t_SELF, text)}")
7159
7069
  Rules[:_t_FLOAT] = rule_info("t_FLOAT", "< \"-\"? c_num+ \".\" c_num+ > {token(:t_FLOAT, text)}")
7160
7070
  Rules[:_t_INTEGER] = rule_info("t_INTEGER", "< \"-\"? c_num+ > {token(:t_INTEGER, text)}")
7161
- Rules[:_t_JUMP] = rule_info("t_JUMP", "< \"->\" > {token(:t_JUMP, text)}")
7162
7071
  Rules[:_t_DOT] = rule_info("t_DOT", "< \".\" > {token(:t_DOT, text)}")
7163
7072
  Rules[:_t_QUEST] = rule_info("t_QUEST", "< \".\" c_spc_nl* \"?\" > {token(:t_QUEST, text)}")
7164
7073
  Rules[:_t_SCOPE] = rule_info("t_SCOPE", "< \"::\" > {token(:t_SCOPE, text)}")
@@ -7195,11 +7104,11 @@ class CodeTools::PegParser
7195
7104
  Rules[:_lit_string_as_symbol] = rule_info("lit_string_as_symbol", "(t_STRING_BEGIN t_STRING_BODY:tb t_STRING_END {node(:lit, tb, encode_escapes(tb.text).to_sym)} | t_SSTRING_BEGIN t_SSTRING_BODY:tb t_SSTRING_END {node(:lit, tb, encode_escapes(tb.text).to_sym)})")
7196
7105
  Rules[:_lit_symstr] = rule_info("lit_symstr", "t_SYMSTR_BEGIN t_STRING_BODY:tb t_STRING_END {node(:lit, tb, encode_escapes(tb.text).to_sym)}")
7197
7106
  Rules[:_category_name] = rule_info("category_name", "t_CATGRY_BEGIN t_CATGRY_BODY:tb t_CATGRY_END {node(:lit, tb, encode_escapes(tb.text).to_sym)}")
7198
- Rules[:_expr_atom_evstr] = rule_info("expr_atom_evstr", "expr_atom_not_string:n0 {node(:evstr, n0, n0)}")
7199
- Rules[:_dyn_string_parts] = rule_info("dyn_string_parts", "(c_spc* expr_atom_evstr:n0 c_spc* lit_string:n1 {[n0,n1]})+:nlist { nlist.flatten }")
7200
- Rules[:_dyn_string] = rule_info("dyn_string", "lit_string:n0 dyn_string_parts:nrest {node(:dstr, n0, n0.value, nrest)}")
7201
- Rules[:_dyn_symstr] = rule_info("dyn_symstr", "lit_symstr:n0 dyn_string_parts:nrest {node(:dsym, n0, n0.value.to_s, nrest)}")
7202
- Rules[:_constant] = rule_info("constant", "(constant:n0 t_SCOPE:ts t_CONSTANT:tc {node(:colon2, ts, n0, tc.sym)} | t_SCOPE:ts t_CONSTANT:tc {node(:colon3, ts, tc.sym)} | t_CONSTANT:tc {node(:const, tc, tc.sym)})")
7107
+ Rules[:_dyn_string_parts] = rule_info("dyn_string_parts", "(c_spc* expr_atom_not_string:n0 c_spc* lit_string:n1 {[n0,n1]})+:nlist { nlist.flatten }")
7108
+ Rules[:_dyn_string] = rule_info("dyn_string", "lit_string:n0 dyn_string_parts:nrest {node(:dstr, n0, [n0] + nrest)}")
7109
+ Rules[:_dyn_symstr] = rule_info("dyn_symstr", "lit_symstr:n0 dyn_string_parts:nrest {node(:dsym, n0, [n0] + nrest)}")
7110
+ Rules[:_colon_const] = rule_info("colon_const", "t_SCOPE t_CONSTANT:tc { tc }")
7111
+ Rules[:_constant] = rule_info("constant", "t_SCOPE?:ts t_CONSTANT:tc (t_SCOPE t_CONSTANT:tx)*:trest {node(:const, (ts||tc), !!ts, [tc.sym, *trest.map(&:sym)])}")
7203
7112
  Rules[:_const_sep] = rule_info("const_sep", "(c_spc_nl* t_CONST_SEP c_spc_nl*)+")
7204
7113
  Rules[:_constant_list] = rule_info("constant_list", "constant:n0 (const_sep constant:n)*:nrest {node(:arrass, n0, [n0, *nrest])}")
7205
7114
  Rules[:_id_as_symbol] = rule_info("id_as_symbol", "t_IDENTIFIER:t0 {node(:lit, t0, t0.sym)}")
@@ -7208,7 +7117,7 @@ class CodeTools::PegParser
7208
7117
  Rules[:_declobj] = rule_info("declobj", "constant_list:n0 c_spc_nl* t_DECLARE_BEGIN:t declobj_expr_body:n1 {node(:declobj, t, n0, n1)}")
7209
7118
  Rules[:_category_expr] = rule_info("category_expr", "declobj_expr_not_category")
7210
7119
  Rules[:_category_sepd_exprs] = rule_info("category_sepd_exprs", "arg_sep category_expr:n0 (arg_sep category_expr:n)*:nrest { [n0, *nrest] }")
7211
- Rules[:_category] = rule_info("category", "category_name:n0 category_sepd_exprs?:nlist &(arg_sep_opt (t_CATGRY_BEGIN | t_DECLARE_END)) {node(:category, n0, n0, (nlist ? node(:block, nlist.first, nlist) : node(:null, n0)))}")
7120
+ Rules[:_category] = rule_info("category", "category_name:n0 category_sepd_exprs?:nlist &(arg_sep_opt (t_CATGRY_BEGIN | t_DECLARE_END)) {node(:category, n0, n0.value, (nlist ? node(:block, nlist.first, nlist) : node(:null, n0)))}")
7212
7121
  Rules[:_copen] = rule_info("copen", "constant:n0 c_spc_nl* t_REOPEN:tb c_spc_nl* t_DECLARE_BEGIN declobj_expr_body:n1 {node(:copen, tb, n0, n1)}")
7213
7122
  Rules[:_cdefn] = rule_info("cdefn", "constant:n0 c_spc_nl* t_DEFINE:t c_spc_nl* declobj:n1 {node(:cdefn, t, n0, n1)}")
7214
7123
  Rules[:_t_DECLSTR_BEGIN] = rule_info("t_DECLSTR_BEGIN", "< /[^\\s{:,<][^\\s]+/ > { \# Table of replacement characters to use when calculating \# the ending delimiter from the starting delimiter. \# Directional characters are replaced with their opposite. @declstr_replace_tbl ||= %w{ < > ( ) { } [ ] } \# Calculate the ending delimiter to look for and store it @declstr_destrlim = text \\ .split(/(?<=[^a-zA-Z])|(?=[^a-zA-Z])/) .map { |str| idx = @declstr_replace_tbl.find_index(str) idx.nil? ? str : (idx.odd? ? @declstr_replace_tbl[idx-1] : @declstr_replace_tbl[idx+1]) } .reverse .join '' token(:t_DECLSTR_BEGIN, text) }")
@@ -7217,7 +7126,6 @@ class CodeTools::PegParser
7217
7126
  Rules[:_s_DECLSTR_BODY] = rule_info("s_DECLSTR_BODY", "s_DECLSTR_BODYLINE*:slist { slist[1..-1].join('') }")
7218
7127
  Rules[:_declstr_body] = rule_info("declstr_body", "t_DECLSTR_BEGIN:tb s_DECLSTR_BODY:st c_spc_nl* t_DECLSTR_END {node(:str, tb, st)}")
7219
7128
  Rules[:_declstr] = rule_info("declstr", "constant_list:nc c_spc+ declstr_body:nb {node(:declstr, nc, nc, nb)}")
7220
- Rules[:_return_arg_expr] = rule_info("return_arg_expr", "arg_expr:n0 c_spc* t_JUMP:to {node(:return, to, n0)}")
7221
7129
  Rules[:_assignment] = rule_info("assignment", "(local_assignment | invoke_assignment)")
7222
7130
  Rules[:_assign_rhs] = rule_info("assign_rhs", "arg_expr")
7223
7131
  Rules[:_local_assignment] = rule_info("local_assignment", "t_IDENTIFIER:ti c_spc_nl* t_ASSIGN:to c_spc_nl* assign_rhs:rhs {node(:lasgn, to, ti.sym, rhs)}")
@@ -7236,14 +7144,14 @@ class CodeTools::PegParser
7236
7144
  Rules[:_in_arg_kwarg_mark] = rule_info("in_arg_kwarg_mark", "c_spc_nl* t_MEME_MARK:to")
7237
7145
  Rules[:_in_arg_kwarg] = rule_info("in_arg_kwarg", "id_as_symbol:n0 in_arg_kwarg_mark c_spc_nl* arg_expr:n1 { [n0, n1] }")
7238
7146
  Rules[:_in_arg_splat] = rule_info("in_arg_splat", "t_OP_MULT:to expr_atom:n0 {node(:splat, to, n0)}")
7239
- Rules[:_in_arg_block] = rule_info("in_arg_block", "t_OP_TOPROC:to expr_atom:n0 {node(:block_pass, to, nil, n0)}")
7147
+ Rules[:_in_arg_block] = rule_info("in_arg_block", "t_OP_TOPROC:to expr_atom:n0 {node(:blkarg, to, n0)}")
7240
7148
  Rules[:_in_arg_list] = rule_info("in_arg_list", "(in_arg_normals:n0 arg_sep in_arg_kwargs:n1 arg_sep in_arg_block:n2 { [*n0,n1,n2] } | in_arg_normals:n0 arg_sep in_arg_kwargs:n1 { [*n0,n1] } | in_arg_normals:n0 arg_sep in_arg_block:n1 { [*n0,n1] } | in_arg_kwargs:n0 arg_sep in_arg_block:n1 { [n0, n1] } | in_arg_normals:n0 { [*n0] } | in_arg_kwargs:n0 { [n0] } | in_arg_block:n0 { [n0] })")
7241
7149
  Rules[:_arg_list] = rule_info("arg_list", "(t_ARGS_BEGIN:tb arg_sep_opt t_ARGS_END {node(:argass, tb, [])} | t_ARGS_BEGIN:tb arg_sep_opt in_arg_list:nlist arg_sep_opt t_ARGS_END {node(:argass, tb, nlist)})")
7242
7150
  Rules[:_lit_array] = rule_info("lit_array", "(t_ARRAY_BEGIN:tb arg_sep_opt t_ARRAY_END {node(:arrass, tb, [])} | t_ARRAY_BEGIN:tb arg_sep_opt in_arg_list:nlist arg_sep_opt t_ARRAY_END {node(:arrass, tb, nlist)})")
7243
7151
  Rules[:_param] = rule_info("param", "(t_IDENTIFIER:ti c_spc_nl* t_ASSIGN:to c_spc_nl* arg_expr:nv { [:optional, node(:lasgn, ti, ti.sym, nv)] } | t_IDENTIFIER:ti c_spc_nl* t_MEME_MARK:to c_spc_nl* arg_expr?:nv { [:kwargs, node(:lasgn, ti, ti.sym, (nv || node(:lit, to, :*)))] } | t_OP_EXP c_spc_nl* t_IDENTIFIER:ti { [:kwrest, ti.sym] } | t_OP_MULT c_spc_nl* t_IDENTIFIER:ti { [:rest, ti.sym] } | t_OP_TOPROC c_spc_nl* t_IDENTIFIER:ti { [:block, ti.sym] } | t_IDENTIFIER:ti { [:required, ti.sym] })")
7244
7152
  Rules[:_param_sepd] = rule_info("param_sepd", "arg_sep param:n0 { n0 }")
7245
7153
  Rules[:_param_sepds] = rule_info("param_sepds", "param:n0 (arg_sep param:n)*:nrest arg_sep_opt { [n0, *nrest] }")
7246
- Rules[:_param_list] = rule_info("param_list", "(t_PARAMS_BEGIN:tb t_PARAMS_END { node(:args, tb, nil, nil, nil, nil, nil, nil, nil) } | t_PARAMS_BEGIN:tb param_sepds:plist t_PARAMS_END { required, optional, rest, kwargs, kwrest, block = 6.times.map { [] } required << plist.shift[1] while plist[0] && plist[0][0] == :required optional << plist.shift[1] while plist[0] && plist[0][0] == :optional rest << plist.shift[1] while plist[0] && plist[0][0] == :rest kwargs << plist.shift[1] while plist[0] && plist[0][0] == :kwargs kwrest << plist.shift[1] while plist[0] && plist[0][0] == :kwrest block << plist.shift[1] while plist[0] && plist[0][0] == :block required = required optional = optional.empty? ? nil : node(:block, tb, optional) rest = rest.first post = nil kwargs = kwargs.empty? ? nil : node(:block, tb, kwargs) kwrest = kwrest.first block = block.first node(:args, tb, required, optional, rest, post, kwargs, kwrest, block) })")
7154
+ Rules[:_param_list] = rule_info("param_list", "(t_PARAMS_BEGIN:tb t_PARAMS_END { node(:args, tb, [], [], nil, [], [], nil, nil) } | t_PARAMS_BEGIN:tb param_sepds:plist t_PARAMS_END { required, optional, rest, post, kwargs, kwrest, block = 7.times.map { [] } required << plist.shift[1] while plist[0] && plist[0][0] == :required optional << plist.shift[1] while plist[0] && plist[0][0] == :optional rest << plist.shift[1] while plist[0] && plist[0][0] == :rest post << plist.shift[1] while plist[0] && plist[0][0] == :required kwargs << plist.shift[1] while plist[0] && plist[0][0] == :kwargs kwrest << plist.shift[1] while plist[0] && plist[0][0] == :kwrest block << plist.shift[1] while plist[0] && plist[0][0] == :block required = required optional = optional rest = rest.first post = post kwargs = kwargs kwrest = kwrest.first block = block.first \# TODO: move these conversions to their respective reductions block = block && node(:blkprm, tb, block) node(:args, tb, required, optional, rest, post, kwargs, kwrest, block) })")
7247
7155
  Rules[:_left_op_normal] = rule_info("left_op_normal", "(t_OP_EXP | t_OP_MULT | t_OP_DIV | t_OP_MOD | t_OP_PLUS | t_OP_MINUS | t_OP_COMPARE)")
7248
7156
  Rules[:_left_op_branch] = rule_info("left_op_branch", "(t_OP_AND | t_OP_OR | t_OP_AND_Q | t_OP_OR_Q | t_OP_VOID_Q)")
7249
7157
  Rules[:_left_op] = rule_info("left_op", "(left_op_normal | left_op_branch)")
@@ -1,23 +1,6 @@
1
1
 
2
2
  require 'stringio'
3
3
 
4
- module CodeTools
5
- class Parser < Melbourne
6
- end
7
-
8
- class Compiler
9
- module ParserPatch
10
- def initialize *args
11
- super
12
- @processor = Myco::ToolSet::Parser
13
- end
14
- end
15
-
16
- Parser.prepend ParserPatch
17
- end
18
- end
19
-
20
- require_relative 'parser/ast'
21
4
  require_relative 'parser/peg_parser'
22
5
 
23
6
  module CodeTools
@@ -0,0 +1,5 @@
1
+
2
+ module ::CodeTools; end
3
+
4
+ Myco.eval_file 'code_tools/AST.my'
5
+ require_relative 'code_tools/parser'
@@ -59,4 +59,51 @@
59
59
  }
60
60
  }
61
61
  }
62
+
63
+ # The 'pre' decorator defines a wrapper that pre-processes arguments
64
+ pre: Decorator {
65
+ apply: |meme| {
66
+ orig_meme = meme.target.memes[meme.name]
67
+ wrap_meme = meme.dup
68
+ meme.body = Proc.new |*a,&b| {
69
+ new_a = \
70
+ wrap_meme.result_for(self,*a)
71
+ orig_meme.result_for(self,*new_a,&b)
72
+ }
73
+ }
74
+ }
75
+
76
+ # The 'post' decorator defines a wrapper that post-processes return value
77
+ post: Decorator {
78
+ apply: |meme| {
79
+ orig_meme = meme.target.memes[meme.name]
80
+ wrap_meme = meme.dup
81
+ meme.body = Proc.new |*a,&b| {
82
+ result = \
83
+ orig_meme.result_for(self,*a,&b)
84
+ wrap_meme.result_for(self,result)
85
+ }
86
+ }
87
+ }
88
+
89
+ # The 'setter' decorator defines a setter that pre-processes the given value
90
+ setter: Decorator {
91
+ apply: |meme| {
92
+ wrap_meme = meme.dup
93
+ meme.setter = Proc.new |orig_value| {
94
+ wrap_meme.result_for(self,orig_value)
95
+ }
96
+ }
97
+ }
98
+
99
+ # The 'getter' decorator defines a getter that post-processes the return value
100
+ getter: Decorator {
101
+ apply: |meme| {
102
+ wrap_meme = meme.dup
103
+ meme.getter = Proc.new |orig_value| {
104
+ wrap_meme.result_for(self,orig_value)
105
+ }
106
+ }
107
+ }
108
+
62
109
  }
@@ -64,5 +64,71 @@
64
64
  )}
65
65
  )
66
66
  )})}}.instance)}
67
+ declare_meme(:pre, [], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
68
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme| (
69
+ orig_meme = meme.target.memes.__send__(
70
+ :[],
71
+ meme.name
72
+ )
73
+ wrap_meme = meme.dup
74
+ meme.__send__(
75
+ :body=,
76
+ ::Myco.find_constant(:Proc).new { |*a, &b| (
77
+ new_a = wrap_meme.result_for(
78
+ self,
79
+ *a
80
+ )
81
+ orig_meme.result_for(
82
+ self,
83
+ *new_a,
84
+ &b
85
+ )
86
+ )}
87
+ )
88
+ )})}}.instance)}
89
+ declare_meme(:post, [], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
90
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme| (
91
+ orig_meme = meme.target.memes.__send__(
92
+ :[],
93
+ meme.name
94
+ )
95
+ wrap_meme = meme.dup
96
+ meme.__send__(
97
+ :body=,
98
+ ::Myco.find_constant(:Proc).new { |*a, &b| (
99
+ result = orig_meme.result_for(
100
+ self,
101
+ *a,
102
+ &b
103
+ )
104
+ wrap_meme.result_for(
105
+ self,
106
+ result
107
+ )
108
+ )}
109
+ )
110
+ )})}}.instance)}
111
+ declare_meme(:setter, [], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
112
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme| (
113
+ wrap_meme = meme.dup
114
+ meme.__send__(
115
+ :setter=,
116
+ ::Myco.find_constant(:Proc).new { |orig_value| (wrap_meme.result_for(
117
+ self,
118
+ orig_value
119
+ ))}
120
+ )
121
+ )})}}.instance)}
122
+ declare_meme(:getter, [], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
123
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme| (
124
+ wrap_meme = meme.dup
125
+ meme.__send__(
126
+ :getter=,
127
+ ::Myco.find_constant(:Proc).new { |orig_value| (wrap_meme.result_for(
128
+ self,
129
+ orig_value
130
+ ))}
131
+ )
132
+ )})}}.instance)}
67
133
  )})}}
68
134
  .tap { |__c__| __c__.__name__ = :BasicDecorators })}}.instance