From ce47e3b24ea37748b809cb5c53b217b6474e0fd3 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 11 Feb 2025 15:48:02 +1300 Subject: Define semantic types --- src/environment.rs | 2 +- src/parsers/semantic.rs | 19 ------------- src/tokens/semantic.rs | 73 +++++++++++++++++++++++++------------------------ 3 files changed, 38 insertions(+), 56 deletions(-) diff --git a/src/environment.rs b/src/environment.rs index 006b45b..d88e1b5 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -54,7 +54,7 @@ impl Scope { pub enum Definition { Integer(IntegerDefinition), - Block(BlockLiteral), + Block, } pub enum IntegerDefinition { diff --git a/src/parsers/semantic.rs b/src/parsers/semantic.rs index 94ed70c..6576b44 100644 --- a/src/parsers/semantic.rs +++ b/src/parsers/semantic.rs @@ -1,21 +1,2 @@ use crate::*; - -pub struct SemanticParser { - pub syntactic_tokens: Vec, - pub semantic_tokens: Vec, -} - - -impl SemanticParser { - pub fn new(syntactic_tokens: Vec) -> Self { - Self { - syntactic_tokens, - semantic_tokens: Vec::new(), - } - } - - pub fn parse(&mut self) { - todo!() - } -} diff --git a/src/tokens/semantic.rs b/src/tokens/semantic.rs index ed53685..a665b9a 100644 --- a/src/tokens/semantic.rs +++ b/src/tokens/semantic.rs @@ -1,60 +1,62 @@ use crate::*; -pub enum SemanticToken { - MacroDefinition, - Invocation, +/// The entire semantic program, ready to generate bytecode. +pub struct Program { + pub definitions: Vec, + pub invocations: Vec, } -pub struct Invocation { +/// A symbol definition. +pub struct Definition { pub name: String, - pub bytecode: BytecodeSpan, - pub arguments: Vec, -} - -pub struct BlockLiteral { - pub tokens: Vec, + pub source: SourceSpan, + pub arguments: Vec, + pub variant: DefinitionVariant, } -pub struct BlockToken { +pub struct ArgumentDefinition { + pub name: String, pub source: SourceSpan, - pub bytecode: BytecodeSpan, - pub variant: BlockTokenVariant, + pub variant: ArgumentDefinitionVariant, } -pub enum BlockTokenVariant { - Invocation(Invocation), - Word(PackedBinaryLiteral), +pub enum ArgumentDefinitionVariant { + Integer, + Block, } -pub struct MacroDefinition { - pub name: String, - pub arguments: Vec, - pub body: BlockLiteral, +pub enum DefinitionVariant { + Integer(IntegerDefinition), + Block(Vec), } -// -------------------------------------------------------------------------- // - -pub struct SemanticParseError { +pub struct IntegerDefinition { pub source: SourceSpan, - pub variant: SemanticParseErrorVariant, + pub variant: IntegerDefinitionVariant, } -pub enum SemanticParseErrorVariant { +pub enum IntegerDefinitionVariant { + Literal(usize), + Constant(ConstantExpression), + Reference(String), +} +pub struct BlockToken { + pub source: SourceSpan, + pub variant: BlockTokenVariant, } -// -------------------------------------------------------------------------- // +pub enum BlockTokenVariant { + Invocation(Invocation), + Comment(String), + Word(PackedBinaryLiteral), +} -pub struct DefinitionArgument { +pub struct Invocation { pub name: String, pub source: SourceSpan, - pub variant: DefinitionArgumentVariant, -} - -pub enum DefinitionArgumentVariant { - Integer, - Block, + pub arguments: Vec, } pub struct InvocationArgument { @@ -63,9 +65,8 @@ pub struct InvocationArgument { } pub enum InvocationArgumentVariant { - BlockLiteral(BlockLiteral), + BlockLiteral(Vec), IntegerLiteral(usize), ConstantExpression(ConstantExpression), - Invocation(Invocation), + Reference(String), } - -- cgit v1.2.3-70-g09d2