Skip to content

Commit 40015bc

Browse files
committed
Review AST adding parametric atom type
1 parent 02b30ad commit 40015bc

File tree

26 files changed

+202
-174
lines changed

26 files changed

+202
-174
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
resolver = "2"
33
members = [
44
"core",
5+
"lang/ast",
56
"lang/v0/parser",
67
"lang/v0/macro",
78
"lang/v1/parser",

README.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Generalization is the capability to design a parser based on pipelined parsers a
1616
In order to have a seamless parser definition two dedicated `proc_macro` are designed:
1717

1818
```rust
19-
parsec_rules = ("private"? "let" ident ('{' rust_type '}')? ':' '{' rust_type '}' "=" parser)+
19+
parsec_rules = "let" ident ('{' rust_type '}')? ':' '{' rust_type '}' "=" parser)+
2020
parser = binding? atom occurrence? additional? transform?
2121
```
2222

@@ -25,7 +25,7 @@ binding = ident '='
2525
occurrence = ("*" | "+" | "?")
2626
additional = "|"? parser
2727
transform = "->" '{' rust_code '}'
28-
atom = alter? '(' parser ')' | CHAR | STRING | ident | '{' rust_code '}'
28+
atom = alter? '(' parser ')' | CHAR | STRING | ident
2929
alter = ("^"|"!"|"#"|"/")
3030
ident = [a..zA..Z][a..zA..Z0..9_]* - {"let"}
3131
```
@@ -182,16 +182,6 @@ match response {
182182
}
183183
```
184184

185-
## Bootstrap scenario
186-
187-
### Stage 1
188-
189-
The [Celma parser v0](https://github.com/d-plaindoux/celma/blob/master/lang/src/meta/parser.rs) is written with parser combinators
190-
191-
### Stage 2
192-
193-
The [Celma parser V1](https://github.com/d-plaindoux/celma/blob/master/bootstrap/src/bootstrap/parser.rs) is written using the Celma parser V0.
194-
195185
# License
196186

197187
Copyright 2019-2025 Didier Plaindoux.

core/examples/expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
use celma_core::parser::and::{AndOperation, AndProjection};
1818
use celma_core::parser::char::{a_char, alpha, char_in_set, digit, not_char};
1919
use celma_core::parser::core::{eos, parser};
20-
use celma_core::parser::map::MapOperation;
2120
use celma_core::parser::lazy::lazy;
21+
use celma_core::parser::map::MapOperation;
2222
use celma_core::parser::or::OrOperation;
2323
use celma_core::parser::repeat::RepeatOperation;
2424
use celma_core::parser::response::Response::Success;

core/src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ pub mod bind;
2020
pub mod char;
2121
pub mod check;
2222
pub mod core;
23-
pub mod map;
2423
pub mod lazy;
2524
pub mod literal;
2625
pub mod location;
2726
pub mod lookahead;
27+
pub mod map;
2828
pub mod not;
2929
pub mod option;
3030
pub mod or;

core/tests/parser/bind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ mod tests_monadic {
2020
use celma_core::parser::bind::BindOperation;
2121
use celma_core::parser::char::a_char;
2222
use celma_core::parser::core::eos;
23-
use celma_core::parser::map::MapOperation;
2423
use celma_core::parser::literal::string;
24+
use celma_core::parser::map::MapOperation;
2525
use celma_core::parser::repeat::RepeatOperation;
2626
use celma_core::parser::specs::Parse;
2727
use celma_core::stream::char_stream::CharStream;

core/tests/parser/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ mod tests_monadic {
2020
use celma_core::parser::bind::BindOperation;
2121
use celma_core::parser::char::a_char;
2222
use celma_core::parser::core::eos;
23-
use celma_core::parser::map::MapOperation;
2423
use celma_core::parser::literal::string;
24+
use celma_core::parser::map::MapOperation;
2525
use celma_core::parser::repeat::RepeatOperation;
2626
use celma_core::parser::specs::Parse;
2727
use celma_core::stream::char_stream::CharStream;

core/tests/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ pub mod bind;
2020
pub mod char;
2121
pub mod check;
2222
pub mod core;
23-
pub mod map;
2423
pub mod lazy;
2524
pub mod literal;
2625
pub mod location;
2726
pub mod lookahead;
27+
pub mod map;
2828
pub mod not;
2929
pub mod option;
3030
pub mod or;

core/tests/parser/not.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#[cfg(test)]
1818
mod tests_literal {
1919
use celma_core::parser::char::a_char;
20-
use celma_core::parser::map::MapOperation;
2120
use celma_core::parser::literal::string;
21+
use celma_core::parser::map::MapOperation;
2222
use celma_core::parser::not::NotOperation;
2323
use celma_core::parser::repeat::RepeatOperation;
2424
use celma_core::parser::specs::Parse;

lang/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## Celma Lang
2+
3+
Celma is a embedded language in Rust targeting simple parser construction.
4+
As already explained in the main README such language is processes during
5+
the Rust compilation stage.
6+
7+
### V0
8+
9+
In the V0 the compilation is a direct style Parsec generation without any
10+
optimisations.
11+
12+
### V1
13+
14+
This version target an aggressive and an efficient parser compilation. For this
15+
purpose the compilation follows a traditional control ans data flow and was
16+
mainly inspired by the paper [A Typed, Algebraic Approach to Parsing](https://www.cl.cam.ac.uk/~jdy22/papers/a-typed-algebraic-approach-to-parsing.pdf)
17+
18+
#### Abstract syntax tree
19+
20+
```rust
21+
#[derive(Clone, Debug, Eq, PartialEq)]
22+
pub enum ASTParsec {
23+
PIdent(String),
24+
PChar(char),
25+
PString(String),
26+
PBind(String, Box<ASTParsec>),
27+
PMap(Box<ASTParsec>, String),
28+
PSequence(Box<ASTParsec>, Box<ASTParsec>),
29+
PChoice(Box<ASTParsec>, Box<ASTParsec>),
30+
PNot(Box<ASTParsec>),
31+
PTry(Box<ASTParsec>),
32+
PCheck(Box<ASTParsec>),
33+
POptional(Box<ASTParsec>),
34+
PRepeat(bool, Box<ASTParsec>),
35+
PLookahead(Box<ASTParsec>),
36+
}
37+
38+
#[derive(Clone, Debug, Eq, PartialEq)]
39+
pub struct ASTParsecRule {
40+
pub public: bool,
41+
pub name: String,
42+
pub input: String,
43+
pub returns: String,
44+
pub rule: Box<ASTParsec>,
45+
}
46+
```

lang/ast/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "celma_lang_ast"
3+
version = "0.1.0"
4+
authors = ["dplaindoux <[email protected]>"]
5+
edition = "2021"
6+

0 commit comments

Comments
 (0)