|
12 | 12 | #![deny(rustdoc::private_intra_doc_links)] |
13 | 13 | #![deny(rustdoc::private_doc_tests)] |
14 | 14 | //! Santiago is a lexing and parsing toolkit for Rust. |
15 | | -//! It provides a library for defining any |
16 | | -//! [context-free grammar](https://en.wikipedia.org/wiki/Context-free_grammar), |
17 | | -//! a [lexical analysis](https://en.wikipedia.org/wiki/Lexical_analysis) module, |
18 | | -//! and facilities for building evaluators of the language. |
| 15 | +//! It provides you: |
| 16 | +//! - A library for defining any |
| 17 | +//! [context-free grammar](https://en.wikipedia.org/wiki/Context-free_grammar), |
| 18 | +//! - A [Lexical analysis](https://en.wikipedia.org/wiki/Lexical_analysis) module, |
| 19 | +//! - And facilities for building interpreters or compilers of the language. |
19 | 20 | //! |
20 | | -//! With Santiago, you have everything you need to build your own programming |
21 | | -//! language, and a compiler or interpreter for it. |
| 21 | +//! With Santiago you have everything that is needed |
| 22 | +//! to build your own programming language! |
22 | 23 | //! |
23 | | -//! Santiago aims to be the Rust alternative to |
| 24 | +//! We are the Rust alternative to |
24 | 25 | //! [GNU Bison](https://en.wikipedia.org/wiki/GNU_Bison), |
25 | 26 | //! [Yacc](https://en.wikipedia.org/wiki/Yacc) and |
26 | 27 | //! [Flex](https://en.wikipedia.org/wiki/Flex_(lexical_analyser_generator)). |
|
118 | 119 | //! let parse_trees = santiago::parser::parse(&grammar, &lexemes).unwrap(); |
119 | 120 | //! ``` |
120 | 121 | //! |
121 | | -//! And voilà! |
| 122 | +//! Which looks like: |
122 | 123 | //! ```text |
123 | 124 | #![doc = include_str!("../tests/ambiguous_integer_addition/cases/addition/parse_trees")] |
124 | 125 | //! ``` |
|
162 | 163 | #![doc = include_str!("../tests/integer_addition/cases/addition/parse_trees")] |
163 | 164 | //! ``` |
164 | 165 | //! |
165 | | -//! All we are missing now is evaluating the addition, |
166 | | -//! for this let's modify the grammar |
| 166 | +//! All we are missing now is evaluating the addition. |
| 167 | +//! For this let's modify the grammar |
167 | 168 | //! so that each time a rule matches |
168 | | -//! we produce an amenable data-structure: |
| 169 | +//! we produce an amenable data-structure |
| 170 | +//! that can be turned into an Abstract Syntax Tree: |
169 | 171 | //! ```rust |
170 | 172 | #![doc = include_str!("../tests/integer_addition_with_value/grammar.rs")] |
171 | 173 | //! ``` |
172 | 174 | //! |
173 | | -//! We just need to call Santiago's builtin-function `as_abstract_syntax_tree()`. |
| 175 | +//! Now, the next time we parse, |
| 176 | +//! we can transform our Parse Tree into |
| 177 | +//! an Abstract Syntax Tree |
| 178 | +//! by calling Santiago's builtin-function `as_abstract_syntax_tree()`. |
174 | 179 | //! ```rust |
175 | 180 | //! # mod m { |
176 | 181 | //! # include!("../tests/integer_addition_with_value/eval.rs"); |
|
190 | 195 | //! let ast = parse_tree.as_abstract_syntax_tree(); |
191 | 196 | //! |
192 | 197 | //! assert_eq!( |
193 | | -//! value, |
| 198 | +//! ast, |
194 | 199 | //! BinaryOperation(vec![ |
195 | 200 | //! BinaryOperation(vec![ |
196 | 201 | //! Int(10), |
|
232 | 237 | //! # |
233 | 238 | //! let ast = parse_tree.as_abstract_syntax_tree(); |
234 | 239 | //! |
235 | | -//! assert_eq!(eval(&value), 60); |
| 240 | +//! assert_eq!(eval(&ast), 60); |
236 | 241 | //! ``` |
237 | 242 | //! |
238 | 243 | //! How nice is that? |
|
439 | 444 | //! |
440 | 445 | //! let ast = parse_tree.as_abstract_syntax_tree(); |
441 | 446 | //! |
442 | | -//! assert_eq!(eval(&value), -6); |
| 447 | +//! assert_eq!(eval(&ast), -6); |
443 | 448 | //! ``` |
444 | 449 | //! |
445 | 450 | //! ## JavaScript string interpolations |
|
0 commit comments