diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2025-05-29 12:58:15 -0700 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-10-24 22:20:49 -0700 |
| commit | 860c2bfad35d35dbef056f5775ead376868373d6 (patch) | |
| tree | 470f3d55bb5106698bd366cbd56007759f74c14f /docs | |
| parent | 6aefc92c33f7bef17c338aa3e456dc45ca41058a (diff) | |
| download | meson-860c2bfad35d35dbef056f5775ead376868373d6.tar.gz | |
modules/codegen: Add support for bison/byacc/yacc
This adds a similar wrapper to the Lex wrapper for yacc/bison/byacc. The
interface is equivalent.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/markdown/Codegen-module.md | 66 | ||||
| -rw-r--r-- | docs/markdown/snippets/codegen_module.md | 2 |
2 files changed, 66 insertions, 2 deletions
diff --git a/docs/markdown/Codegen-module.md b/docs/markdown/Codegen-module.md index 5c2618d6b..0f6d524f2 100644 --- a/docs/markdown/Codegen-module.md +++ b/docs/markdown/Codegen-module.md @@ -10,7 +10,7 @@ authors: *(New in 1.10.0)* -This module provides wrappers around common code generators, such as flex/lex. This purpose of this is to make it easier and more pleasant to use *common* code generators in a mesonic way. +This module provides wrappers around common code generators, such as flex/lex and yacc/bison. This purpose of this is to make it easier and more pleasant to use *common* code generators in a mesonic way. ## Functions @@ -33,6 +33,25 @@ It accepts the following keyword arguments: - `disabler`: Return a disabler if not found - `native`: Is this generator for the host or build machine? +### yacc() + +```meson +yacc = codegen.yacc(implementations : ['bison', 'win_bison']) +``` + +This function provides fine grained controls over which implementation(s) and version(s) of the parser generator to use. + +Accepts the following keyword arguments: + + - `implementations`: a string array of acceptable implementations to use. May include: `yacc`, `byacc`, `bison`, or `win_bison`. + - `yacc_version`: a string array of version constraints to apply to the `yacc` binary + - `byacc_version`: a string array of version constraints to apply to the `byacc` binary + - `bison_version`: a string array of version constraints to apply to the `bison` binary + - `win_bison_version`: a string array of version constraints to apply to the `win_bison` binary + - `required`: A boolean or feature option + - `disabler`: Return a disabler if not found + - `native`: Is this generator for the host or build machine? + ## Returned Objects ### LexGenerator @@ -78,3 +97,48 @@ headers = [l1[1], l1[2]] # [header, table] l2 = lex.generate('lexer.l', table : '@BASENAME@.tab.h') table = l2[1] ``` + +### YaccGenerator + +#### yacc.implementation + +```meson +yacc = codegen.yacc() +impl = yacc.implementation() +``` + +Returns the string name of the yacc implementation chosen. May be one of: + +- yacc +- bison +- byacc +- win_bison + +#### yacc.generate + +```meson +yacc = codegen.yacc() +yacc.generate('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 header 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 +yacc = codegen.yacc() +p1 = yacc.generate('parser.y', header : '@BASENAME@.h', locations : 'locations.h') +headers = [p1[1], p1[2]] # [header, locations] + +p2 = yacc.generate('parser.yy', locations : 'locations.hpp') +locations = p2[1] +``` diff --git a/docs/markdown/snippets/codegen_module.md b/docs/markdown/snippets/codegen_module.md index b4ea04c0a..0dd79c576 100644 --- a/docs/markdown/snippets/codegen_module.md +++ b/docs/markdown/snippets/codegen_module.md @@ -1,3 +1,3 @@ ## Experimental Codegen module -A new module wrapping some common code generators has been added. Currently it supports lex/flex. +A new module wrapping some common code generators has been added. Currently it supports lex/flex and yacc/bison. |
