depager 0.2.3 → 0.3.0.b20250423
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.
- checksums.yaml +7 -0
 - data/.rubocop.yml +44 -0
 - data/.simplecov +5 -0
 - data/Gemfile +12 -0
 - data/LICENSE.gpl +339 -0
 - data/Manifest.txt +73 -0
 - data/README.en +7 -21
 - data/README.ja +19 -99
 - data/Rakefile +31 -0
 - data/bin/depager +7 -45
 - data/examples/action_pl0d/pl0d.action.dr +421 -0
 - data/examples/action_pl0d/test.pl0ds +48 -0
 - data/examples/c89/c89.dr +493 -496
 - data/examples/c89/test.c89 +10 -10
 - data/examples/extension/astdf.rb +9 -0
 - data/examples/extension/atree.dr +55 -0
 - data/examples/{sample_calc → extension}/calc.atree.dr +42 -43
 - data/examples/{sample_calc/calc.action.dr → extension/calc.simple_action.dr} +33 -33
 - data/examples/extension/paction.dr +16 -15
 - data/examples/extension/pactiontest.dr +14 -14
 - data/examples/extension/simple_action.rb +46 -0
 - data/examples/pl0d/pl0ds.dr +337 -334
 - data/examples/pl0d/test.pl0ds +33 -33
 - data/examples/rie_calc/calc.rie.dr +57 -0
 - data/examples/rie_calc/test.calc +4 -0
 - data/examples/rie_dcuse/dcuse.rie.dr +71 -0
 - data/examples/rie_dcuse/test.dcuse +1 -0
 - data/examples/rie_pl0/orig_ex/exerrdg.pl0 +44 -0
 - data/examples/rie_pl0/orig_ex/exerrm.pl0 +19 -0
 - data/examples/rie_pl0/orig_ex/exerrmre.pl0 +20 -0
 - data/examples/rie_pl0/orig_ex/exerrtok.pl0 +18 -0
 - data/examples/rie_pl0/orig_ex/exmdg.pl0 +40 -0
 - data/examples/rie_pl0/orig_ex/exmdgwwl.pl0 +43 -0
 - data/examples/rie_pl0/orig_ex/exmrw.pl0 +22 -0
 - data/examples/rie_pl0/orig_ex/exmwwl.pl0 +18 -0
 - data/examples/rie_pl0/orig_ex/exnorw.pl0 +17 -0
 - data/examples/rie_pl0/pl0.rie.dr +450 -0
 - data/examples/rie_pl0/test.pl0 +10 -0
 - data/examples/slex_test/divreg.slex.dr +29 -29
 - data/examples/slex_test/ljoin.slex.dr +36 -36
 - data/examples/slex_test/test.divreg +1 -1
 - data/examples/slex_test/test.ljoin +3 -3
 - data/examples/{sample_calc/calc.nvaction.dr → tiny_calc/calc.action.dr} +33 -33
 - data/examples/{sample_calc → tiny_calc}/calc.ast.action.dr +76 -66
 - data/examples/{sample_calc → tiny_calc}/calc.ast.dr +67 -55
 - data/examples/tiny_calc/calc.cst.dr +50 -0
 - data/examples/{sample_calc → tiny_calc}/calc.dr +43 -43
 - data/examples/{sample_calc → tiny_calc}/calc.lex.dr +29 -29
 - data/examples/{sample_calc/calc_prec.nvaction.dr → tiny_calc/calc_prec.action.dr} +31 -31
 - data/lib/depager/cli.rb +44 -0
 - data/lib/depager/grammar.rb +253 -291
 - data/lib/depager/lr.rb +589 -579
 - data/lib/depager/parser.rb +269 -277
 - data/lib/depager/plugins/_rie_debug.rb +63 -0
 - data/lib/depager/plugins/action.rb +47 -0
 - data/lib/depager/plugins/ast.dr +367 -0
 - data/lib/depager/plugins/ast.rb +1329 -0
 - data/lib/depager/{ruby/plugins → plugins}/cst.dr +174 -180
 - data/lib/depager/plugins/cst.rb +591 -0
 - data/lib/depager/{ruby/plugins → plugins}/lex.dr +85 -89
 - data/lib/depager/plugins/lex.rb +313 -0
 - data/lib/depager/plugins/rie.dr +725 -0
 - data/lib/depager/plugins/rie.rb +1614 -0
 - data/lib/depager/{ruby/plugins → plugins}/slex.dr +201 -200
 - data/lib/depager/plugins/slex.rb +769 -0
 - data/lib/depager/plugins/srp.rb +46 -0
 - data/lib/depager/ruby/templates/extension_lalr_master.erb +40 -51
 - data/lib/depager/ruby/templates/extension_lalr_slave.erb +113 -107
 - data/lib/depager/ruby/templates/single_lalr_parser.erb +124 -117
 - data/lib/depager/utils.rb +158 -318
 - data/lib/depager/version.rb +3 -3
 - data/lib/depager.rb +572 -670
 - metadata +77 -80
 - data/ChangeLog +0 -16
 - data/data/depager/pre-setup.rb +0 -3
 - data/examples/c89/c89.tab.rb +0 -7127
 - data/examples/pl0d/pl0ds.tab.rb +0 -2698
 - data/examples/sample_calc/calc.action.tab.rb +0 -457
 - data/examples/sample_calc/calc.ast.action.tab.rb +0 -749
 - data/examples/sample_calc/calc.ast.tab.rb +0 -665
 - data/examples/sample_calc/calc.astdf.dr +0 -54
 - data/examples/sample_calc/calc.astdf.tab.rb +0 -672
 - data/examples/sample_calc/calc.atree.tab.rb +0 -451
 - data/examples/sample_calc/calc.cst.dr +0 -45
 - data/examples/sample_calc/calc.cst.tab.rb +0 -644
 - data/examples/sample_calc/calc.lex.tab.rb +0 -374
 - data/examples/sample_calc/calc.nvaction.tab.rb +0 -465
 - data/examples/sample_calc/calc.tab.rb +0 -365
 - data/examples/sample_calc/calc_prec.nvaction.tab.rb +0 -431
 - data/examples/slex_test/divreg.slex.tab.rb +0 -303
 - data/examples/slex_test/ljoin.slex.tab.rb +0 -370
 - data/lib/depager/ruby/plugins/_ast_tmpl.rb +0 -73
 - data/lib/depager/ruby/plugins/action.rb +0 -43
 - data/lib/depager/ruby/plugins/ast.dr +0 -269
 - data/lib/depager/ruby/plugins/ast.rb +0 -1308
 - data/lib/depager/ruby/plugins/astdf.rb +0 -6
 - data/lib/depager/ruby/plugins/atree.dr +0 -55
 - data/lib/depager/ruby/plugins/atree.rb +0 -347
 - data/lib/depager/ruby/plugins/cst.rb +0 -626
 - data/lib/depager/ruby/plugins/lex.rb +0 -336
 - data/lib/depager/ruby/plugins/nvaction.rb +0 -19
 - data/lib/depager/ruby/plugins/slex.rb +0 -817
 - data/lib/depager/ruby/plugins/srp.rb +0 -51
 - data/lib/depager/ruby/templates/simple.erb +0 -23
 - data/setup.rb +0 -1585
 - /data/examples/{sample_calc → tiny_calc}/test.calc +0 -0
 
    
        data/examples/c89/test.c89
    CHANGED
    
    | 
         @@ -1,10 +1,10 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            /*
         
     | 
| 
       2 
     | 
    
         
            -
              comment
         
     | 
| 
       3 
     | 
    
         
            -
            */
         
     | 
| 
       4 
     | 
    
         
            -
            int fact(int n)
         
     | 
| 
       5 
     | 
    
         
            -
            {
         
     | 
| 
       6 
     | 
    
         
            -
                if (n ==  
     | 
| 
       7 
     | 
    
         
            -
                    return 1;
         
     | 
| 
       8 
     | 
    
         
            -
                else
         
     | 
| 
       9 
     | 
    
         
            -
                    return n * fact(n - 1);
         
     | 
| 
       10 
     | 
    
         
            -
            }
         
     | 
| 
      
 1 
     | 
    
         
            +
            /*
         
     | 
| 
      
 2 
     | 
    
         
            +
              comment
         
     | 
| 
      
 3 
     | 
    
         
            +
            */
         
     | 
| 
      
 4 
     | 
    
         
            +
            int fact(int n)
         
     | 
| 
      
 5 
     | 
    
         
            +
            {
         
     | 
| 
      
 6 
     | 
    
         
            +
                if (n == 0)
         
     | 
| 
      
 7 
     | 
    
         
            +
                    return 1;
         
     | 
| 
      
 8 
     | 
    
         
            +
                else
         
     | 
| 
      
 9 
     | 
    
         
            +
                    return n * fact(n - 1);
         
     | 
| 
      
 10 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,55 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            %defext Examples::ATreeBuilderExtension
         
     | 
| 
      
 2 
     | 
    
         
            +
            %extend Depager::Action ('depager/plugins/action.rb')
         
     | 
| 
      
 3 
     | 
    
         
            +
            %extend Depager::Lexer ('depager/plugins/lex.rb')
         
     | 
| 
      
 4 
     | 
    
         
            +
            %decorate @Action
         
     | 
| 
      
 5 
     | 
    
         
            +
            #%decorate Depager::LALR::ShiftReducePrinter ('depager/plugins/srp.rb')
         
     | 
| 
      
 6 
     | 
    
         
            +
            %expanded_code_delimiter DEPAGER_EXPANDED_CODE
         
     | 
| 
      
 7 
     | 
    
         
            +
            %inner{
         
     | 
| 
      
 8 
     | 
    
         
            +
              attr_accessor :action_code, :on_reduce
         
     | 
| 
      
 9 
     | 
    
         
            +
              def init_extension
         
     | 
| 
      
 10 
     | 
    
         
            +
                @action_code = ''
         
     | 
| 
      
 11 
     | 
    
         
            +
                @on_reduce = []
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
              def term_extension
         
     | 
| 
      
 14 
     | 
    
         
            +
                g_parser.outer_code <<
         
     | 
| 
      
 15 
     | 
    
         
            +
                  generate_action_decorator_code(@on_reduce, @action_code)
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
            %}
         
     | 
| 
      
 18 
     | 
    
         
            +
            %hook post_rhs
         
     | 
| 
      
 19 
     | 
    
         
            +
            %banner '=>...'
         
     | 
| 
      
 20 
     | 
    
         
            +
            %%
         
     | 
| 
      
 21 
     | 
    
         
            +
            %LEX{
         
     | 
| 
      
 22 
     | 
    
         
            +
              /[ \t]+/                { }
         
     | 
| 
      
 23 
     | 
    
         
            +
              /\r?\n/                 { yield nil, nil }
         
     | 
| 
      
 24 
     | 
    
         
            +
              /[a-zA-Z][a-zA-Z0-9_]*/ { yield token(:ID, $&) }
         
     | 
| 
      
 25 
     | 
    
         
            +
              /'(.+)'/                { yield token(:STR, $1) }
         
     | 
| 
      
 26 
     | 
    
         
            +
              /::/                    { yield token(:CC, $&) }
         
     | 
| 
      
 27 
     | 
    
         
            +
              /=>/                    { yield token(:EG, $&) }
         
     | 
| 
      
 28 
     | 
    
         
            +
              /./                     { yield token($&, $&) }
         
     | 
| 
      
 29 
     | 
    
         
            +
            %}
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            #begin-rule
         
     | 
| 
      
 32 
     | 
    
         
            +
              start:
         
     | 
| 
      
 33 
     | 
    
         
            +
                  EG ast
         
     | 
| 
      
 34 
     | 
    
         
            +
                  {
         
     | 
| 
      
 35 
     | 
    
         
            +
                    n = g_parser.rules.size-1
         
     | 
| 
      
 36 
     | 
    
         
            +
                    master.action_code <<
         
     | 
| 
      
 37 
     | 
    
         
            +
                      master.expand_inline_code(_ast, _EG.lineno, :wrap => "def _atree_#{n} val")
         
     | 
| 
      
 38 
     | 
    
         
            +
                    master.on_reduce[n] = ":_atree_#{n}"
         
     | 
| 
      
 39 
     | 
    
         
            +
                  }
         
     | 
| 
      
 40 
     | 
    
         
            +
              ;
         
     | 
| 
      
 41 
     | 
    
         
            +
              ast:
         
     | 
| 
      
 42 
     | 
    
         
            +
                  ID '(' ')'           { "[:#{_ID.value}]" }
         
     | 
| 
      
 43 
     | 
    
         
            +
                | ID '(' fact_list ')' { "[:#{_ID.value}, #{_fact_list.join(',')}]" }
         
     | 
| 
      
 44 
     | 
    
         
            +
                | ID                   { "val[#{g_parser.name_to_rhs_index(_ID.value)}]" }
         
     | 
| 
      
 45 
     | 
    
         
            +
              ;
         
     | 
| 
      
 46 
     | 
    
         
            +
              fact_list:
         
     | 
| 
      
 47 
     | 
    
         
            +
                  fact                 { [ _fact ] }
         
     | 
| 
      
 48 
     | 
    
         
            +
                | fact_list ',' fact   { _fact_list.push _fact }
         
     | 
| 
      
 49 
     | 
    
         
            +
              ;
         
     | 
| 
      
 50 
     | 
    
         
            +
              fact:
         
     | 
| 
      
 51 
     | 
    
         
            +
                  ID                   { "val[#{g_parser.name_to_rhs_index(_ID.value)}]" }
         
     | 
| 
      
 52 
     | 
    
         
            +
                | STR                  { "'#{_STR.value}'" }
         
     | 
| 
      
 53 
     | 
    
         
            +
              ;
         
     | 
| 
      
 54 
     | 
    
         
            +
            #end-rule
         
     | 
| 
      
 55 
     | 
    
         
            +
            %%
         
     | 
| 
         @@ -1,43 +1,42 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            %class TinyCalc
         
     | 
| 
       2 
     | 
    
         
            -
            %extend Lexer ('plugins/lex.rb')
         
     | 
| 
       3 
     | 
    
         
            -
            %extend ATreeBuilder (' 
     | 
| 
       4 
     | 
    
         
            -
            %decorate @ATreeBuilder
         
     | 
| 
       5 
     | 
    
         
            -
            #%decorate ShiftReducePrinter ('plugins/srp.rb')
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
               
     | 
| 
       11 
     | 
    
         
            -
               
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                  expr  
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
               
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
                  term  
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
               
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                  NUM
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
            pp r
         
     | 
| 
      
 1 
     | 
    
         
            +
            %class TinyCalc::Parser
         
     | 
| 
      
 2 
     | 
    
         
            +
            %extend Depager::Lexer ('depager/plugins/lex.rb')
         
     | 
| 
      
 3 
     | 
    
         
            +
            %extend Examples::ATreeBuilder ('./atree.dr.rb')
         
     | 
| 
      
 4 
     | 
    
         
            +
            %decorate @ATreeBuilder
         
     | 
| 
      
 5 
     | 
    
         
            +
            #%decorate Depager::LALR::ShiftReducePrinter ('depager/plugins/srp.rb')
         
     | 
| 
      
 6 
     | 
    
         
            +
            %%
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            %LEX{
         
     | 
| 
      
 9 
     | 
    
         
            +
              /\s+/, /\#.*/ { }
         
     | 
| 
      
 10 
     | 
    
         
            +
              /[1-9][0-9]*/ { yield token(:NUM, $&.to_i) }
         
     | 
| 
      
 11 
     | 
    
         
            +
              /./           { yield token($&, $&) }
         
     | 
| 
      
 12 
     | 
    
         
            +
            %}
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            #begin-rule
         
     | 
| 
      
 15 
     | 
    
         
            +
              expr :
         
     | 
| 
      
 16 
     | 
    
         
            +
                  expr '+' term
         
     | 
| 
      
 17 
     | 
    
         
            +
                  => add(expr, term)
         
     | 
| 
      
 18 
     | 
    
         
            +
                | expr '-' term
         
     | 
| 
      
 19 
     | 
    
         
            +
                  => sub(expr, term)
         
     | 
| 
      
 20 
     | 
    
         
            +
                | term
         
     | 
| 
      
 21 
     | 
    
         
            +
                  => term
         
     | 
| 
      
 22 
     | 
    
         
            +
              ;
         
     | 
| 
      
 23 
     | 
    
         
            +
              term :
         
     | 
| 
      
 24 
     | 
    
         
            +
                  term '*' fact
         
     | 
| 
      
 25 
     | 
    
         
            +
                  => mul(term, fact)
         
     | 
| 
      
 26 
     | 
    
         
            +
                | term '/' fact
         
     | 
| 
      
 27 
     | 
    
         
            +
                  => div(term, fact)
         
     | 
| 
      
 28 
     | 
    
         
            +
                | fact
         
     | 
| 
      
 29 
     | 
    
         
            +
                  => fact
         
     | 
| 
      
 30 
     | 
    
         
            +
              ;
         
     | 
| 
      
 31 
     | 
    
         
            +
              fact :
         
     | 
| 
      
 32 
     | 
    
         
            +
                  NUM
         
     | 
| 
      
 33 
     | 
    
         
            +
                  => literal(NUM)
         
     | 
| 
      
 34 
     | 
    
         
            +
                | '(' expr ')'
         
     | 
| 
      
 35 
     | 
    
         
            +
                  => expr
         
     | 
| 
      
 36 
     | 
    
         
            +
              ;
         
     | 
| 
      
 37 
     | 
    
         
            +
            #end-rule
         
     | 
| 
      
 38 
     | 
    
         
            +
            %%
         
     | 
| 
      
 39 
     | 
    
         
            +
            require 'pp'
         
     | 
| 
      
 40 
     | 
    
         
            +
            parser = TinyCalc.create_decorated_parser()
         
     | 
| 
      
 41 
     | 
    
         
            +
            t, = parser.parse(ARGF)
         
     | 
| 
      
 42 
     | 
    
         
            +
            pp t
         
     | 
| 
         @@ -1,33 +1,33 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            %class TinyCalc
         
     | 
| 
       2 
     | 
    
         
            -
            %extend Lexer ('plugins/lex.rb')
         
     | 
| 
       3 
     | 
    
         
            -
            %extend  
     | 
| 
       4 
     | 
    
         
            -
            %decorate @ 
     | 
| 
       5 
     | 
    
         
            -
            #%decorate ShiftReducePrinter ('plugins/srp.rb')
         
     | 
| 
       6 
     | 
    
         
            -
            %%
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
            %LEX{
         
     | 
| 
       9 
     | 
    
         
            -
              /\s+/, /\#.*/ { }
         
     | 
| 
       10 
     | 
    
         
            -
              /[1-9][0-9]*/ { yield token(:NUM, $&.to_i) }
         
     | 
| 
       11 
     | 
    
         
            -
              /./           { yield token($&, $&) }
         
     | 
| 
       12 
     | 
    
         
            -
            %}
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
            #begin-rule
         
     | 
| 
       15 
     | 
    
         
            -
              expr : 
     | 
| 
       16 
     | 
    
         
            -
                  expr '+' term { val[0] + val[2] }
         
     | 
| 
       17 
     | 
    
         
            -
                | expr '-' term { val[0] - val[2] }
         
     | 
| 
       18 
     | 
    
         
            -
                | term          { val[0] }
         
     | 
| 
       19 
     | 
    
         
            -
              ;
         
     | 
| 
       20 
     | 
    
         
            -
              term :
         
     | 
| 
       21 
     | 
    
         
            -
                  term '*' fact { val[0] * val[2] }
         
     | 
| 
       22 
     | 
    
         
            -
                | term '/' fact { val[0] / val[2] }
         
     | 
| 
       23 
     | 
    
         
            -
                | fact          { val[0] }
         
     | 
| 
       24 
     | 
    
         
            -
              ;
         
     | 
| 
       25 
     | 
    
         
            -
              fact :
         
     | 
| 
       26 
     | 
    
         
            -
                  NUM           { val[0].value }
         
     | 
| 
       27 
     | 
    
         
            -
                | '(' expr ')'  { val[1] }
         
     | 
| 
       28 
     | 
    
         
            -
              ;
         
     | 
| 
       29 
     | 
    
         
            -
            #end-rule
         
     | 
| 
       30 
     | 
    
         
            -
            %%
         
     | 
| 
       31 
     | 
    
         
            -
            parser = TinyCalc 
     | 
| 
       32 
     | 
    
         
            -
            r, = parser.parse( 
     | 
| 
       33 
     | 
    
         
            -
            puts r
         
     | 
| 
      
 1 
     | 
    
         
            +
            %class TinyCalc::Parser
         
     | 
| 
      
 2 
     | 
    
         
            +
            %extend Depager::Lexer ('depager/plugins/lex.rb')
         
     | 
| 
      
 3 
     | 
    
         
            +
            %extend Examples::SimpleAction ('./simple_action.rb')
         
     | 
| 
      
 4 
     | 
    
         
            +
            %decorate @SimpleAction
         
     | 
| 
      
 5 
     | 
    
         
            +
            #%decorate Depager::LALR::ShiftReducePrinter ('depager/plugins/srp.rb')
         
     | 
| 
      
 6 
     | 
    
         
            +
            %%
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            %LEX{
         
     | 
| 
      
 9 
     | 
    
         
            +
              /\s+/, /\#.*/ { }
         
     | 
| 
      
 10 
     | 
    
         
            +
              /[1-9][0-9]*/ { yield token(:NUM, $&.to_i) }
         
     | 
| 
      
 11 
     | 
    
         
            +
              /./           { yield token($&, $&) }
         
     | 
| 
      
 12 
     | 
    
         
            +
            %}
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            #begin-rule
         
     | 
| 
      
 15 
     | 
    
         
            +
              expr :
         
     | 
| 
      
 16 
     | 
    
         
            +
                  expr '+' term { val[0] + val[2] }
         
     | 
| 
      
 17 
     | 
    
         
            +
                | expr '-' term { val[0] - val[2] }
         
     | 
| 
      
 18 
     | 
    
         
            +
                | term          { val[0] }
         
     | 
| 
      
 19 
     | 
    
         
            +
              ;
         
     | 
| 
      
 20 
     | 
    
         
            +
              term :
         
     | 
| 
      
 21 
     | 
    
         
            +
                  term '*' fact { val[0] * val[2] }
         
     | 
| 
      
 22 
     | 
    
         
            +
                | term '/' fact { val[0] / val[2] }
         
     | 
| 
      
 23 
     | 
    
         
            +
                | fact          { val[0] }
         
     | 
| 
      
 24 
     | 
    
         
            +
              ;
         
     | 
| 
      
 25 
     | 
    
         
            +
              fact :
         
     | 
| 
      
 26 
     | 
    
         
            +
                  NUM           { val[0].value }
         
     | 
| 
      
 27 
     | 
    
         
            +
                | '(' expr ')'  { val[1] }
         
     | 
| 
      
 28 
     | 
    
         
            +
              ;
         
     | 
| 
      
 29 
     | 
    
         
            +
            #end-rule
         
     | 
| 
      
 30 
     | 
    
         
            +
            %%
         
     | 
| 
      
 31 
     | 
    
         
            +
            parser = TinyCalc.create_decorated_parser
         
     | 
| 
      
 32 
     | 
    
         
            +
            r, = parser.parse(ARGF)
         
     | 
| 
      
 33 
     | 
    
         
            +
            puts r
         
     | 
| 
         @@ -1,15 +1,16 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            %defext PseudoActionExtension
         
     | 
| 
       2 
     | 
    
         
            -
            %extend Lexer ('plugins/lex.rb')
         
     | 
| 
       3 
     | 
    
         
            -
            %extend Action ('plugins/action.rb')
         
     | 
| 
       4 
     | 
    
         
            -
            %decorate @Action
         
     | 
| 
       5 
     | 
    
         
            -
            #%decorate ShiftReducePrinter ('plugins/srp.rb')
         
     | 
| 
       6 
     | 
    
         
            -
            %hook  
     | 
| 
       7 
     | 
    
         
            -
            %%
         
     | 
| 
       8 
     | 
    
         
            -
            %LEX{
         
     | 
| 
       9 
     | 
    
         
            -
              /\s 
     | 
| 
       10 
     | 
    
         
            -
               
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
              
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            %defext Examples::PseudoActionExtension
         
     | 
| 
      
 2 
     | 
    
         
            +
            %extend Depager::Lexer ('depager/plugins/lex.rb')
         
     | 
| 
      
 3 
     | 
    
         
            +
            %extend Depager::Action ('depager/plugins/action.rb')
         
     | 
| 
      
 4 
     | 
    
         
            +
            %decorate @Action
         
     | 
| 
      
 5 
     | 
    
         
            +
            #%decorate Depager::LALR::ShiftReducePrinter ('depager/plugins/srp.rb')
         
     | 
| 
      
 6 
     | 
    
         
            +
            %hook post_rhs
         
     | 
| 
      
 7 
     | 
    
         
            +
            %%
         
     | 
| 
      
 8 
     | 
    
         
            +
            %LEX{
         
     | 
| 
      
 9 
     | 
    
         
            +
              /\s+/ { }
         
     | 
| 
      
 10 
     | 
    
         
            +
              /\{/  { yield $&, $&, @lineno }
         
     | 
| 
      
 11 
     | 
    
         
            +
              /\}/  { yield $&, $&, @lineno ; yield nil, nil }
         
     | 
| 
      
 12 
     | 
    
         
            +
            %}
         
     | 
| 
      
 13 
     | 
    
         
            +
             start:
         
     | 
| 
      
 14 
     | 
    
         
            +
               '{' '}' { warn 'HIT' }
         
     | 
| 
      
 15 
     | 
    
         
            +
             ;
         
     | 
| 
      
 16 
     | 
    
         
            +
            %%
         
     | 
| 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            %class PseudoActionTest
         
     | 
| 
       2 
     | 
    
         
            -
            %extend PseudoAction ('paction.rb')
         
     | 
| 
       3 
     | 
    
         
            -
            %%
         
     | 
| 
       4 
     | 
    
         
            -
            #begin-rule
         
     | 
| 
       5 
     | 
    
         
            -
              expr:
         
     | 
| 
       6 
     | 
    
         
            -
                  expr '+' fact { }
         
     | 
| 
       7 
     | 
    
         
            -
              ;
         
     | 
| 
       8 
     | 
    
         
            -
              fact:
         
     | 
| 
       9 
     | 
    
         
            -
                  ID { }
         
     | 
| 
       10 
     | 
    
         
            -
              ;
         
     | 
| 
       11 
     | 
    
         
            -
            #end-rule
         
     | 
| 
       12 
     | 
    
         
            -
            %%
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            %class PseudoActionTest::Parser
         
     | 
| 
      
 2 
     | 
    
         
            +
            %extend Examples::PseudoAction ('./paction.dr.rb')
         
     | 
| 
      
 3 
     | 
    
         
            +
            %%
         
     | 
| 
      
 4 
     | 
    
         
            +
            #begin-rule
         
     | 
| 
      
 5 
     | 
    
         
            +
              expr:
         
     | 
| 
      
 6 
     | 
    
         
            +
                  expr '+' fact { }
         
     | 
| 
      
 7 
     | 
    
         
            +
              ;
         
     | 
| 
      
 8 
     | 
    
         
            +
              fact:
         
     | 
| 
      
 9 
     | 
    
         
            +
                  ID { }
         
     | 
| 
      
 10 
     | 
    
         
            +
              ;
         
     | 
| 
      
 11 
     | 
    
         
            +
            #end-rule
         
     | 
| 
      
 12 
     | 
    
         
            +
            %%
         
     | 
| 
      
 13 
     | 
    
         
            +
            parser = PseudoActionTest.new()
         
     | 
| 
      
 14 
     | 
    
         
            +
            pareser.parse(ARGF)
         
     | 
| 
         @@ -0,0 +1,46 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "depager/parser"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Examples; end
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            class Examples::SimpleActionExtension < Depager::Extension # :nodoc:all
         
     | 
| 
      
 6 
     | 
    
         
            +
              def init_extension
         
     | 
| 
      
 7 
     | 
    
         
            +
                @line0 = @line = @oldline = ""
         
     | 
| 
      
 8 
     | 
    
         
            +
                @action_code = ""
         
     | 
| 
      
 9 
     | 
    
         
            +
                @on_reduce = []
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              def term_extension
         
     | 
| 
      
 13 
     | 
    
         
            +
                g_parser.outer_code <<
         
     | 
| 
      
 14 
     | 
    
         
            +
                  generate_action_decorator_code(@on_reduce, @action_code)
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              def modify_action_code(code)
         
     | 
| 
      
 18 
     | 
    
         
            +
                [code, 0]
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              def pre_rule_list
         
     | 
| 
      
 22 
     | 
    
         
            +
                return unless /^%ACTION\{\s*$/.match?(g_parser.original_line)
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                while (line = file.gets)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  break if /^%\}\s*$/.match?(line)
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                  @action_code << line
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
                g_parser.update_context ""
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              def post_rhs
         
     | 
| 
      
 33 
     | 
    
         
            +
                return unless /\s*\{/.match?(g_parser.line)
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                @original_line = g_parser.original_line
         
     | 
| 
      
 36 
     | 
    
         
            +
                @line = g_parser.line
         
     | 
| 
      
 37 
     | 
    
         
            +
                lineno = g_parser.file.lineno
         
     | 
| 
      
 38 
     | 
    
         
            +
                code = parse_block
         
     | 
| 
      
 39 
     | 
    
         
            +
                d = 1
         
     | 
| 
      
 40 
     | 
    
         
            +
                n = g_parser.rules.size - 1
         
     | 
| 
      
 41 
     | 
    
         
            +
                @action_code <<
         
     | 
| 
      
 42 
     | 
    
         
            +
                  expand_inline_code(code, lineno, wrap: "def _act_#{n} val", delta: d)
         
     | 
| 
      
 43 
     | 
    
         
            +
                g_parser.update_context @line
         
     | 
| 
      
 44 
     | 
    
         
            +
                @on_reduce[n] = ":_act_#{n}"
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
            end
         
     |