Skip to content

Commit dc8e76b

Browse files
committed
review initial AST remove useless parametric type
1 parent 96ced8d commit dc8e76b

File tree

6 files changed

+46
-50
lines changed

6 files changed

+46
-50
lines changed

lang/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ the Rust compilation stage.
99
In the V0 the compilation is a direct style Parsec generation without any
1010
optimisations.
1111

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-
1812
#### Abstract syntax tree
1913

2014
```rust
@@ -37,10 +31,16 @@ pub enum ASTParsec {
3731

3832
#[derive(Clone, Debug, Eq, PartialEq)]
3933
pub struct ASTParsecRule {
40-
pub public: bool,
4134
pub name: String,
4235
pub input: String,
4336
pub returns: String,
4437
pub rule: Box<ASTParsec>,
4538
}
46-
```
39+
```
40+
41+
### V1
42+
43+
This version target an aggressive and an efficient parser compilation. For this
44+
purpose the compilation follows a traditional control ans data flow and was
45+
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)
46+

lang/v0/ast/src/syntax.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,37 @@
1515
*/
1616

1717
#[derive(Clone, Debug, Eq, PartialEq)]
18-
pub enum ASTParsec<I> {
18+
pub enum ASTParsec {
1919
PIdent(String),
2020
// Are these constructors required?
21-
PAtom(I),
22-
PAtoms(Vec<I>),
23-
PBind(String, Box<ASTParsec<I>>),
21+
PAtom(char),
22+
PAtoms(Vec<char>),
23+
PBind(String, Box<ASTParsec>),
2424
// --------------------------------
2525
PCode(String),
26-
PMap(Box<ASTParsec<I>>, String),
27-
PSequence(Box<ASTParsec<I>>, Box<ASTParsec<I>>),
28-
PChoice(Box<ASTParsec<I>>, Box<ASTParsec<I>>),
29-
PNot(Box<ASTParsec<I>>),
30-
PTry(Box<ASTParsec<I>>),
31-
PCheck(Box<ASTParsec<I>>),
32-
POptional(Box<ASTParsec<I>>),
33-
PRepeat(bool, Box<ASTParsec<I>>),
34-
PLookahead(Box<ASTParsec<I>>),
26+
PMap(Box<ASTParsec>, String),
27+
PSequence(Box<ASTParsec>, Box<ASTParsec>),
28+
PChoice(Box<ASTParsec>, Box<ASTParsec>),
29+
PNot(Box<ASTParsec>),
30+
PTry(Box<ASTParsec>),
31+
PCheck(Box<ASTParsec>),
32+
POptional(Box<ASTParsec>),
33+
PRepeat(bool, Box<ASTParsec>),
34+
PLookahead(Box<ASTParsec>),
3535
}
3636

3737

3838

39-
impl<I> ASTParsec<I> {
39+
impl ASTParsec {
4040
pub fn wrap(self) -> Box<Self> {
4141
Box::new(self)
4242
}
4343
}
4444

4545
#[derive(Clone, Debug, Eq, PartialEq)]
46-
pub struct ASTParsecRule<I> {
46+
pub struct ASTParsecRule {
4747
pub name: String,
4848
pub input: String,
4949
pub returns: String,
50-
pub rule: ASTParsec<I>,
50+
pub rule: ASTParsec,
5151
}

lang/v0/parser/src/parser.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ where
7676
// -------------------------------------------------------------------------------------------------
7777

7878
#[inline]
79-
fn parsec_rules<'a, S>(
80-
) -> impl Parse<Vec<ASTParsecRule<char>>, S> + Combine<Vec<ASTParsecRule<char>>> + 'a
79+
fn parsec_rules<'a, S>() -> impl Parse<Vec<ASTParsecRule>, S> + Combine<Vec<ASTParsecRule>> + 'a
8180
where
8281
S: Stream<Item = char> + 'a,
8382
{
@@ -96,13 +95,11 @@ where
9695
.and(parsec())
9796
.and_left(skip())
9897
.map(
99-
|(((n, i), r), b): (((String, Option<String>), String), ASTParsec<char>)| {
100-
ASTParsecRule {
101-
name: n,
102-
input: i.unwrap_or(String::from("char")),
103-
returns: r,
104-
rule: b,
105-
}
98+
|(((n, i), r), b): (((String, Option<String>), String), ASTParsec)| ASTParsecRule {
99+
name: n,
100+
input: i.unwrap_or(String::from("char")),
101+
returns: r,
102+
rule: b,
106103
},
107104
)
108105
.rep()
@@ -111,7 +108,7 @@ where
111108
// -------------------------------------------------------------------------------------------------
112109

113110
#[inline]
114-
fn parsec<'a, S>() -> impl Parse<ASTParsec<char>, S> + Combine<ASTParsec<char>> + 'a
111+
fn parsec<'a, S>() -> impl Parse<ASTParsec, S> + Combine<ASTParsec> + 'a
115112
where
116113
S: Stream<Item = char> + 'a,
117114
{
@@ -179,8 +176,7 @@ where
179176
char_in_set(vec!['+', '?', '*'])
180177
}
181178

182-
fn additional<'a, S>(
183-
) -> impl Parse<(bool, ASTParsec<char>), S> + Combine<(bool, ASTParsec<char>)> + 'a
179+
fn additional<'a, S>() -> impl Parse<(bool, ASTParsec), S> + Combine<(bool, ASTParsec)> + 'a
184180
where
185181
S: Stream<Item = char> + 'a,
186182
{
@@ -192,7 +188,7 @@ where
192188
}
193189

194190
#[inline]
195-
fn atom<'a, S>() -> impl Parse<ASTParsec<char>, S> + Combine<ASTParsec<char>> + 'a
191+
fn atom<'a, S>() -> impl Parse<ASTParsec, S> + Combine<ASTParsec> + 'a
196192
where
197193
S: Stream<Item = char> + 'a,
198194
{
@@ -216,7 +212,7 @@ where
216212
}
217213

218214
#[inline]
219-
fn atom2<'a, S>() -> impl Parse<ASTParsec<char>, S> + Combine<ASTParsec<char>> + 'a
215+
fn atom2<'a, S>() -> impl Parse<ASTParsec, S> + Combine<ASTParsec> + 'a
220216
where
221217
S: Stream<Item = char> + 'a,
222218
{
@@ -225,10 +221,10 @@ where
225221
.and_right(lazy(|| parser(parsec())))
226222
.and_left(skip())
227223
.and_left(a_char(')'))
228-
.or(code().map(PCode))
229-
.or(delimited_char().map(PAtom))
230-
.or(delimited_string().map(|l| PAtoms(l.chars().collect())))
231-
.or(ident().map(PIdent))
224+
.or(code().map(PCode))
225+
.or(delimited_char().map(PAtom))
226+
.or(delimited_string().map(|l| PAtoms(l.chars().collect())))
227+
.or(ident().map(PIdent))
232228
}
233229

234230
#[inline]
@@ -261,15 +257,15 @@ where
261257

262258
// -------------------------------------------------------------------------------------------------
263259

264-
pub fn celma_parsec<'a, S>() -> impl Parse<ASTParsec<char>, S> + Combine<ASTParsec<char>> + 'a
260+
pub fn celma_parsec<'a, S>() -> impl Parse<ASTParsec, S> + Combine<ASTParsec> + 'a
265261
where
266262
S: Stream<Item = char> + 'a,
267263
{
268264
skip().and_right(parsec()).and_left(skip()).and_left(eos())
269265
}
270266

271267
pub fn celma_parsec_rules<'a, S>(
272-
) -> impl Parse<Vec<ASTParsecRule<char>>, S> + Combine<Vec<ASTParsecRule<char>>> + 'a
268+
) -> impl Parse<Vec<ASTParsecRule>, S> + Combine<Vec<ASTParsecRule>> + 'a
273269
where
274270
S: Stream<Item = char> + 'a,
275271
{

lang/v0/parser/src/transpiler.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub trait Transpile<E> {
2929
fn transpile(&self) -> Result<E, Error>;
3030
}
3131

32-
impl Transpile<TokenStream> for Vec<ASTParsecRule<char>> {
32+
impl Transpile<TokenStream> for Vec<ASTParsecRule> {
3333
fn transpile(&self) -> Result<TokenStream, Error> {
3434
let parsers: TokenStream = self
3535
.iter()
@@ -42,7 +42,7 @@ impl Transpile<TokenStream> for Vec<ASTParsecRule<char>> {
4242
}
4343
}
4444

45-
impl Transpile<TokenStream> for ASTParsecRule<char> {
45+
impl Transpile<TokenStream> for ASTParsecRule {
4646
fn transpile(&self) -> Result<TokenStream, Error> {
4747
let Self {
4848
name,
@@ -80,7 +80,7 @@ impl Transpile<TokenStream> for ASTParsecRule<char> {
8080
}
8181
}
8282

83-
impl Transpile<TokenStream> for ASTParsec<char> {
83+
impl Transpile<TokenStream> for ASTParsec {
8484
fn transpile(&self) -> Result<TokenStream, Error> {
8585
let body = self.transpile_body()?.1;
8686

@@ -106,7 +106,7 @@ pub trait TranspileBody<E> {
106106
fn transpile_body(&self) -> Result<E, Error>;
107107
}
108108

109-
impl TranspileBody<(Option<String>, TokenStream)> for ASTParsec<char> {
109+
impl TranspileBody<(Option<String>, TokenStream)> for ASTParsec {
110110
fn transpile_body(&self) -> Result<(Option<String>, TokenStream), Error> {
111111
match self {
112112
PBind(n, p) => Ok((Some(n.clone()), p.transpile_body()?.1)),

lang/v1/parser/src/first.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
use crate::token::Token::{AllAtom, Atom};
1818
use crate::token::{First, Token};
19-
use celma_lang_v0_ast::syntax::ASTParsec;
19+
use celma_lang_v1_ast::syntax::ASTParsec;
2020

2121
impl<E> First<E> for ASTParsec<E>
2222
where

lang/v1/parser/tests/first_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#[cfg(test)]
1818
mod tests {
19-
use celma_lang_v0_ast::syntax::ASTParsec::{PAtom, PIdent};
19+
use celma_lang_v1_ast::syntax::ASTParsec::{PAtom, PIdent};
2020
use celma_lang_v1::token::First;
2121
use celma_lang_v1::token::Token::{AllAtom, Atom};
2222

0 commit comments

Comments
 (0)