Skip to content

Commit 83de568

Browse files
committed
Minor type and transformation sketches
1 parent 2a4dc64 commit 83de568

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ occurrence = ("*" | "+" | "?")
2929
additional = "|" ? parser
3030
transform = "->" '{' rust_code '}'
3131
atom = alter? '(' parser? ')' | CHAR | STRING | ident
32-
alter = ("^" | "!" | "#" | "/")
32+
alter = ("^" | "!" | "#")
3333
ident = [a..zA..Z][a..zA..Z0..9_] * - {"let"}
3434
```
3535

@@ -185,8 +185,8 @@ let stream = ParserStream::new( & tokenizer, CharStream::new("1 + 2"));
185185
let response = expr().and_left(eos()).parse(stream);
186186

187187
match response {
188-
Success(v, _, _) => assert_eq!(v.eval(), 3),
189-
_ => assert_eq!(true, false),
188+
Success(v, _, _) => assert_eq!(v.eval(), 3),
189+
_ => assert_eq!(true, false),
190190
}
191191
```
192192

lang/v1/normalizer/src/ast.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,32 @@ pub enum ASTGrammar<A> {
2020
Bottom(),
2121
Var(String),
2222
Token(A),
23-
TokenChar(char),
2423
Seq(Box<AST<A>>, Box<AST<A>>),
2524
Choice(Box<AST<A>>, Box<AST<A>>),
2625
Rec(String, Box<AST<A>>),
26+
// Extension for capture and transformation
27+
Bind(String, Box<AST<A>>),
28+
Map(Box<AST<A>>, String),
29+
// Negation for alternate paths
30+
Not(Box<AST<A>>),
2731
}
2832

2933
/*
30-
PBind(String, Box<ASTParsec>), // Variable
31-
PMap(Box<ASTParsec>, String), // Map
32-
PNot(Box<ASTParsec>), // Negation
33-
34-
-- Pre-normalization
35-
34+
PN : ASTParsec -> (string -> ASTParsec) -> string list -> ASTGrammar
3635
PN : ASTParsec -> (string -> ASTParsec) -> string list -> ASTGrammar
3736
38-
/ Var(n) if n in l
39-
PN[PIdent(n)]gl = {
40-
\ mu(n,PN[g(n)]g(n::l) otherwise
41-
37+
PN[PIdent(n)]gl = Var(n) if n in l
38+
| mu(n,PN[g(n)]g(n::l) otherwise
4239
PN[PAtom(c)]gl = TokenChar(c)
4340
PN[PAtoms([])]gl = Epsilon()
44-
PN[PAtoms(c::l)]gl = Seq(TokenChar(v),PN[PAtoms(c::l)]gl)
41+
PN[PAtoms(c::l)]gl = Seq(Token(v),PN[PAtoms(c::l)]gl)
4542
PN[PEpsilon()]gl = Epsilon()
4643
PN[PSequence(T1,T2]]gl = Seq(PN[T1]gl,PN[T2]gl)
4744
PN[PChoice(T1,T2)]gl = Choice(PN[T1]gl,PN[T2]gl)
48-
PN[PRepeat(T)]gl = PN[T]gl | mu(n,Choice(Seq(PN[T]gl,Var(n)),Epsilon()))
45+
PN[PRepeat(T)]gl = PN[T]gl|mu(n,Choice(Seq(PN[T]gl,Var(n)),Epsilon())) - fresh n not in l
4946
PN[PTry(T)gl] = PN[T]gl
50-
PN[PCheck(T]gl] = PN[T]gl
47+
PN[PCheck(T)gl] = PN[T]gl
48+
PN[PBind(s,T)]gl = Bind(s,PN[T]gl)
49+
PN[PMap(T,s)]gl = Map(PN[T]gl,s)
50+
PN[PNot(T)]gl = Not(PN[T]gl)
5151
*/

lang/v1/normalizer/src/dgnf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ Normalization of well-typed context-free expressions.
2727
(seq) N 𝑔1·𝑔2 = 𝑛⇒{𝑛→𝑁1 𝑛2 |𝑛1 →𝑁1 ∈𝐺1 }∪𝐺1 ∪𝐺2
2828
where N 𝑔1 = 𝑛1 ⇒𝐺1 ∧N 𝑔2 = 𝑛2 ⇒𝐺2
2929
(alt) N 𝑔1∨𝑔2 = 𝑛⇒{𝑛→𝑁1 |𝑛1 →𝑁1 ∈𝐺1 }∪{𝑛→𝑁2 |𝑛2 →𝑁2 ∈𝐺2 }∪𝐺1 ∪𝐺2
30-
where N 𝑔1 = 𝑛1 ⇒𝐺1 ∧N 𝑔2 = 𝑛2 ⇒𝐺2
30+
where N 𝑔1 = 𝑛1 ⇒𝐺1 ∧N 𝑔2 = 𝑛2 ⇒𝐺2
3131
(fix) N 𝜇𝛼.𝑔 = 𝛼 ⇒{𝛼 →𝑁 |𝑛→𝑁 ∈𝐺} (1)
3232
∪{𝑛′→𝑁 𝑛′|𝑛′→𝛼𝑛′∈𝐺∧𝑛→𝑁 ∈𝐺} (2)
3333
∪𝐺\𝑛′→𝛼 𝑛′ (3)
34-
where N 𝑔= 𝑛⇒𝐺
34+
where N 𝑔= 𝑛⇒𝐺
3535
𝐺\𝑛′→𝛼 𝑛′ is 𝐺 with all 𝑛′→𝛼𝑛′removed for any 𝑛′and 𝑛′
3636
(var) N 𝛼 = 𝑛⇒{𝑛→𝛼}
3737

0 commit comments

Comments
 (0)