-
Notifications
You must be signed in to change notification settings - Fork 2
Installation & Usage
For now, cpspg can only be installed from its Git repository. To do so, execute the following commands:
git clone https://github.com/fram-lang/cpspg.git
cd cpspg
dune build --profile release
dune installEnsure that you have Git, OCaml, and Dune installed before running the above commands.
The general usage of cpspg is as follows:
cpspg [options] <input> [output...]
cpspg [options] [-f format] -o <output> <input>Both forms expect exactly one input file and an arbitrary number of output files. When the input file is omitted (or -), cpspg reads its data from standard input. When no output file is specified (or one of the outputs is -), cpspg writes the generated code to standard output.
Invoking cpspg without any options makes it read grammar from standard input and write generated OCaml code to standard output.
cpspg provides several options to customize its behavior and output:
-
-o <file>: Set the output file name to<file>. -
-f <format>: Forcecpspgto generate a file in the given<format>. By default, the format is guessed from the file extension, independently for each output file. Currently supported formats:-
ml- OCaml program -
mli- OCaml interface file -
dot- Graphviz visualization of the generated automaton
-
-
--lr0,--slr,--lr1,--lalr: Construct an$LR(0)$ ,$SLR$ ,$LR(1)$ , or$LALR(1)$ automaton, respectively. These automatons differ mainly by the number of generated states and by lookahead computation, with$LALR$ (the default) usually being the best option. -
--no-locations: Disable all code related to location tracking in the generated code. This disables the$locfamily of keywords. -
--no-line-directives: Do not include line directives in the generated code. -
--comment: Include comments in the generated code. -
--readable-ids: Make identifiers in the generated code longer. -
--readable: Make the generated code more readable (implies--comment,--readable-ids, and--no-line-directives). -
--compat: Increase compatibility withocamlyacc. This makescpspggenerate a shim of theParsingmodule from OCaml's standard library.
cpspg can be included in the Dune build process by adding the following to the dune file:
(rule
(deps Parser.mly)
(targets Parser.ml Parser.mli)
(action
(chdir %{workspace_root} (run cpspg %{deps} %{targets}))))This rule generates the files Parser.ml and Parser.mli based on the Parser.mly file. Additional options (like --compat) can be added after the cpspg invocation. The chdir action ensures that cpspg reports correct filenames in errors.