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;
|
||||
|
||||
/// 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.
|
||||
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
||||
pub enum Expr {
|
||||
|
|
@ -77,13 +93,6 @@ pub enum Statement {
|
|||
Break,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
||||
pub struct Definition {
|
||||
pub mutable: bool,
|
||||
pub name: Name,
|
||||
pub expr: Expr,
|
||||
}
|
||||
|
||||
/// A reduced value.
|
||||
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
||||
pub enum Value {
|
||||
|
|
@ -136,10 +145,6 @@ pub struct Record(pub BTreeMap<Label, Ref>);
|
|||
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
||||
pub struct Vector(pub Vec<Ref>);
|
||||
|
||||
/// A Program.
|
||||
#[derive(PartialEq, PartialOrd, Debug, Clone)]
|
||||
pub struct Program(pub Vec<Definition>);
|
||||
|
||||
// ----- //
|
||||
// Impls //
|
||||
// ----- //
|
||||
|
|
@ -225,7 +230,7 @@ impl From<bool> for Expr {
|
|||
|
||||
impl From<Vec<Definition>> for 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> {
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
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>> {
|
||||
|
|
|
|||
|
|
@ -304,6 +304,7 @@ pub fn scan(source: String) -> Tokens {
|
|||
"if" => Token::If,
|
||||
"else" => Token::Else,
|
||||
"return" => Token::Return,
|
||||
"include" => Token::Include,
|
||||
"loop" => Token::Loop,
|
||||
"break" => Token::Break,
|
||||
"true" => Token::True,
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ source: src/parser/parser.rs
|
|||
expression: result
|
||||
---
|
||||
Ok(
|
||||
Program(
|
||||
[
|
||||
Program {
|
||||
defs: [
|
||||
Definition {
|
||||
mutable: false,
|
||||
name: Name(
|
||||
|
|
@ -124,5 +124,5 @@ Ok(
|
|||
),
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ pub enum Token {
|
|||
If,
|
||||
Else,
|
||||
Return,
|
||||
Include,
|
||||
OpenParen,
|
||||
CloseParen,
|
||||
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.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<_>>());
|
||||
// action buttons
|
||||
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.y = gamepad.right_stick_y();
|
||||
break;
|
||||
}
|
||||
input
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue