-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modules/codegen: Add support for bison/byacc/yacc
- Loading branch information
Showing
3 changed files
with
122 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,30 @@ headers = [l1[1], l1[2]] # [header, table] | |
l2 = codegen.lex('lexer.l', table : '@[email protected]') | ||
table = l2[1] | ||
``` | ||
|
||
### yacc() | ||
|
||
```meson | ||
codegen.yacc('parser.y') | ||
``` | ||
|
||
This function wraps bison, yacc, byacc, and win_bison (on Windows), and attempts to abstract away the differences between them | ||
|
||
This requires an input file, which may be a string, File, or generated source. It additionally takes the following options keyword arguments: | ||
|
||
- `version`: Version constraints on the lexer | ||
- `args`: An array of extra arguments to pass the lexer | ||
- `plainname`: If set to true then `@PLAINNAME@` will be used as the source base, otherwise `@BASENAME@`. | ||
- `source`: the name of the source output. If this is unset Meson will use `{base}.{ext}` with an extension of `cpp` if the input has an extension of `.yy` or `c` otherwise, with base being determined by the `plainname` argument. | ||
- `header`: the name of the source output. If this is unset Meson will use `{base}.{ext}` with an extension of `hpp` if the input has an extension of `.yy` or `h` otherwise, with base being determined by the `plainname` argument. | ||
- `locations`: The name of the locations file, if one is generated. Due to the way yacc works this must be duplicated in the file and in the command. | ||
|
||
The outputs will be in the form `source header [locations]`, which means those can be accessed by indexing the output of the `yacc` call: | ||
|
||
```meson | ||
p1 = codegen.yacc('parser.y', header : '@[email protected]', table : '@[email protected]') | ||
headers = [l1[1], l1[2]] # [header, table] | ||
p2 = codegen.lex('parser.y', locations : 'locations.hpp') | ||
table = l2[1] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ project('flex and bison', 'c') | |
|
||
# TODO: handle win_flex/win_bison | ||
|
||
flex = find_program('flex', 'lex', required: false) | ||
bison = find_program('bison', required: false) | ||
flex = find_program('flex', 'reflex', 'lex', required: false) | ||
bison = find_program('bison', 'byacc', 'yacc', required: false) | ||
|
||
if not flex.found() | ||
error('MESON_SKIP_TEST flex not found.') | ||
|
@@ -22,12 +22,7 @@ endif | |
|
||
codegen = import('unstable-codegen') | ||
lfiles = codegen.lex('lexer.l') | ||
|
||
pgen = generator(bison, | ||
output : ['@[email protected]', '@[email protected]'], | ||
arguments : ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@']) | ||
|
||
pfiles = pgen.process('parser.y') | ||
pfiles = codegen.yacc('parser.y', header : '@[email protected]') | ||
|
||
e = executable( | ||
'pgen', | ||
|