Compare commits
6 Commits
10438691c2
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| eba41e4330 | |||
| a894fc6689 | |||
| f91d5a5091 | |||
| d2e89dae3e | |||
| c2fea96feb | |||
| e59e340777 |
@@ -0,0 +1 @@
|
|||||||
|
target
|
||||||
Generated
-22
@@ -416,27 +416,6 @@ version = "1.2.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f"
|
checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "derive_more"
|
|
||||||
version = "2.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d751e9e49156b02b44f9c1815bcb94b984cdcc4396ecc32521c739452808b134"
|
|
||||||
dependencies = [
|
|
||||||
"derive_more-impl",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "derive_more-impl"
|
|
||||||
version = "2.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"rustc_version",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dispatch"
|
name = "dispatch"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@@ -598,7 +577,6 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"console_error_panic_hook",
|
"console_error_panic_hook",
|
||||||
"console_log",
|
"console_log",
|
||||||
"derive_more",
|
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"log",
|
"log",
|
||||||
"pollster",
|
"pollster",
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ log = "0.4"
|
|||||||
wgpu = "29.0.3"
|
wgpu = "29.0.3"
|
||||||
pollster = "0.4.0"
|
pollster = "0.4.0"
|
||||||
console_error_panic_hook = "0.1.7"
|
console_error_panic_hook = "0.1.7"
|
||||||
derive_more = "2.1.1"
|
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
console_error_panic_hook = "0.1.6"
|
console_error_panic_hook = "0.1.6"
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
local two
|
||||||
|
do
|
||||||
|
local one
|
||||||
|
if something then
|
||||||
|
local three
|
||||||
|
print(something)
|
||||||
|
end
|
||||||
|
local four
|
||||||
|
if something2 then
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
#![recursion_limit = "256"]
|
|
||||||
// Credit of most code to https://sotrh.github.io/learn-wgpu/ since I'm not familiar with wgpu
|
// Credit of most code to https://sotrh.github.io/learn-wgpu/ since I'm not familiar with wgpu
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
|||||||
+1148
-409
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -1,2 +1,3 @@
|
|||||||
|
#![recursion_limit = "256"]
|
||||||
pub mod engine;
|
pub mod engine;
|
||||||
mod lang;
|
pub mod lang;
|
||||||
+3
-2
@@ -1,7 +1,8 @@
|
|||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
|
||||||
use game::engine::run;
|
use game::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
run().unwrap();
|
|
||||||
|
//engine::run().unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,353 @@
|
|||||||
|
// Macro for expanding syntax form into a struct
|
||||||
|
macro_rules! definition {
|
||||||
|
{@build ($n:ident structure) ($($t:tt)*) null () } => {
|
||||||
|
#[allow(unused)]
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct $n ($($t)*);
|
||||||
|
};
|
||||||
|
{@build ($n:ident enumeration new ($($f:tt)*) ($m:ident($($mt:tt)*)$($r:tt)*)) () null ()} => {
|
||||||
|
definition!{@build ($n enumeration ($($f)*) ($m($($mt)*)$($r)*)) () null () $($mt)*}
|
||||||
|
};
|
||||||
|
{@build ($n:ident enumeration ($($f:tt)*) ($m:ident($($mt:tt)*)$($r:tt)*)) ($($t:tt)*) null ()} => {
|
||||||
|
definition!{@build ($n enumeration new ($($f)*$m($($t)*)) ($($r)*)) () null () }
|
||||||
|
};
|
||||||
|
{@build ($n:ident enumeration new ($($m:ident($($mt:tt)*))*) ()) () null () } => {
|
||||||
|
definition!{@build ($n enumeration filter () ($($m($($mt)*))*))}
|
||||||
|
};
|
||||||
|
{@build ($n:ident enumeration filter ($($e:tt)*) ($m:ident($($mt:tt)+)$($t:tt)*))} => {
|
||||||
|
definition!{@build ($n enumeration filter ($($e)*$m($($mt)*),) ($($t)*))}
|
||||||
|
};
|
||||||
|
{@build ($n:ident enumeration filter ($($e:tt)*) ($m:ident()$($t:tt)*))} => {
|
||||||
|
definition!{@build ($n enumeration filter ($($e)*$m,) ($($t)*))}
|
||||||
|
};
|
||||||
|
{@build ($n:ident enumeration filter ($($e:tt)*) ())} => {
|
||||||
|
#[allow(unused)]
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum $n {
|
||||||
|
$($e)*
|
||||||
|
}
|
||||||
|
};
|
||||||
|
{@build $m:tt ($($t:tt)*) null () $l:literal $($r:tt)*} => {
|
||||||
|
definition!{@build $m ($($t)*) null () $($r)*}
|
||||||
|
};
|
||||||
|
{@build $m:tt ($($t:tt)*) null () $i:ident $($r:tt)*} => {
|
||||||
|
definition!{@build $m ($($t)*Box<$i>,) null () $($r)*}
|
||||||
|
};
|
||||||
|
{@build $m:tt ($($t:tt)*) option ($a:tt) () $($r:tt)*} => {
|
||||||
|
definition!{@build $m ($($t)*Option<$a>,) null () $($r)*}
|
||||||
|
};
|
||||||
|
{@build $m:tt ($($t:tt)*) vector ($a:tt) () $($r:tt)*} => {
|
||||||
|
definition!{@build $m ($($t)*Vec<$a>,) null () $($r)*}
|
||||||
|
};
|
||||||
|
{@build $m:tt ($($t:tt)*) option ($($a:tt)*) () $($r:tt)*} => {
|
||||||
|
definition!{@build $m ($($t)*Option<($($a),*)>,) null () $($r)*}
|
||||||
|
};
|
||||||
|
{@build $m:tt ($($t:tt)*) vector ($($a:tt)*) () $($r:tt)*} => {
|
||||||
|
definition!{@build $m ($($t)*Vec<($($a),*)>,) null () $($r)*}
|
||||||
|
};
|
||||||
|
{@build $m:tt ($($t:tt)*) null () [$($b:tt)*] $($r:tt)*} => {
|
||||||
|
definition!{@build $m ($($t)*) option () ($($b)*) $($r)*}
|
||||||
|
};
|
||||||
|
{@build $m:tt ($($t:tt)*) null () {$($b:tt)*} $($r:tt)*} => {
|
||||||
|
definition!{@build $m ($($t)*) vector () ($($b)*) $($r)*}
|
||||||
|
};
|
||||||
|
{@build $m:tt ($($t:tt)*) $i:ident ($($a:tt)*) ($l:literal $($b:tt)*) $($r:tt)*} => {
|
||||||
|
definition!{@build $m ($($t)*) $i ($($a)*) ($($b)*) $($r)*}
|
||||||
|
};
|
||||||
|
{@build $m:tt ($($t:tt)*) $i:ident ($($a:tt)*) ($n:ident $($b:tt)*) $($r:tt)*} => {
|
||||||
|
definition!{@build $m ($($t)*) $i ($($a)*$n) ($($b)*) $($r)*}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
macro_rules! implement {
|
||||||
|
{@begin $n:ident structure $($t:tt)*} => {
|
||||||
|
implement!{@build (state result) (structure $n) {} {} $($t)*}
|
||||||
|
};
|
||||||
|
{@begin $n:ident enumeration ($m:ident ($($t2:tt)*)$($t:tt)*)} => {
|
||||||
|
implement!{@build (state result) (enumeration $m {} ($($t)*) $n) {} {} $($t2)*}
|
||||||
|
};
|
||||||
|
{@build ($st:ident $r:ident) $m:tt $f:tt {$($f2:tt)*} $s:literal $($t:tt)*} => {
|
||||||
|
implement!{@build ($st $r) $m $f {
|
||||||
|
$($f2)*
|
||||||
|
$st = $st.trim_start();
|
||||||
|
if $st.starts_with($s) {
|
||||||
|
$st = &$st[$s.len()..]
|
||||||
|
} else {
|
||||||
|
return Err("error".to_string())
|
||||||
|
}
|
||||||
|
} $($t)*}
|
||||||
|
};
|
||||||
|
{@build ($s:ident $r:ident) $m:tt {$($f:tt)*} {$($f2:tt)*} $i:ident $($t:tt)*} => {
|
||||||
|
implement!{@build ($s $r) $m {$($f)*{$($f2)*}} {
|
||||||
|
let $r;
|
||||||
|
match $i::consume($s) {
|
||||||
|
Ok((r,s)) => {
|
||||||
|
$s = s;
|
||||||
|
$r = r;
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
return Err(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} $($t)*}
|
||||||
|
};
|
||||||
|
{@build $va:tt ($($m:tt)*) {$($f:tt)*} {$($f2:tt)*} {$($r:tt)*} $($t:tt)*} => {
|
||||||
|
implement!{@build $va (vector {$($f)*{$($f2)*}} ($($t)*) $($m)*) {} {} $($r)*}
|
||||||
|
};
|
||||||
|
{@build $va:tt ($($m:tt)*) {$($f:tt)*} {$($f2:tt)*} [$($r:tt)*] $($t:tt)*} => {
|
||||||
|
implement!{@build $va (option {$($f)*{$($f2)*}} ($($t)*) $($m)*) {} {} $($r)*}
|
||||||
|
};
|
||||||
|
{@finish ($s:ident $re:ident) (option {$($l:tt)*} ($($t:tt)*) $($m:tt)*) {{$($f:tt)*}$({$($r:tt)*})*} } => {
|
||||||
|
implement!{@build ($s $re) ($($m)*) {$($l)*} {
|
||||||
|
let mut $re;
|
||||||
|
let taker = move |_state| {
|
||||||
|
let mut $s: &str = _state;
|
||||||
|
$($f)*
|
||||||
|
Ok(((
|
||||||
|
$({$($r)*$re}),*
|
||||||
|
),$s))
|
||||||
|
};
|
||||||
|
match taker($s) {
|
||||||
|
Ok((r,s)) => {
|
||||||
|
$s = s;
|
||||||
|
$re = Some(r);
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
$re = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} $($t)*}
|
||||||
|
};
|
||||||
|
{@finish ($s:ident $re:ident) (vector {$($l:tt)*} ($($t:tt)*) $($m:tt)*) {{$($f:tt)*}$({$($r:tt)*})*} } => {
|
||||||
|
implement!{@build ($s $re) ($($m)*) {$($l)*} {
|
||||||
|
let mut $re = Vec::new();
|
||||||
|
let taker = move |_state| {
|
||||||
|
let mut $s: &str = _state;
|
||||||
|
$($f)*
|
||||||
|
Ok(((
|
||||||
|
$({$($r)*$re}),*
|
||||||
|
),$s))
|
||||||
|
};
|
||||||
|
while !$s.is_empty() {
|
||||||
|
match taker($s) {
|
||||||
|
Ok((r,s)) => {
|
||||||
|
$s = s;
|
||||||
|
$re.push(r);
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} $($t)*}
|
||||||
|
};
|
||||||
|
{@build $va:tt $m:tt {$($r:tt)*} $r2:tt} => {
|
||||||
|
implement!{@finish $va $m {$($r)*$r2}}
|
||||||
|
};
|
||||||
|
{@finish ($s:ident $re:ident) (structure $n:ident) {{$($f:tt)*}$({$($r:tt)*})*} } => {
|
||||||
|
#[allow(unused)]
|
||||||
|
impl Parse for $n {
|
||||||
|
fn consume(_state: &str) -> Result<(Self, &str), Error> where Self: Sized {
|
||||||
|
let mut $s: &str = _state;
|
||||||
|
$($f)*
|
||||||
|
Ok((
|
||||||
|
$n($({$($r)*$re.into()}),*),$s
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
{@finish ($s:ident $re:ident) (enumeration $m2:ident {$($l:tt)*} ($m:ident ($($t2:tt)*)$($t:tt)*) $n:ident) {$f:tt$({$($r:tt)*})+} } => {
|
||||||
|
implement!{@build ($s $re) (enumeration $m {$($l)*{
|
||||||
|
$f
|
||||||
|
Ok((
|
||||||
|
$n::$m2($({$($r)*$re.into()}),+),$s
|
||||||
|
))
|
||||||
|
}} ($($t)*) $n) {} {} $($t2)*}
|
||||||
|
};
|
||||||
|
{@finish ($s:ident $re:ident) (enumeration $m3:ident {$($l:tt)*} ($m:ident ($($t2:tt)*)$($t:tt)*) $n:ident) {$f:tt} } => {
|
||||||
|
implement!{@build ($s $re) (enumeration $m {$($l)*{
|
||||||
|
$f
|
||||||
|
Ok((
|
||||||
|
$n::$m3,$s
|
||||||
|
))
|
||||||
|
}} ($($t)*) $n) {} {} $($t2)*}
|
||||||
|
};
|
||||||
|
{@finish ($s:ident $re:ident) (enumeration $m2:ident {$($l:tt)*} () $n:ident) {$f:tt$({$($r:tt)*})+}} => {
|
||||||
|
implement!{@finish ($s $re) (enumeration {$($l)*{
|
||||||
|
$f
|
||||||
|
Ok((
|
||||||
|
$n::$m2($({$($r)*$re.into()}),+),$s
|
||||||
|
))
|
||||||
|
}} () $n)} // straight to below
|
||||||
|
};
|
||||||
|
{@finish ($s:ident $re:ident) (enumeration $m2:ident {$($l:tt)*} () $n:ident) {$f:tt}} => {
|
||||||
|
implement!{@finish ($s $re) (enumeration {$($l)*{
|
||||||
|
$f
|
||||||
|
Ok((
|
||||||
|
$n::$m2,$s
|
||||||
|
))
|
||||||
|
}} () $n)} // straight to below
|
||||||
|
};
|
||||||
|
{@finish ($s:ident $re:ident) (enumeration {$({$($f:tt)*})*} () $n:ident)} => {
|
||||||
|
#[allow(unused)]
|
||||||
|
impl Parse for $n {
|
||||||
|
fn consume(_state: &str) -> Result<(Self, &str), Error> where Self: Sized {
|
||||||
|
let mut $s: &str = _state;
|
||||||
|
$(
|
||||||
|
let case = (||{
|
||||||
|
let mut state: &str = _state;
|
||||||
|
$($f)*
|
||||||
|
})(); // put it into a closure and run it (makes returning easier)
|
||||||
|
if case.is_ok() {
|
||||||
|
return case;
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
Err("error".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
macro_rules! class {
|
||||||
|
($i:ident($($t:tt)*)) => {
|
||||||
|
definition!{@build ($i structure) () null () $($t)*}
|
||||||
|
implement!{@begin $i structure $($t)*}
|
||||||
|
//display!{@begin $i structure $($t)*}
|
||||||
|
};
|
||||||
|
($i:ident{$($n:ident($($t:tt)*)),*}) => {
|
||||||
|
definition!{@build ($i enumeration new () ($($n($($t)*))*)) () null ()}
|
||||||
|
implement!{@begin $i enumeration ($($n($($t)*))*)}
|
||||||
|
//display!{@begin $i enumeration ($($n($($t)*))*)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
macro_rules! parser {
|
||||||
|
() => {};
|
||||||
|
($i:ident$t:tt;$($tail:tt)*) => {
|
||||||
|
class!($i$t);
|
||||||
|
parser!($($tail)*);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: reimplement attrib here
|
||||||
|
// https://www.lua.org/manual/5.5/manual.html#9
|
||||||
|
parser!{
|
||||||
|
// LiteralString -> "..."
|
||||||
|
// LiteralNumber -> 0x... 123.456
|
||||||
|
Chunk ( Block );
|
||||||
|
Block ( {Statement} [Return] );
|
||||||
|
Statement {
|
||||||
|
Semicolon (";"),
|
||||||
|
Assignment (Variables "=" Expressions),
|
||||||
|
Call (RootAtom CallChain),
|
||||||
|
Label (Label),
|
||||||
|
Break ("break"),
|
||||||
|
Goto ("goto" Name),
|
||||||
|
Do ("do" Block "end"),
|
||||||
|
While ("while" Expression "do" Block "end"),
|
||||||
|
Repeat ("repeat" Block "until" Expression),
|
||||||
|
If ("if" Expression "then" Block {"elseif" Expression "then" Block} ["else" Block] "end"),
|
||||||
|
ForRange ("for" Name "=" Expression "," Expression ["," Expression] "do" Block "end"),
|
||||||
|
ForIn ("for" Names "in" Expressions "do" Block "end"),
|
||||||
|
Function ("function" FunctionName FunctionBody),
|
||||||
|
LocalFunction ("local" "function" Name FunctionBody),
|
||||||
|
GlobalFunction ("global" "function" Name FunctionBody),
|
||||||
|
Declaration ("local" Names ["=" Expressions]),
|
||||||
|
Global ("global" Names)
|
||||||
|
};
|
||||||
|
Return( "return" [Expressions] [";"] );
|
||||||
|
Label( "::" Name "::" );
|
||||||
|
FunctionName( Name {"." Name} [":" Name] );
|
||||||
|
Variables( Variable {"," Variable} );
|
||||||
|
Names( Name {"," Name} );
|
||||||
|
Expressions( Expression {"," Expression} );
|
||||||
|
// DEVIATION: This parser is greedy, so the manual's syntax breaks it.
|
||||||
|
RootAtom {
|
||||||
|
Variable (Name),
|
||||||
|
Expression ("(" Expression ")")
|
||||||
|
};
|
||||||
|
IndexAtom {
|
||||||
|
Dot ("." Name),
|
||||||
|
Index ("[" Expression "]")
|
||||||
|
};
|
||||||
|
CallAtom {
|
||||||
|
Normal (Arguments),
|
||||||
|
Method (":" Name Arguments)
|
||||||
|
};
|
||||||
|
PrefixAtom {
|
||||||
|
Call (CallAtom),
|
||||||
|
Index (IndexAtom)
|
||||||
|
};
|
||||||
|
VariableChain {
|
||||||
|
Link (PrefixAtom VariableChain),
|
||||||
|
Finish (IndexAtom)
|
||||||
|
};
|
||||||
|
CallChain {
|
||||||
|
Link (PrefixAtom CallChain),
|
||||||
|
Finish (CallAtom)
|
||||||
|
};
|
||||||
|
Variable (RootAtom VariableChain);
|
||||||
|
Expression {
|
||||||
|
Nil ("nil"),
|
||||||
|
False ("false"),
|
||||||
|
True ("true"),
|
||||||
|
VarArg ("..."),
|
||||||
|
Number (Number),
|
||||||
|
String (String),
|
||||||
|
FunctionDef (FunctionDef),
|
||||||
|
Prefix (RootAtom {PrefixAtom}),
|
||||||
|
Table (Table),
|
||||||
|
Binary (Expression BinaryOp Expression), // todo: .
|
||||||
|
Unary (UnaryOp Expression)
|
||||||
|
};
|
||||||
|
// -----------------------
|
||||||
|
Arguments {
|
||||||
|
Expressions ("(" [Expressions] ")"),
|
||||||
|
Table (Table),
|
||||||
|
String (String)
|
||||||
|
};
|
||||||
|
FunctionDef( "function" FunctionBody );
|
||||||
|
FunctionBody( "(" [Parameters] ")" Block "end" );
|
||||||
|
Parameters {
|
||||||
|
Names (Names ["," VarArg]),
|
||||||
|
VarArg (VarArg)
|
||||||
|
};
|
||||||
|
VarArg( "..." [Name] );
|
||||||
|
Table( "{" [Fields] "}" );
|
||||||
|
Fields( Field {FieldSep Field} [FieldSep] );
|
||||||
|
Field {
|
||||||
|
ExpressionIndex ("[" Expression "]" "=" Expression),
|
||||||
|
Name (Name "=" Expression),
|
||||||
|
Expression (Expression)
|
||||||
|
};
|
||||||
|
FieldSep {
|
||||||
|
Comma (","),
|
||||||
|
Semicolon (";")
|
||||||
|
};
|
||||||
|
BinaryOp {
|
||||||
|
Plus ("+"),
|
||||||
|
Minus ("-"),
|
||||||
|
Mul ("*"),
|
||||||
|
Divide ("/"),
|
||||||
|
DivFloor ("//"),
|
||||||
|
Caret ("^"),
|
||||||
|
Modulo ("%"),
|
||||||
|
Ampersand ("&"),
|
||||||
|
Tilde ("~"),
|
||||||
|
Pipe ("|"),
|
||||||
|
ShiftRight (">>"),
|
||||||
|
ShiftLeft ("<<"),
|
||||||
|
Concat (".."),
|
||||||
|
Less ("<"),
|
||||||
|
LessEqual ("<="),
|
||||||
|
Greater (">"),
|
||||||
|
GreatEqual (">="),
|
||||||
|
Equivalent ("=="),
|
||||||
|
NotEqual ("~="),
|
||||||
|
And ("and"),
|
||||||
|
Or ("or")
|
||||||
|
};
|
||||||
|
UnaryOp {
|
||||||
|
Negate ("-"),
|
||||||
|
Not ("not"),
|
||||||
|
Ampersand ("#"),
|
||||||
|
Tilde ("~")
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user