lrama 0.5.11 → 0.5.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 634093bc73fd1504910364bffa6827a66fa7479f1f5b5238fdf577f0bb6d3d9d
4
- data.tar.gz: 96db570d049f47f20bf619535ee91e7f0f846a492404a54f7fe41a6addcce484
3
+ metadata.gz: '008f1a5df39b115123be84cb5e1edd379d88458bc95256b0e4fe4659481ceb51'
4
+ data.tar.gz: 02af30da8cf4cb2cad841f43b603433edafab09b0cf0e8993201c2e9aea12029
5
5
  SHA512:
6
- metadata.gz: 6b09e84cd16cd162f263e68abf7ada808418212ca449fab0f4a380c42c0193f479cad3d0d1afcc1d5f17d81b890e3754642d1a9433f7be5f6fc71fdcb2df3f97
7
- data.tar.gz: 1994a670f1033e737f2193e2e71ccaa0818e4144ac7f4424ebf24046ece23efc3f67eeb0927c5336663a244f270b321247b39dbbdbe76cfacc13b94da6289a8b
6
+ metadata.gz: 12cf8b98035052e89f9060dd73ec2b32ad9c5bec2fe4076e6ee0416832039962cf973c7ca895b482f2f434500648638c01a717d67357aa055eccce851995adaf
7
+ data.tar.gz: a4cffc85bb5945a3d4d037c0eadee0df22e30236085e01f06bffe1646d0acafd09fdb606860752cdea9dbfdf45baa1fc8d244504b7a0ca29c37ab60f9a727367
@@ -122,7 +122,7 @@ jobs:
122
122
  - run: mkdir -p tool/lrama
123
123
  working-directory: ../ruby
124
124
  - name: Copy Lrama to ruby/tool
125
- run: cp -r LEGAL.md MIT exe lib template ../ruby/tool/lrama
125
+ run: cp -r LEGAL.md NEWS.md MIT exe lib template ../ruby/tool/lrama
126
126
  working-directory:
127
127
  - run: tree tool/lrama
128
128
  working-directory: ../ruby
data/LEGAL.md CHANGED
@@ -7,5 +7,6 @@ mentioned below.
7
7
 
8
8
  These files are licensed under the GNU General Public License version 3 or later. See these files for more information.
9
9
 
10
+ * template/bison/_yacc.h
10
11
  * template/bison/yacc.c
11
12
  * template/bison/yacc.h
data/NEWS.md ADDED
@@ -0,0 +1,167 @@
1
+ # NEWS for Lrama
2
+
3
+ ## Lrama 0.5.11 (2023-12-02)
4
+
5
+ ### Type specification of parameterizing rules
6
+
7
+ Allow to specify type of rules by specifying tag, `<i>` in below example.
8
+ Tag is post-modification style.
9
+
10
+ ```
11
+ %union {
12
+ int i;
13
+ }
14
+
15
+ %%
16
+
17
+ program : option(number) <i>
18
+ | number_alias? <i>
19
+ ;
20
+ ```
21
+
22
+ https://github.com/ruby/lrama/pull/272
23
+
24
+
25
+ ## Lrama 0.5.10 (2023-11-18)
26
+
27
+ ### Parameterizing rules (option, nonempty_list, list)
28
+
29
+ Support function call style parameterizing rules for `option`, `nonempty_list` and `list`.
30
+
31
+ https://github.com/ruby/lrama/pull/197
32
+
33
+ ### Parameterizing rules (separated_list)
34
+
35
+ Support `separated_list` and `separated_nonempty_list` parameterizing rules.
36
+
37
+ ```
38
+ program: separated_list(',', number)
39
+
40
+ // Expanded to
41
+
42
+ program: separated_list_number
43
+ separated_list_number: ε
44
+ separated_list_number: separated_nonempty_list_number
45
+ separated_nonempty_list_number: number
46
+ separated_nonempty_list_number: separated_nonempty_list_number ',' number
47
+ ```
48
+
49
+ ```
50
+ program: separated_nonempty_list(',', number)
51
+
52
+ // Expanded to
53
+
54
+ program: separated_nonempty_list_number
55
+ separated_nonempty_list_number: number
56
+ separated_nonempty_list_number: separated_nonempty_list_number ',' number
57
+ ```
58
+
59
+ https://github.com/ruby/lrama/pull/204
60
+
61
+ ## Lrama 0.5.9 (2023-11-05)
62
+
63
+ ### Parameterizing rules (suffix)
64
+
65
+ Parameterizing rules are template of rules.
66
+ It's very common pattern to write "list" grammar rule like:
67
+
68
+ ```
69
+ opt_args: /* none */
70
+ | args
71
+ ;
72
+
73
+ args: arg
74
+ | args arg
75
+ ```
76
+
77
+ Lrama supports these suffixes:
78
+
79
+ * `?`: option
80
+ * `+`: nonempty list
81
+ * `*`: list
82
+
83
+ Idea of Parameterizing rules comes from Menhir LR(1) parser generator (https://gallium.inria.fr/~fpottier/menhir/manual.html#sec32).
84
+
85
+ https://github.com/ruby/lrama/pull/181
86
+
87
+ ## Lrama 0.5.7 (2023-10-23)
88
+
89
+ ### Racc parser
90
+
91
+ Replace Lrama's parser from hand written parser to LR parser generated by Racc.
92
+ Lrama uses `--embedded` option to generate LR parser because Racc is changed from default gem to bundled gem by Ruby 3.3 (https://github.com/ruby/lrama/pull/132).
93
+
94
+ https://github.com/ruby/lrama/pull/62
95
+
96
+ ## Lrama 0.5.4 (2023-08-17)
97
+
98
+ ### Runtime configuration for error recovery
99
+
100
+ Meke error recovery function configurable on runtime by two new macros.
101
+
102
+ * `YYMAXREPAIR`: Expected to return max length of repair operations. `%parse-param` is passed to this function.
103
+ * `YYERROR_RECOVERY_ENABLED`: Expected to return bool value to determine error recovery is enabled or not. `%parse-param` is passed to this function.
104
+
105
+ https://github.com/ruby/lrama/pull/74
106
+
107
+ ## Lrama 0.5.3 (2023-08-05)
108
+
109
+ ### Error Recovery
110
+
111
+ Support token insert base Error Recovery.
112
+ `-e` option is needed to generate parser with error recovery functions.
113
+
114
+ https://github.com/ruby/lrama/pull/44
115
+
116
+ ## Lrama 0.5.2 (2023-06-14)
117
+
118
+ ### Named References
119
+
120
+ Instead of positional references like `$1` or `$$`,
121
+ named references allow to access to symbol by name.
122
+
123
+ ```
124
+ primary: k_class cpath superclass bodystmt k_end
125
+ {
126
+ $primary = new_class($cpath, $bodystmt, $superclass);
127
+ }
128
+ ```
129
+
130
+ Alias name can be declared.
131
+
132
+ ```
133
+ expr[result]: expr[ex-left] '+' expr[ex.right]
134
+ {
135
+ $result = $[ex-left] + $[ex.right];
136
+ }
137
+ ```
138
+
139
+ Bison supports this feature from 2.5.
140
+
141
+ ### Add parse params to some macros and functions
142
+
143
+ `%parse-param` are added to these macros and functions to remove ytab.sed hack from Ruby.
144
+
145
+ * `YY_LOCATION_PRINT`
146
+ * `YY_SYMBOL_PRINT`
147
+ * `yy_stack_print`
148
+ * `YY_STACK_PRINT`
149
+ * `YY_REDUCE_PRINT`
150
+ * `yysyntax_error`
151
+
152
+ https://github.com/ruby/lrama/pull/40
153
+
154
+ See also: https://github.com/ruby/ruby/pull/7807
155
+
156
+ ## Lrama 0.5.0 (2023-05-17)
157
+
158
+ ### stdin mode
159
+
160
+ When `-` is given as grammar file name, reads the grammar source from STDIN, and takes the next argument as the input file name. This mode helps pre-process a grammar source.
161
+
162
+ https://github.com/ruby/lrama/pull/8
163
+
164
+ ## Lrama 0.4.0 (2023-05-13)
165
+
166
+ This is the first version migrated to Ruby.
167
+ This version generates "parse.c" compatible with Bison 3.8.2.
data/README.md CHANGED
@@ -138,7 +138,7 @@ $ stackprof --d3-flamegraph tmp/stackprof-cpu-myapp.dump > tmp/flamegraph.html
138
138
 
139
139
  1. Update `Lrama::VERSION`
140
140
  2. Release as a gem by `rake release`
141
- 3. Update Lrama in ruby/ruby by `cp -r LEGAL.md MIT exe lib template ruby/tool/lrama`
141
+ 3. Update Lrama in ruby/ruby by `cp -r LEGAL.md NEWS.md MIT exe lib template ruby/tool/lrama`
142
142
  4. Create new release on [GitHub](https://github.com/ruby/lrama/releases)
143
143
 
144
144
  ## License
@@ -14,9 +14,23 @@ module Lrama
14
14
  # * ($1) yyvsp[i]
15
15
  # * (@1) yylsp[i]
16
16
  #
17
+ #
18
+ # Consider a rule like
19
+ #
20
+ # class: keyword_class { $1 } tSTRING { $2 + $3 } keyword_end { $class = $1 + $keyword_end }
21
+ #
22
+ # For the semantic action of original rule:
23
+ #
24
+ # "Rule" class: keyword_class { $1 } tSTRING { $2 + $3 } keyword_end { $class = $1 + $keyword_end }
25
+ # "Position in grammar" $1 $2 $3 $4 $5 $6
26
+ # "Index for yyvsp" -4 -3 -2 -1 0
27
+ #
28
+ #
29
+ # For the first midrule action:
30
+ #
17
31
  # "Rule" class: keyword_class { $1 } tSTRING { $2 + $3 } keyword_end { $class = $1 + $keyword_end }
18
- # "Position in grammar" $1 $2 $3 $4 $5 $6
19
- # "Index for yyvsp" -4 -3 -2 -1 0
32
+ # "Position in grammar" $1
33
+ # "Index for yyvsp" 0
20
34
  def reference_to_c(ref)
21
35
  case
22
36
  when ref.type == :dollar && ref.name == "$" # $$
@@ -45,10 +59,12 @@ module Lrama
45
59
  @rule.position_in_original_rule_rhs || @rule.rhs.count
46
60
  end
47
61
 
62
+ # If this is midrule action, RHS is a RHS of the original rule.
48
63
  def rhs
49
64
  (@rule.original_rule || @rule).rhs
50
65
  end
51
66
 
67
+ # Unlike `rhs`, LHS is always a LHS of the rule.
52
68
  def lhs
53
69
  @rule.lhs
54
70
  end
data/lib/lrama/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lrama
2
- VERSION = "0.5.11".freeze
2
+ VERSION = "0.5.12".freeze
3
3
  end
@@ -3,6 +3,8 @@ module Lrama
3
3
  class ParameterizingRules
4
4
  class Builder
5
5
  class Base
6
+ attr_reader build_token: Lexer::Token::Ident
7
+
6
8
  def initialize: (Lexer::Token::Parameterizing token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
7
9
  def build: () -> Array[Rule]
8
10
 
@@ -10,7 +12,7 @@ module Lrama
10
12
  @token: Lexer::Token::Parameterizing
11
13
  @key: Symbol
12
14
  @rule_counter: Counter
13
- @lhs: Lexer::Token
15
+ @lhs_tag: untyped
14
16
  @user_code: Lexer::Token::UserCode?
15
17
  @precedence_sym: Lexer::Token?
16
18
  @line: Integer?
@@ -3,6 +3,8 @@ module Lrama
3
3
  class ParameterizingRules
4
4
  class Builder
5
5
  class SeparatedList < Base
6
+ @separator: Lexer::Token
7
+
6
8
  def initialize: (Lexer::Token token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
7
9
  end
8
10
  end
@@ -3,6 +3,8 @@ module Lrama
3
3
  class ParameterizingRules
4
4
  class Builder
5
5
  class SeparatedNonemptyList < Base
6
+ @separator: Lexer::Token
7
+
6
8
  def initialize: (Lexer::Token token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
7
9
  end
8
10
  end
@@ -7,14 +7,15 @@ module Lrama
7
7
  @token: Lexer::Token::Parameterizing
8
8
  @key: Symbol
9
9
  @rule_counter: Counter
10
- @lhs: Lexer::Token
10
+ @lhs_tag: untyped
11
11
  @user_code: Lexer::Token::UserCode?
12
12
  @precedence_sym: Lexer::Token?
13
13
  @line: Integer?
14
+ @builder: Grammar::ParameterizingRules::Builder::Base
14
15
 
15
16
  def initialize: (Lexer::Token token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
16
17
  def build: () -> Array[Rule]
17
- def build_token: () -> Lrama::Lexer::Token
18
+ def build_token: () -> Lexer::Token
18
19
  def create_builder: () -> void
19
20
  def validate_key!: () -> void
20
21
  end
@@ -2,9 +2,9 @@ module Lrama
2
2
  class Lexer
3
3
  class Token
4
4
  class Parameterizing < Token
5
- attr_accessor args: Array[Lrama::Lexer::Token]
5
+ attr_accessor args: Array[Lexer::Token]
6
6
 
7
- def initialize: (s_value: String, ?alias_name: String, ?location: Location, ?args: Array[Lrama::Lexer::Token]) -> void
7
+ def initialize: (s_value: String, ?alias_name: String, ?location: Location, ?args: Array[Lexer::Token]) -> void
8
8
 
9
9
  def option?: () -> bool
10
10
  def nonempty_list?: () -> bool
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lrama
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.11
4
+ version: 0.5.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuichiro Kaneko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-01 00:00:00.000000000 Z
11
+ date: 2023-12-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: LALR (1) parser generator written by Ruby
14
14
  email:
@@ -27,10 +27,10 @@ files:
27
27
  - Gemfile
28
28
  - LEGAL.md
29
29
  - MIT
30
+ - NEWS.md
30
31
  - README.md
31
32
  - Rakefile
32
33
  - Steepfile
33
- - doc/TODO.md
34
34
  - exe/lrama
35
35
  - lib/lrama.rb
36
36
  - lib/lrama/bitmap.rb
data/doc/TODO.md DELETED
@@ -1,59 +0,0 @@
1
- # TODO
2
-
3
- * command
4
- * lexer
5
- * [x] Basic functionalities
6
- * parser
7
- * [x] Basic functionalities
8
- * [x] Precedence in grammar
9
- * LALR
10
- * [x] compute_nullable
11
- * [x] compute_lr0_states
12
- * [x] Direct Read Sets
13
- * [x] Reads Relation
14
- * [x] Read Sets
15
- * [x] Includes Relation
16
- * [x] Lookback Relation
17
- * [x] Follow Sets
18
- * [x] Look-Ahead Sets
19
- * [x] Precedence support
20
- * [x] Conflict check
21
- * [x] Algorithm Digraph
22
- * [ ] Conflict resolution
23
- * [x] Do not generate default action if states have conflicts
24
- * [ ] Fix number of s/r conflicts of basic.y. See basic.output file generated by Bison.
25
- * Rendering
26
- * [x] Table compaction
27
- * [x] -d option
28
- * yacc.c
29
- * [x] %lex-param
30
- * [x] %parse-param
31
- * [x] %printer
32
- * [x] Replace $, @ in user codes
33
- * [x] `[@oline@]`
34
- * [ ] b4_symbol (for eof, error and so on)
35
- * Assumption
36
- * b4_locations_if is true
37
- * b4_pure_if is true
38
- * b4_pull_if is false
39
- * b4_lac_if is false
40
- * Performance improvement
41
- * [ ]
42
- * Licenses
43
- * [x] Write down something about licenses
44
- * Reporting
45
- * [ ] Bison style
46
- * [ ] Wrap not selected reduce with "[]". See basic.output file generated by Bison.
47
- * Counterexamples
48
- * [x] Nonunifying Counterexamples
49
- * [ ] Unifying Counterexamples
50
- * [ ] Performance improvement using reverse_transitions and reverse_productions
51
- * Error Tolerance
52
- * [x] Corchuelo et al. algorithm with N = 1 (this means the next token when error is raised)
53
- * [x] Add new decl for error token semantic value initialization (%error-token)
54
- * [x] Use YYMALLOC & YYFREE
55
- * Lex state
56
- * CI
57
- * [x] Setup CI
58
- * [x] Add ruby 3.1 or under
59
- * [x] Add integration tests which installs Lrama, build ruby and run `make test`