From 65cfb92d145aa8a75f44be0b4f5b51a7e094a00f Mon Sep 17 00:00:00 2001 From: Artemis Rosman <73006620+rozukke@users.noreply.github.com> Date: Sat, 10 Aug 2024 15:01:54 +1000 Subject: [PATCH] Layout parser --- src/lexer/mod.rs | 2 +- src/main.rs | 1 + src/parser.rs | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/parser.rs diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index a51841a..6604850 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs @@ -5,7 +5,7 @@ use crate::lexer::cursor::Cursor; use crate::span::{Idx, Span}; use crate::symbol::Register; -mod cursor; +pub mod cursor; #[derive(Debug)] pub struct Token { diff --git a/src/main.rs b/src/main.rs index 3b74b27..9600e74 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use lexer::{tokenize, TokenKind}; mod lexer; mod ops; +mod parser; mod runtime; mod span; mod symbol; diff --git a/src/parser.rs b/src/parser.rs new file mode 100644 index 0000000..e865b62 --- /dev/null +++ b/src/parser.rs @@ -0,0 +1,37 @@ +use crate::lexer::{cursor::Cursor, TokenKind}; + +/// Transforms token stream into 'AST' +pub struct Parser<'source> { + /// Reference to the source file + src: &'source str, + /// Used to parse tokens + cur: Cursor<'source>, +} + +impl<'a> From<&'a str> for Parser<'a> { + fn from(value: &'a str) -> Self { + Parser { + src: value, + cur: Cursor::new(value), + } + } +} + +impl<'source> Parser<'source> { + pub fn parse(&self) { + // First, check that there is an .orig directive with an appropriate value. + todo!() + } + + pub fn expect(kind: TokenKind) { + todo!() + } + + pub fn parse_direc(&self) { + todo!() + } + + pub fn parse_op(&self) { + todo!() + } +}