Crates.io | prism-parser |
lib.rs | prism-parser |
version | 0.2.0 |
source | src |
created_at | 2024-06-14 09:27:34.765856 |
updated_at | 2024-08-18 10:31:43.27895 |
description | A PEG parsing library built for the Prism programming language |
homepage | |
repository | |
max_upload_size | |
id | 1271793 |
size | 232,329 |
Prism Parser
A PEG parsing library built for the Prism programming language
This crate provides a PEG parser with the following features:
This crate is under heavy development and not yet ready to be used in production code.
This defines the grammar of a simple arithmetic language, and support to adapt the language:
rule start = block;
rule block {
b <- "grammar" "{" g:grammar(prule_action) "}" ";" b:#adapt(g, block);
s :: b <- s:stmt ";" b:block;
[] <- "";
}
rule stmt {
Let(e) <- "let" e:expr;
Do() <- "do";
}
rule expr {
group additive {
Add(x, y) <- x:#next "+" y:#this;
}
group multiplicative {
Mul(x, y) <- x:#next "*" y:#this;
}
group base {
Block(b) <- "(" b:block ")";
UnaryMinus(v) <- "-" v:#this;
Num(n) <- n:#str([0-9]*);
}
}
rule layout = [' ' | '\n'];
Example programs in this language:
1 * 2 + -3
grammar {
rule expr {
group additive {
1 + (-2) <- x:#next "-" y:#this;
}
}
};
1 - 2