Skip to content

Commit 631f4ad

Browse files
committed
Minor doc and code review
1 parent 316f0f8 commit 631f4ad

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,11 @@ optimisations cf. [celma parser in direct style](https://github.com/d-plaindoux/
200200

201201
This version target an aggressive and an efficient parser compilation. For this
202202
purpose the compilation follows a traditional control and data flow mainly inspired
203-
by the paper [A Typed, Algebraic Approach to Parsing](https://www.cl.cam.ac.uk/~jdy22/papers/a-typed-algebraic-approach-to-parsing.pdf).
203+
by the papers like [A Typed, Algebraic Approach to Parsing](https://www.cl.cam.ac.uk/~jdy22/papers/a-typed-algebraic-approach-to-parsing.pdf)
204+
and [Fusing Lexing and Parsing](https://www.cl.cam.ac.uk/~jdy22/papers/fusing-lexing-and-parsing.pdf).
204205

205206
First, we express [Celma in Celma](https://github.com/d-plaindoux/celma/blob/master/lang/v1/parser/src/parser.rs).
206-
This gives us an AST denoting parsers expressed using the Celma language.
207+
This gives us an AST denoting parsers expressed using the Celma language i.e. Celma(v1) thanks to Celma(v0).
207208

208209
### Type checking
209210

lang/v0/macro/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ edition = "2021"
88
proc-macro = true
99

1010
[dependencies]
11+
syn = "2.0.98"
1112
celma_v0_core = { version = "0.1.0", path = "../core" }
1213
celma_v0_parser = { version = "0.1.0", path = "../parser" }
14+
proc-macro2 = "1.0.93"
1315

1416
[dev-dependencies]
1517
bencher = "0.1.5"

lang/v0/macro/src/lib.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,38 @@
1616

1717
extern crate proc_macro;
1818

19+
use celma_v0_core::parser::response::Response;
1920
use celma_v0_core::parser::response::Response::{Reject, Success};
2021
use celma_v0_core::parser::specs::Parse;
2122
use celma_v0_core::stream::char_stream::CharStream;
2223
use celma_v0_core::stream::specs::Stream;
2324
use celma_v0_parser::parser::{celma_parsec, celma_parsec_rules};
2425
use celma_v0_parser::transpiler::Transpile;
25-
use proc_macro::TokenStream;
26+
use syn::Error;
2627

2728
#[proc_macro]
28-
pub fn parsec(input: TokenStream) -> TokenStream {
29+
pub fn parsec(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
2930
let source = input.to_string();
3031
let result = celma_parsec()
3132
.parse(CharStream::new(source.as_str()))
3233
.map(|ast| ast.transpile());
3334

34-
match result {
35-
Success(code, _, _) => match code {
36-
Ok(code) => code.into(),
37-
Err(err) => panic!("{}", err.into_compile_error()),
38-
},
39-
Reject(s, _) => panic!("Parse error at {:?}", s.position()),
40-
}
35+
conclude_parsing(result)
4136
}
4237

4338
#[proc_macro]
44-
pub fn parsec_rules(input: TokenStream) -> TokenStream {
39+
pub fn parsec_rules(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
4540
let source = input.to_string();
4641
let result = celma_parsec_rules()
4742
.parse(CharStream::new(source.as_str()))
4843
.map(|ast| ast.transpile());
4944

45+
conclude_parsing(result)
46+
}
47+
48+
fn conclude_parsing(
49+
result: Response<Result<proc_macro2::TokenStream, Error>, CharStream<(usize, usize, usize)>>,
50+
) -> proc_macro::TokenStream {
5051
match result {
5152
Success(code, _, _) => match code {
5253
Ok(code) => code.into(),

lang/v0/parser/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ authors = ["dplaindoux <[email protected]>"]
55
edition = "2021"
66

77
[dependencies]
8-
celma_v0_core = { version = "0.1.0", path = "../core" }
9-
celma_v0_ast = { version = "0.1.0", path = "../ast" }
10-
celma_v1_ast = { version = "0.1.0", path = "../../v1/ast" }
118
proc-macro2 = "1.0.93"
129
quote = "1.0.38"
1310
syn = "2.0.96"
11+
celma_v0_core = { version = "0.1.0", path = "../core" }
12+
celma_v0_ast = { version = "0.1.0", path = "../ast" }

0 commit comments

Comments
 (0)