You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit adds a new directive `%type-params`, which allows passing arbitrary generics (types and lifetimes) to the generated parser implementation.
The generics are propagated to action functions and `__GtActionsKind`, so they're available in return types as well.
This change only affects generated code: generics are not propagated to parser backend.
I've also added an example with my use case: passing an arena allocator, and returning references to AST nodes.
Copy file name to clipboardExpand all lines: doc/src/actioncode.md
+16Lines changed: 16 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,3 +69,19 @@ R -> ...:
69
69
'ID' { format!("{}{}", p, ...) }
70
70
;
71
71
```
72
+
73
+
# Generic parse parameter
74
+
75
+
If `%parse-param` needs to be generic, additional type variables and lifetimes
76
+
can be specified in the `%parse-generics T1, T2, ...` declaration.
77
+
78
+
For example, if a grammar has following declarations:
79
+
80
+
```
81
+
%parse-generics T: FromStr
82
+
%parse-param p: T
83
+
```
84
+
85
+
then the `parse` function will take an additional parameter of type `T`.
86
+
87
+
This can be used, for example, [to allocate AST nodes in a memory arena.](https://github.com/softdevteam/grmtools/tree/master/lrpar/examples/calc_ast_arena).
0 commit comments