NEWS.md in lrama-0.6.10 vs NEWS.md in lrama-0.6.11
- old
+ new
@@ -1,14 +1,49 @@
# NEWS for Lrama
+## Lrama 0.6.11 (2024-12-23)
+
+### Add support for %type declarations using %nterm in Nonterminal Symbols
+
+Allow to use `%nterm` in Nonterminal Symbols for `%type` declarations.
+
+```yacc
+%nterm <type> nonterminal…
+```
+
+This directive is also supported for compatibility with Bison, and only non-terminal symbols are allowed. In other words, definitions like the following will result in an error:
+
+```yacc
+%{
+// Prologue
+%}
+
+%token EOI 0 "EOI"
+%nterm EOI
+
+%%
+
+program: /* empty */
+ ;
+```
+
+It show an error message like the following:
+
+```command
+❯ exe/lrama nterm.y
+nterm.y:6:7: symbol EOI redeclared as a nonterminal
+%nterm EOI
+ ^^^
+```
+
## Lrama 0.6.10 (2024-09-11)
### Aliased Named References for actions of RHS in parameterizing rules
Allow to use aliased named references for actions of RHS in parameterizing rules.
-```
+```yacc
%rule sum(X, Y): X[summand] '+' Y[addend] { $$ = $summand + $addend }
;
```
https://github.com/ruby/lrama/pull/410
@@ -16,22 +51,22 @@
### Named References for actions of RHS in parameterizing rules caller side
Allow to use named references for actions of RHS in parameterizing rules caller side.
-```
+```yacc
opt_nl: '\n'?[nl] <str> { $$ = $nl; }
;
```
https://github.com/ruby/lrama/pull/414
### Widen the definable position of parameterizing rules
Allow to define parameterizing rules in the middle of the grammar.
-```
+```yacc
%rule defined_option(X): /* empty */
| X
;
%%
@@ -50,12 +85,12 @@
### Report unused terminal symbols
Support to report unused terminal symbols.
Run `exe/lrama --report=terms` to show unused terminal symbols.
-```
-❯ exe/lrama --report=terms sample/calc.y
+```console
+$ exe/lrama --report=terms sample/calc.y
11 Unused Terms
0 YYerror
1 YYUNDEF
2 '\\\\'
3 '\\13'
@@ -72,12 +107,12 @@
### Report unused rules
Support to report unused rules.
Run `exe/lrama --report=rules` to show unused rules.
-```
-❯ exe/lrama --report=rules sample/calc.y
+```console
+$ exe/lrama --report=rules sample/calc.y
3 Unused Rules
0 unused_option
1 unused_list
2 unused_nonempty_list
```
@@ -94,12 +129,12 @@
### Diagnostics report for parameterizing rules redefine
Support to warning redefined parameterizing rules.
Run `exe/lrama -W` or `exe/lrama --warnings` to show redefined parameterizing rules.
-```
-❯ exe/lrama -W sample/calc.y
+```console
+$ exe/lrama -W sample/calc.y
parameterizing rule redefined: redefined_method(X)
parameterizing rule redefined: redefined_method(X)
```
https://github.com/ruby/lrama/pull/448
@@ -115,11 +150,11 @@
### Callee side tag specification of parameterizing rules
Allow to specify tag on callee side of parameterizing rules.
-```
+```yacc
%union {
int i;
}
%rule with_tag(X) <i>: X { $$ = $1; }
@@ -128,11 +163,11 @@
### Named References for actions of RHS in parameterizing rules
Allow to use named references for actions of RHS in parameterizing rules.
-```
+```yacc
%rule option(number): /* empty */
| number { $$ = $number; }
;
```
@@ -140,11 +175,11 @@
### Nested parameterizing rules with tag
Allow to nested parameterizing rules with tag.
-```
+```yacc
%union {
int i;
}
%rule nested_nested_option(X): /* empty */
@@ -177,12 +212,12 @@
### Trace actions
Support trace actions for debugging.
Run `exe/lrama --trace=actions` to show grammar rules with actions.
-```
-❯ exe/lrama --trace=actions sample/calc.y
+```console
+$ exe/lrama --trace=actions sample/calc.y
Grammar rules with actions:
$accept -> list, YYEOF {}
list -> ε {}
list -> list, LF {}
list -> list, expr, LF { printf("=> %d\n", $2); }
@@ -197,11 +232,11 @@
### Inlining
Support inlining for rules.
The `%inline` directive causes all references to symbols to be replaced with its definition.
-```
+```yacc
%rule %inline op: PLUS { + }
| TIMES { * }
;
%%
@@ -211,11 +246,11 @@
;
```
as same as
-```
+```yacc
expr : number { $$ = $1; }
| expr '+' expr { $$ = $1 + $3; }
| expr '*' expr { $$ = $1 * $3; }
;
```
@@ -224,11 +259,11 @@
### Typed Midrule Actions
User can specify the type of mid rule action by tag (`<bar>`) instead of specifying it with in an action.
-```
+```yacc
primary: k_case expr_value terms?
{
$<val>$ = p->case_labels;
p->case_labels = Qnil;
}
@@ -239,11 +274,11 @@
}
```
can be written as
-```
+```yacc
primary: k_case expr_value terms?
{
$$ = p->case_labels;
p->case_labels = Qnil;
}<val>
@@ -264,11 +299,11 @@
### Parameterizing rules (preceded, terminated, delimited)
Support `preceded`, `terminated` and `delimited` rules.
-```
+```text
program: preceded(opening, X)
// Expanded to
program: preceded_opening_X
@@ -300,11 +335,11 @@
User can set codes for freeing semantic value resources by using `%destructor`.
In general, these resources are freed by actions or after parsing.
However if syntax error happens in parsing, these codes may not be executed.
Codes associated to `%destructor` are executed when semantic value is popped from the stack by an error.
-```
+```yacc
%token <val1> NUM
%type <val2> expr2
%type <val3> expr
%destructor {
@@ -348,11 +383,11 @@
2. `$:n` variable to access index of each grammar symbols
User also needs to access semantic value of their stack in grammar action. `$:n` provides the way to access to it. `$:n` is translated to the minus index from the top of the stack.
For example
-```
+```yacc
primary: k_if expr_value then compstmt if_tail k_end
{
/*% ripper: if!($:2, $:4, $:5) %*/
/* $:2 = -5, $:4 = -3, $:5 = -2. */
}
@@ -373,11 +408,11 @@
### Nested parameterizing rules
Allow to pass an instantiated rule to other parameterizing rules.
-```
+```yacc
%rule constant(X) : X
;
%rule option(Y) : /* empty */
| Y
@@ -390,11 +425,11 @@
%%
```
Allow to use nested parameterizing rules when define parameterizing rules.
-```
+```yacc
%rule option(x) : /* empty */
| X
;
%rule double(Y) : Y Y
@@ -417,11 +452,11 @@
### User defined parameterizing rules
Allow to define parameterizing rule by `%rule` directive.
-```
+```yacc
%rule pair(X, Y): X Y { $$ = $1 + $2; }
;
%%
@@ -440,11 +475,11 @@
### Type specification of parameterizing rules
Allow to specify type of rules by specifying tag, `<i>` in below example.
Tag is post-modification style.
-```
+```yacc
%union {
int i;
}
%%
@@ -467,11 +502,11 @@
### Parameterizing rules (separated_list)
Support `separated_list` and `separated_nonempty_list` parameterizing rules.
-```
+```text
program: separated_list(',', number)
// Expanded to
program: separated_list_number
@@ -498,11 +533,11 @@
### Parameterizing rules (suffix)
Parameterizing rules are template of rules.
It's very common pattern to write "list" grammar rule like:
-```
+```yacc
opt_args: /* none */
| args
;
args: arg
@@ -530,11 +565,11 @@
## Lrama 0.5.4 (2023-08-17)
### Runtime configuration for error recovery
-Meke error recovery function configurable on runtime by two new macros.
+Make error recovery function configurable on runtime by two new macros.
* `YYMAXREPAIR`: Expected to return max length of repair operations. `%parse-param` is passed to this function.
* `YYERROR_RECOVERY_ENABLED`: Expected to return bool value to determine error recovery is enabled or not. `%parse-param` is passed to this function.
https://github.com/ruby/lrama/pull/74
@@ -553,19 +588,19 @@
### Named References
Instead of positional references like `$1` or `$$`,
named references allow to access to symbol by name.
-```
+```yacc
primary: k_class cpath superclass bodystmt k_end
{
$primary = new_class($cpath, $bodystmt, $superclass);
}
```
Alias name can be declared.
-```
+```yacc
expr[result]: expr[ex-left] '+' expr[ex.right]
{
$result = $[ex-left] + $[ex.right];
}
```