diff --git a/src/lang.rs b/src/lang.rs index c77397d..e69de29 100644 --- a/src/lang.rs +++ b/src/lang.rs @@ -1,169 +0,0 @@ -use std::str::Chars; - -struct Type { - name: String, - params: Vec, -} -struct Decl { - name: String, - typed: Option, - default: Option, -} -struct Param { - borrow: bool, - decl: Decl, -} -struct Call { - name: String, - params: Vec, -} -struct StructEntry { - name: Option, - value: Expr -} -struct FuncEntry { - name: Option, - value: Expr, - borrow: bool, -} -struct Class { - name: String, - entries: Vec, - methods: Vec, -} -struct Function { - annotations: Vec, - name: String, - params: Vec, - result: Type, -} -enum Overloaded { - Plus, - Get, - Set, - GetIndex, - SetIndex, -} -enum Annotation { - Inline, - Native, - Overload(Overloaded), - Expr(String), -} -enum Statement { - Class(Class), - DeclLet(Decl), - DeclVar(Decl), - Assignment { - name: String, - expr: Expr, - }, - Call(Call), - Return(Expr), - Block(Block), - While(Expr,Box), - Loop(Box), - Function(Function), - Break, -} -enum Expr { - Paren(Box), - Call(Call), - Add { - left: Box, - right: Box, - }, - String(String), - Number(String), -} -struct Block(Vec); -struct ParseError(String); -enum Part { - Set(&'static str), - Raw(&'static str), -} -enum Selector { - Cap(Pattern), - One(Part), - Any(Part), -} -struct Pattern(&'static [Selector]); -impl Pattern { - fn eval<'a>(&self, str: &'a str) -> Result<(&'a str, Vec<&'a str>), ()> { - let mut captures = Vec::new(); - let mut current = str; - let mut count = 0; - self.0.iter().try_for_each(|selector: &Selector| { - match selector { - Selector::Cap(pattern) => { - pattern.eval(str).and_then(|(sum, _)| { - captures.push(sum); - Ok(()) - }) - }, - Selector::Any(part) => { - let mut delta = 0; - match part { - Part::Set(set) => { - delta = current.chars().take_while(|char| set.contains(*char)).count(); - current = ¤t[delta..]; - }, - Part::Raw(raw) => { - while current.starts_with(raw) { - delta += raw.len(); - current = ¤t[delta..]; - } - }, - } - count += delta; - Ok(()) - } - Selector::One(part) => { - match part { - Part::Set(set) => { - let res = current.chars().next().is_some_and(|char| set.contains(char)); - if res { - current = ¤t[1..]; - count += 1; - } - res - }, - Part::Raw(raw) => { - let res = current.starts_with(raw); - if res { - current = ¤t[raw.len()..]; - count += raw.len(); - } - res - } - }.then_some(()).ok_or(()) - } - } - }).map(|_| (&str[..count],captures)) - } -} -const IDENTIFIER_START_SET: &str = "abcdefghijklmnopqrstuvwxyz_"; -const IDENTIFIER_REST_SET: &str = "abcdefghijklmnopqrstuvwxyz_1234567890"; -const WHITESPACE_SET: &str = "\n\r\t "; -const PATTERN_IDENTIFIER: Pattern = Pattern(&[ - Selector::One(Part::Set(IDENTIFIER_START_SET)), - Selector::Any(Part::Set(IDENTIFIER_REST_SET)), -]); -const PATTERN_WHITESPACE: Pattern = Pattern(&[Selector::Any(Part::Set(WHITESPACE_SET))]); -const PATTERN_COMMENT: Pattern = Pattern(&[Selector::Any(Part::Raw())]); -const PATTERN_CALL_START: Pattern = Pattern(&[ - Selector::Cap(PATTERN_IDENTIFIER), - Selector::One(Part::Set("(")) -]); -fn parse_call(str: &str) -> Result { - PATTERN_CALL_START.eval(str).and_then(|_| { - Ok(()) - }); - Ok(Block(vec!())) -} -fn parse_block(str: &str) -> Result { - parse_call(str) -} -fn parse(source: &str) -> Result { - parse_block(source) -} diff --git a/src/test.png b/src/test.png new file mode 100644 index 0000000..240be72 Binary files /dev/null and b/src/test.png differ