include
This commit is contained in:
parent
bdf9816bda
commit
d7bcac6916
7 changed files with 48 additions and 19 deletions
|
|
@ -2,6 +2,22 @@
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
/// A Program.
|
||||||
|
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
||||||
|
pub struct Program {
|
||||||
|
pub defs: Vec<Definition>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
||||||
|
pub struct File(pub String);
|
||||||
|
|
||||||
|
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
||||||
|
pub struct Definition {
|
||||||
|
pub mutable: bool,
|
||||||
|
pub name: Name,
|
||||||
|
pub expr: Expr,
|
||||||
|
}
|
||||||
|
|
||||||
/// An expression.
|
/// An expression.
|
||||||
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
||||||
pub enum Expr {
|
pub enum Expr {
|
||||||
|
|
@ -77,13 +93,6 @@ pub enum Statement {
|
||||||
Break,
|
Break,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
|
||||||
pub struct Definition {
|
|
||||||
pub mutable: bool,
|
|
||||||
pub name: Name,
|
|
||||||
pub expr: Expr,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A reduced value.
|
/// A reduced value.
|
||||||
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
||||||
pub enum Value {
|
pub enum Value {
|
||||||
|
|
@ -136,10 +145,6 @@ pub struct Record(pub BTreeMap<Label, Ref>);
|
||||||
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
||||||
pub struct Vector(pub Vec<Ref>);
|
pub struct Vector(pub Vec<Ref>);
|
||||||
|
|
||||||
/// A Program.
|
|
||||||
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
|
||||||
pub struct Program(pub Vec<Definition>);
|
|
||||||
|
|
||||||
// ----- //
|
// ----- //
|
||||||
// Impls //
|
// Impls //
|
||||||
// ----- //
|
// ----- //
|
||||||
|
|
@ -225,7 +230,7 @@ impl From<bool> for Expr {
|
||||||
|
|
||||||
impl From<Vec<Definition>> for Program {
|
impl From<Vec<Definition>> for Program {
|
||||||
fn from(defs: Vec<Definition>) -> Program {
|
fn from(defs: Vec<Definition>) -> Program {
|
||||||
Program(defs)
|
Program { defs }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ pub fn global_env_name() -> ast::EnvName {
|
||||||
pub fn setup(program: ast::Program, prim_funcs: PrimitiveFuncs) -> Result<State, Error> {
|
pub fn setup(program: ast::Program, prim_funcs: PrimitiveFuncs) -> Result<State, Error> {
|
||||||
let mut state = State::new(global_env_name().0.clone(), prim_funcs);
|
let mut state = State::new(global_env_name().0.clone(), prim_funcs);
|
||||||
|
|
||||||
defs_to_env(program.0, &global_env_name(), &mut state)?;
|
defs_to_env(program.defs, &global_env_name(), &mut state)?;
|
||||||
Ok(state)
|
Ok(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,30 @@ pub fn parse<T>(tokens: &mut Tokens, parser: Parser<T>) -> Result<T, Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_program(tokens: &mut Tokens) -> ParseResult<ast::Program> {
|
pub fn parse_program(tokens: &mut Tokens) -> ParseResult<ast::Program> {
|
||||||
Ok(parse_definitions(tokens)?.map(ast::Program))
|
Ok(parse_definitions(tokens)?.map(|defs| ast::Program { defs }))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_includes(tokens: &mut Tokens) -> ParseResult<Vec<ast::File>> {
|
||||||
|
tokens.many(parse_include)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_include(tokens: &mut Tokens) -> ParseResult<ast::File> {
|
||||||
|
if let Some(_) = tokens.next_if(&Token::Include) {
|
||||||
|
if let Some(LocatedToken {
|
||||||
|
token: Token::String(string),
|
||||||
|
..
|
||||||
|
}) = tokens.next_if(&Token::String("".into()))
|
||||||
|
{
|
||||||
|
Ok(Some(ast::File(string)))
|
||||||
|
} else {
|
||||||
|
Err(Error::UnexpectedToken {
|
||||||
|
expected: Token::String("".into()),
|
||||||
|
got: tokens.next(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_definitions(tokens: &mut Tokens) -> ParseResult<Vec<ast::Definition>> {
|
fn parse_definitions(tokens: &mut Tokens) -> ParseResult<Vec<ast::Definition>> {
|
||||||
|
|
|
||||||
|
|
@ -304,6 +304,7 @@ pub fn scan(source: String) -> Tokens {
|
||||||
"if" => Token::If,
|
"if" => Token::If,
|
||||||
"else" => Token::Else,
|
"else" => Token::Else,
|
||||||
"return" => Token::Return,
|
"return" => Token::Return,
|
||||||
|
"include" => Token::Include,
|
||||||
"loop" => Token::Loop,
|
"loop" => Token::Loop,
|
||||||
"break" => Token::Break,
|
"break" => Token::Break,
|
||||||
"true" => Token::True,
|
"true" => Token::True,
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ source: src/parser/parser.rs
|
||||||
expression: result
|
expression: result
|
||||||
---
|
---
|
||||||
Ok(
|
Ok(
|
||||||
Program(
|
Program {
|
||||||
[
|
defs: [
|
||||||
Definition {
|
Definition {
|
||||||
mutable: false,
|
mutable: false,
|
||||||
name: Name(
|
name: Name(
|
||||||
|
|
@ -124,5 +124,5 @@ Ok(
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
),
|
},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ pub enum Token {
|
||||||
If,
|
If,
|
||||||
Else,
|
Else,
|
||||||
Return,
|
Return,
|
||||||
|
Include,
|
||||||
OpenParen,
|
OpenParen,
|
||||||
CloseParen,
|
CloseParen,
|
||||||
OpenBracket,
|
OpenBracket,
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ pub fn fetch_events(state: &mut State) -> Input {
|
||||||
input.gamepad1.dpad.up = is_key_down(KeyCode::Up);
|
input.gamepad1.dpad.up = is_key_down(KeyCode::Up);
|
||||||
input.gamepad1.dpad.down = is_key_down(KeyCode::Down);
|
input.gamepad1.dpad.down = is_key_down(KeyCode::Down);
|
||||||
|
|
||||||
for gamepad in state.gamepads.all() {
|
if let Some(gamepad) = state.gamepads.all().next() {
|
||||||
//println!("{:#?}", gamepad.all_currently_pressed().collect::<Vec<_>>());
|
//println!("{:#?}", gamepad.all_currently_pressed().collect::<Vec<_>>());
|
||||||
// action buttons
|
// action buttons
|
||||||
input.gamepad1.buttons.a = gamepad.is_currently_pressed(gamepads::Button::ActionRight);
|
input.gamepad1.buttons.a = gamepad.is_currently_pressed(gamepads::Button::ActionRight);
|
||||||
|
|
@ -165,7 +165,6 @@ pub fn fetch_events(state: &mut State) -> Input {
|
||||||
|
|
||||||
input.gamepad1.right_stick.x = gamepad.right_stick_x();
|
input.gamepad1.right_stick.x = gamepad.right_stick_x();
|
||||||
input.gamepad1.right_stick.y = gamepad.right_stick_y();
|
input.gamepad1.right_stick.y = gamepad.right_stick_y();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
input
|
input
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue