Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ grammar and lexing definitions). First we need to create a file `build.rs` in
the root of our project with the following content:

```rust
use cfgrammar::yacc::YaccKind;
use lrlex::CTLexerBuilder;

fn main() {
CTLexerBuilder::new()
.lrpar_config(|ctp| {
ctp.yacckind(YaccKind::Grmtools)
.grammar_in_src_dir("calc.y")
ctp.grammar_in_src_dir("calc.y")
.unwrap()
})
.lexer_in_src_dir("calc.l")
Expand All @@ -48,6 +46,7 @@ lexer can be found in `src/calc.l`:
and where the definitions for the parser can be found in `src/calc.y`:

```rust
%grmtools{yacckind Grmtools}
%start Expr
%avoid_insert "INT"
%%
Expand Down
5 changes: 3 additions & 2 deletions doc/src/errorrecovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ make use of error recovery.
A simple calculator grammar looks as follows:

```rust,noplaypen
%grmtools{yacckind Grmtools}
%start Expr
%%
Expr -> u64:
Expand Down Expand Up @@ -181,6 +182,7 @@ We thus change the grammar so that inserted integers prevent evaluation from
occurring:

```rust,noplaypen
%grmtools{yacckind Grmtools}
%start Expr
%%
Expr -> Result<u64, ()>:
Expand Down Expand Up @@ -539,8 +541,7 @@ the first parsing error, with the `recoverer` method in `CTParserBuilder` or
```rust,noplaypen
CTLexerBuilder::new()
.lrpar_config(|ctp| {
ctp.yacckind(YaccKind::Grmtools)
.recoverer(lrpar::RecoveryKind::None)
ctp.recoverer(lrpar::RecoveryKind::None)
.grammar_in_src_dir("calc.y")
.unwrap()
})
Expand Down
2 changes: 0 additions & 2 deletions doc/src/manuallexer.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ Putting these together is then relatively easy. First a `build.rs` file for a
hand-written lexer will look roughly as follows:

```rust
use cfgrammar::yacc::YaccKind;
use lrlex::{ct_token_map, DefaultLexerTypes};
use lrpar::CTParserBuilder;

fn main() {
let ctp = CTParserBuilder::<DefaultLexerTypes<u8>>::new()
.yacckind(YaccKind::Grmtools)
.grammar_in_src_dir("grammar.y")
.unwrap()
.build()
Expand Down
5 changes: 2 additions & 3 deletions doc/src/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ file inside the root of our project which can process the lexer and grammar.
Our `build.rs` file thus looks as follows:

```rust,noplaypen
use cfgrammar::yacc::YaccKind;
use lrlex::CTLexerBuilder;

fn main() {
CTLexerBuilder::new()
.lrpar_config(|ctp| {
ctp.yacckind(YaccKind::Grmtools)
.grammar_in_src_dir("calc.y")
ctp.grammar_in_src_dir("calc.y")
.unwrap()
})
.lexer_in_src_dir("calc.l")
Expand Down Expand Up @@ -103,6 +101,7 @@ is lexed, but no lexemes are created from it.

Our initial version of calc.y looks as follows:
```rust,noplaypen
%grmtools{yacckind Grmtools}
%start Expr
%%
Expr -> Result<u64, ()>:
Expand Down
2 changes: 0 additions & 2 deletions lrlex/examples/calc_manual_lex/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use cfgrammar::yacc::YaccKind;
use lrlex::{ct_token_map, DefaultLexerTypes};
use lrpar::CTParserBuilder;

Expand All @@ -13,7 +12,6 @@ const TOKENS_MAP: &[(&str, &str)] = &[

fn main() {
let ctp = CTParserBuilder::<DefaultLexerTypes<u8>>::new()
.yacckind(YaccKind::Grmtools)
.grammar_in_src_dir("calc.y")
.unwrap()
.build()
Expand Down
1 change: 1 addition & 0 deletions lrlex/examples/calc_manual_lex/src/calc.y
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
%grmtools{yacckind Grmtools}
%start Expr
%avoid_insert "INT"
%expect-unused Unmatched "UNMATCHED"
Expand Down
4 changes: 1 addition & 3 deletions lrpar/examples/calc_actions/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![deny(rust_2018_idioms)]
use cfgrammar::yacc::YaccKind;
use lrlex::CTLexerBuilder;

fn main() {
Expand All @@ -8,8 +7,7 @@ fn main() {
CTLexerBuilder::new()
.rust_edition(lrlex::RustEdition::Rust2021)
.lrpar_config(|ctp| {
ctp.yacckind(YaccKind::Grmtools)
.rust_edition(lrpar::RustEdition::Rust2021)
ctp.rust_edition(lrpar::RustEdition::Rust2021)
.grammar_in_src_dir("calc.y")
.unwrap()
})
Expand Down
4 changes: 1 addition & 3 deletions lrpar/examples/calc_actions/src/calc.y
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
%grmtools {
yacckind Grmtools
}
%grmtools {yacckind Grmtools}
%start Expr
%avoid_insert "INT"
%%
Expand Down
4 changes: 1 addition & 3 deletions lrpar/examples/calc_ast/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![deny(rust_2018_idioms)]
use cfgrammar::yacc::YaccKind;
use lrlex::CTLexerBuilder;

fn main() {
Expand All @@ -8,8 +7,7 @@ fn main() {
CTLexerBuilder::new()
.rust_edition(lrlex::RustEdition::Rust2021)
.lrpar_config(|ctp| {
ctp.yacckind(YaccKind::Grmtools)
.rust_edition(lrpar::RustEdition::Rust2021)
ctp.rust_edition(lrpar::RustEdition::Rust2021)
.grammar_in_src_dir("calc.y")
.unwrap()
})
Expand Down
1 change: 1 addition & 0 deletions lrpar/examples/calc_ast/src/calc.y
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
%grmtools {yacckind Grmtools}
%start Expr
%avoid_insert "INT"
%expect-unused Unmatched "UNMATCHED"
Expand Down
4 changes: 1 addition & 3 deletions lrpar/examples/calc_parsetree/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use cfgrammar::yacc::{YaccKind, YaccOriginalActionKind};
use lrlex::CTLexerBuilder;

fn main() {
Expand All @@ -7,8 +6,7 @@ fn main() {
CTLexerBuilder::new()
.rust_edition(lrlex::RustEdition::Rust2021)
.lrpar_config(|ctp| {
ctp.yacckind(YaccKind::Original(YaccOriginalActionKind::GenericParseTree))
.rust_edition(lrpar::RustEdition::Rust2021)
ctp.rust_edition(lrpar::RustEdition::Rust2021)
.grammar_in_src_dir("calc.y")
.unwrap()
})
Expand Down
4 changes: 1 addition & 3 deletions lrpar/examples/clone_param/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![deny(rust_2018_idioms)]
use cfgrammar::yacc::YaccKind;
use lrlex::CTLexerBuilder;

fn main() {
Expand All @@ -8,8 +7,7 @@ fn main() {
CTLexerBuilder::new()
.rust_edition(lrlex::RustEdition::Rust2021)
.lrpar_config(|ctp| {
ctp.yacckind(YaccKind::Grmtools)
.rust_edition(lrpar::RustEdition::Rust2021)
ctp.rust_edition(lrpar::RustEdition::Rust2021)
.grammar_in_src_dir("param.y")
.unwrap()
})
Expand Down
1 change: 1 addition & 0 deletions lrpar/examples/clone_param/src/param.y
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
%grmtools {yacckind Grmtools}
%token Incr Decr
%parse-param val: Rc<RefCell<i64>>
%%
Expand Down
4 changes: 1 addition & 3 deletions lrpar/examples/start_states/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use cfgrammar::yacc::{YaccKind, YaccOriginalActionKind};
use lrlex::CTLexerBuilder;

fn main() {
Expand All @@ -7,8 +6,7 @@ fn main() {
CTLexerBuilder::new()
.rust_edition(lrlex::RustEdition::Rust2021)
.lrpar_config(|ctp| {
ctp.yacckind(YaccKind::Original(YaccOriginalActionKind::GenericParseTree))
.rust_edition(lrpar::RustEdition::Rust2021)
ctp.rust_edition(lrpar::RustEdition::Rust2021)
.grammar_in_src_dir("comment.y")
.unwrap()
})
Expand Down
3 changes: 2 additions & 1 deletion lrpar/examples/start_states/src/comment.y
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
%grmtools{yacckind Original(GenericParseTree)}
%start Expr
%%
Expr: Expr Text | ;

Text: 'TEXT';
Text: 'TEXT';