From db1bc88e7b714da1b79d9aff82b44f4fe3a71e3f Mon Sep 17 00:00:00 2001 From: Goren Barak Date: Fri, 24 Nov 2023 18:42:19 -0500 Subject: [PATCH] explained myself --- README.md | 2 + TAGS~ | 159 ++++++++++++++++++++++++++++++++++++++++++++ src/parse/parse.rs | 29 ++++++++ src/parse/parse.rs~ | 0 4 files changed, 190 insertions(+) create mode 100644 TAGS~ create mode 100644 src/parse/parse.rs create mode 100644 src/parse/parse.rs~ diff --git a/README.md b/README.md index 487033c..3159b7b 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,5 @@ fnaf adder(a, b) { assert_eq(200, adder(able, os)); ``` + +Yes, the FNAF part is real. diff --git a/TAGS~ b/TAGS~ new file mode 100644 index 0000000..6986b9b --- /dev/null +++ b/TAGS~ @@ -0,0 +1,159 @@ + +Cargo.lock,0 + +Cargo.toml,0 + +README.md,130 +# ![SkyLang](.images/slang_logo_dark_transparent_not_motto.png)![SkyLang](.images/slang_logo_dark_transparent_not_motto.png)1,0 + +src/codegen/fasm.rs,91 +pub fn fasm_codegen(exprs: &Vec, not_a_function: bool) -> String {fasm_codegen3,27 + +src/codegen/fasmarm.rs,0 + +src/codegen/mod.rs,23 +pub mod fasm;fasm1,0 + +src/lex/mod.rs,47 +pub mod tok;tok1,0 +pub mod parse;parse2,13 + +src/lex/parse.rs,755 +pub fn match_single_char<'a>(word: &'a str) -> Option> {match_single_char6,40 + macro_rules! tok {tok7,107 +pub fn match_keyword<'a>(word: &'a str) -> Option> {match_keyword38,697 + macro_rules! tok {tok39,760 +pub fn match_two_char<'a>(word: &'a str) -> Option> {match_two_char66,1310 + macro_rules! tok {tok67,1374 +pub fn match_string_literal<'a>(word: &'a str) -> Option> {match_string_literal85,1681 + macro_rules! tok {tok86,1751 +pub fn match_int_literal<'a>(word: &'a str) -> Option> {match_int_literal114,2191 + macro_rules! tok {tok115,2258 +pub fn match_identifier<'a>(word: &'a str) -> Option> {match_identifier134,2562 + macro_rules! tok {tok135,2628 + +src/lex/tok.rs,2268 +pub struct Token<'a> {Token6,79 + tt: TokenType,tt7,102 + word: &'a str,word8,121 +pub enum TokenType {TokenType12,160 + EOF,EOF13,181 + Semicolon, // ;Semicolon16,222 + Equal, // =Equal17,242 + LeftParen, // (LeftParen18,258 + RightParen, // )RightParen19,278 + LeftBrace, // {LeftBrace20,299 + RightBrace, // }RightBrace21,319 + Comma, // ,Comma22,340 + Dot, // .Dot23,356 + Minus, // -Minus24,370 + Plus, // +Plus25,386 + Slash, // /Slash26,401 + Star, // *Star27,417 + Percent, // %Percent28,432 + Bang, // !Bang29,450 + Colon, // :Colon30,465 + Less, // <Less31,481 + Greater, // >Greater32,496 + Fn, // fnFn35,531 + Let, // letLet36,546 + If, // ifIf37,562 + Else, // elseElse38,577 + While, // whileWhile39,595 + Elif, // elifElif40,615 + Return, // returnReturn41,633 + For, // forFor42,655 + In, // inIn43,671 + Break, // breakBreak44,686 + Continue, // continueContinue45,706 + EqualEqual, // ==EqualEqual48,761 + BangEqual, // !=BangEqual49,784 + LessEqual, // <=LessEqual50,806 + GreaterEqual, // >=GreaterEqual51,828 + String, // A string literal.String54,873 + Number, // An integer.Number55,906 + Identifier, // An identifier.Identifier56,933 + True, // trueTrue57,967 + False, // falseFalse58,985 + Null, // NoneNull59,1005 + Error, // A syntax error.Error62,1037 +pub struct Lexer<'a> {Lexer66,1087 + source: &'a str,source67,1110 + tokens: Vec>,tokens68,1131 + current: usize,current69,1159 + after: &'a strafter70,1179 +impl<'a> Lexer<'a> {Lexer73,1201 + pub fn new() -> Self {new74,1222 +impl<'a> std::iter::Iterator for Lexer<'a> {Lexer84,1386 + type Item = Option;Item85,1431 + fn next(&mut self) -> Option {next87,1462 +impl<'a> From<&'a str> for Lexer<'a> {Lexer92,1579 + fn from(value: &'a str) -> Self {from93,1618 +impl<'a> From<&'a std::string::String> for Lexer<'a> {Lexer103,1800 + fn from(value: &'a std::string::String) -> Self {from104,1855 +impl<'a> Token<'a> {Token114,2057 + pub fn new(tt: TokenType, word: &'a str) -> Self {new115,2078 + pub fn empty() -> Self {empty122,2171 + +src/main.rs,102 +pub mod lex;lex3,21 +pub mod codegen;codegen4,34 +pub mod parse;parse7,106 +fn main() {main9,122 + +src/parse/ast.rs,2125 +pub enum Expr<'a> {Expr2,17 + MathExpr(Math<'a>),MathExpr3,37 + FunCall(FunCall<'a>),FunCall4,61 + FunDefinition(FunDefinition<'a>),FunDefinition5,87 + VarDefinition(VarDefinition<'a>),VarDefinition6,125 + Return(Value<'a>),Return7,163 + If(IfStatement<'a>),If8,186 + BreakpointBreakpoint9,211 +pub struct Math<'a> {Math15,279 + pub left: &'a Value<'a>,left16,301 + pub right: &'a Value<'a>,right17,330 + pub operator: MathOperatoroperator18,360 +pub enum MathOperator {MathOperator22,424 + OP_ADD, // AdditionOP_ADD23,448 + OP_SUB, // SubtractionOP_SUB24,472 + OP_DIV, // DivisionOP_DIV25,499 + OP_MULT, // MultiplicationOP_MULT26,523 + OP_MOD, // ModuloOP_MOD27,554 +pub struct FunCall<'a> {FunCall33,610 + pub name: &'a str,name34,635 + pub params: Vec>,params35,658 +pub struct FunDefinition<'a> {FunDefinition39,710 + pub name: &'a str,name40,741 + pub contents: Vec>,contents41,764 +pub struct FunParamDef<'a> {FunParamDef45,817 + name: &'a str,name46,846 + number: u64,number47,865 +pub struct FunParamCall<'a> {FunParamCall51,902 + pub value: Value<'a>,value52,932 +pub struct VarDefinition<'a> {VarDefinition58,992 + pub name: &'a str,name59,1023 + pub value: Value<'a>,value60,1046 +pub struct VarReference<'a> {VarReference65,1106 + pub name: &'a str,name66,1136 +pub struct ParamReference {ParamReference70,1192 + pub param_number: u64,param_number71,1220 +pub enum Value<'a> {Value75,1280 + Var(VarReference<'a>),Var76,1301 + Param(ParamReference),Param77,1328 + Number(u64),Number78,1355 +pub struct IfStatement<'a> {IfStatement82,1392 + pub condition: Condition<'a>,condition83,1421 + pub if_true: Vec>,if_true84,1455 +pub struct Condition<'a> {Condition88,1507 + pub left: Value<'a>,left89,1534 + pub right: Value<'a>,right90,1559 + pub between: COND_OP,between91,1585 +pub enum COND_OP {COND_OP95,1631 + EQ,EQ96,1650 + NE,NE97,1658 +impl<'a> Value<'a> {Value100,1669 + pub fn unwrap(&self) -> String {unwrap101,1690 + +src/parse/mod.rs,21 +pub mod ast;ast1,0 diff --git a/src/parse/parse.rs b/src/parse/parse.rs new file mode 100644 index 0000000..f24f1cc --- /dev/null +++ b/src/parse/parse.rs @@ -0,0 +1,29 @@ +use super::ast::*; +use crate::lex::tok::*; +use logos::Lexer; + +fn parse_var_declaration(tokens: Lexer) -> Option> { + let tok = None; + match tokens.next() { + Let => { + match tokens.next() { + Identifier => { + let name = tokens.slice(); + println!("{:?}", name); + match tokens.next() { + Equal => { + match tokens.next() { + Number(n) => { + let value = Value::Number(n); + println!("{:?}", value); + return VarDefenition {name, value}; + } + } + } + } + } + } + } + _ => None + } +} diff --git a/src/parse/parse.rs~ b/src/parse/parse.rs~ new file mode 100644 index 0000000..e69de29