Skip to content
Snippets Groups Projects
Commit 48bad35a authored by Per Lindgren's avatar Per Lindgren
Browse files

readme

parent b33cc37d
Branches
No related tags found
No related merge requests found
......@@ -4,6 +4,31 @@ Disclaimer, I'm NOT the author of the `syn` and `nom` parsing frameworks, so no
The same goes for all references to supporting crates and references to other Rust libraries, crates and the language itself, so use material at own risk :)
## Build environment
In order to build custom parsers using `syn` you need to use a nightly compiler to build a library with the following set of dependencies and library definition in the `Cargo.toml`.
``` toml
[package]
name = "parsetest"
version = "0.1.0"
authors = ["Per Lindgren <per.lindgren@ltu.se>"]
[dependencies]
quote = "0.4.2"
[dependencies.syn]
version = "0.12.12"
features = ["full"]
[dependencies.proc-macro2]
features = ["nightly"]
version = "0.2.2"
[lib]
proc-macro = true
```
## Built in parsers
The `syn::parse` function allows to parse any struct that implements the `syn::synom::Synom` trait. The `syn` crate provides a large set of structs which satisfies this requirement, which we can use directly or for building parser combinators.
......@@ -213,6 +238,7 @@ The description here is the default error, provided by the built in `LitInt` par
The real strenght of the `syn` and `nom` frameworks comes from the ability to combine parsers. We will start by looking at the last error, assuming we want to parse something like `(LitInt)` into a plain `LitInt`.
``` rust
/// MyLit
struct MyLit {
val: LitInt,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment