full program basic parsing
This commit is contained in:
parent
4738ad92bf
commit
5c2c9a4600
4 changed files with 223 additions and 4 deletions
|
|
@ -28,7 +28,7 @@ let draw = fn(frame, state) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let migrate = fn(state) {
|
let migrate = fn(state) {
|
||||||
return { player: { pos: state.player.position } },
|
return { player: { pos: state.player.position } };
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -399,7 +399,7 @@ let draw = fn(frame, state) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let migrate = fn(state) {
|
let migrate = fn(state) {
|
||||||
return { player: { pos: state.player.position } },
|
return { player: { pos: state.player.position } };
|
||||||
};
|
};
|
||||||
"
|
"
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,217 @@
|
||||||
|
---
|
||||||
|
source: src/parser/parser.rs
|
||||||
|
expression: result
|
||||||
|
---
|
||||||
|
Ok(
|
||||||
|
[
|
||||||
|
Definition {
|
||||||
|
name: Name(
|
||||||
|
"init",
|
||||||
|
),
|
||||||
|
expr: Func(
|
||||||
|
Fn {
|
||||||
|
args: [],
|
||||||
|
body: Block(
|
||||||
|
[
|
||||||
|
Return(
|
||||||
|
Some(
|
||||||
|
Value(
|
||||||
|
Record(
|
||||||
|
Record(
|
||||||
|
{
|
||||||
|
Label(
|
||||||
|
"player",
|
||||||
|
): Value(
|
||||||
|
Record(
|
||||||
|
Record(
|
||||||
|
{
|
||||||
|
Label(
|
||||||
|
"position",
|
||||||
|
): Value(
|
||||||
|
Record(
|
||||||
|
Record(
|
||||||
|
{
|
||||||
|
Label(
|
||||||
|
"x",
|
||||||
|
): Value(
|
||||||
|
Int(
|
||||||
|
10,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Label(
|
||||||
|
"y",
|
||||||
|
): Value(
|
||||||
|
Int(
|
||||||
|
20,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
Definition {
|
||||||
|
name: Name(
|
||||||
|
"update",
|
||||||
|
),
|
||||||
|
expr: Func(
|
||||||
|
Fn {
|
||||||
|
args: [
|
||||||
|
Arg {
|
||||||
|
name: Name(
|
||||||
|
"state",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
Arg {
|
||||||
|
name: Name(
|
||||||
|
"events",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
body: Block(
|
||||||
|
[
|
||||||
|
Return(
|
||||||
|
Some(
|
||||||
|
Var(
|
||||||
|
Name(
|
||||||
|
"state2",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
Definition {
|
||||||
|
name: Name(
|
||||||
|
"draw",
|
||||||
|
),
|
||||||
|
expr: Func(
|
||||||
|
Fn {
|
||||||
|
args: [
|
||||||
|
Arg {
|
||||||
|
name: Name(
|
||||||
|
"frame",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
Arg {
|
||||||
|
name: Name(
|
||||||
|
"state",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
body: Block(
|
||||||
|
[
|
||||||
|
Expr(
|
||||||
|
FunCall {
|
||||||
|
func: Access {
|
||||||
|
expr: Var(
|
||||||
|
Name(
|
||||||
|
"frame",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
field: Label(
|
||||||
|
"clear",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
args: [
|
||||||
|
Value(
|
||||||
|
Int(
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Value(
|
||||||
|
Int(
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Value(
|
||||||
|
Int(
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
Definition {
|
||||||
|
name: Name(
|
||||||
|
"migrate",
|
||||||
|
),
|
||||||
|
expr: Func(
|
||||||
|
Fn {
|
||||||
|
args: [
|
||||||
|
Arg {
|
||||||
|
name: Name(
|
||||||
|
"state",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
body: Block(
|
||||||
|
[
|
||||||
|
Return(
|
||||||
|
Some(
|
||||||
|
Value(
|
||||||
|
Record(
|
||||||
|
Record(
|
||||||
|
{
|
||||||
|
Label(
|
||||||
|
"player",
|
||||||
|
): Value(
|
||||||
|
Record(
|
||||||
|
Record(
|
||||||
|
{
|
||||||
|
Label(
|
||||||
|
"pos",
|
||||||
|
): Access {
|
||||||
|
expr: Access {
|
||||||
|
expr: Var(
|
||||||
|
Name(
|
||||||
|
"state",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
field: Label(
|
||||||
|
"player",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
field: Label(
|
||||||
|
"position",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
@ -33,6 +33,7 @@ pub struct Tokens(pub Vec<LocatedToken>);
|
||||||
|
|
||||||
impl From<Vec<LocatedToken>> for Tokens {
|
impl From<Vec<LocatedToken>> for Tokens {
|
||||||
fn from(mut tokens: Vec<LocatedToken>) -> Tokens {
|
fn from(mut tokens: Vec<LocatedToken>) -> Tokens {
|
||||||
|
// println!("{tokens:#?}");
|
||||||
tokens.reverse();
|
tokens.reverse();
|
||||||
Tokens(tokens)
|
Tokens(tokens)
|
||||||
}
|
}
|
||||||
|
|
@ -60,14 +61,15 @@ impl Tokens {
|
||||||
if let Some(_end) = self.next_if(end) {
|
if let Some(_end) = self.next_if(end) {
|
||||||
Ok(Some(result))
|
Ok(Some(result))
|
||||||
} else {
|
} else {
|
||||||
|
// println!("{:#?}", self);
|
||||||
Err(Error::UnexpectedTokenForParser(
|
Err(Error::UnexpectedTokenForParser(
|
||||||
"between".into(),
|
format!("between end {start:#?} and {end:#?}"),
|
||||||
self.next(),
|
self.next(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(Error::UnexpectedTokenForParser(
|
Err(Error::UnexpectedTokenForParser(
|
||||||
"between".into(),
|
"between parser".into(),
|
||||||
self.next(),
|
self.next(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue