- Install
ycc
# require rust nightly
cargo install ycc --force
or download from release and add to $PATH
.
- Written grammar definition file,
- Example: json5.ygg
- Run build command
ycc build
- Written grammar definition file,
- Example: json5.ygg
- Define build dependencies in cargo(require rust nightly)
[build-dependencies.yggdrasil-shared]
version = "0.2.3"
# git = "https://github.com/ygg-lang/yggdrasil.rs"
# branch = "dev"
- Write the
build.rs
- See: build.rs
- Run
cargo build
and reexport needed symbols
- See: lib.rs
- basic syntax
Name | Description |
---|---|
a? |
Optional element |
a* |
Zero or more elements |
a+ |
One or more elements |
a b |
Sequence of elements |
a | b |
Alternative of branch |
name:e |
Mark element with given name |
#Name |
Mark branch with given name |
^rule |
Remark element |
@macro() |
Macro call |
ANY |
Any unicode characters |
IGNORED |
All rules marked as ignored |
class
vsunion
The same syntax A | B
performs differently in class
and union
context.
// expand `A | B` as class
class TestA {
| tag_a:A
| tag_b:B
}
// expand `A | B` as union
union TestB {
| A #BranchA
| B #BranchB
}
struct TestA {
tag_a: A,
tag_b: B,
}
enum TestB {
BranchA(A),
BranchB(B),
}
- examples
You can learn more from project-yggdrasil.