summaryrefslogtreecommitdiff
path: root/src/tokens/semantic.rs
blob: a665b9a14c21bf901e03cb195af5dfcc46e287b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use crate::*;


/// The entire semantic program, ready to generate bytecode.
pub struct Program {
    pub definitions: Vec<Definition>,
    pub invocations: Vec<Invocation>,
}

/// A symbol definition.
pub struct Definition {
    pub name: String,
    pub source: SourceSpan,
    pub arguments: Vec<ArgumentDefinition>,
    pub variant: DefinitionVariant,
}

pub struct ArgumentDefinition {
    pub name: String,
    pub source: SourceSpan,
    pub variant: ArgumentDefinitionVariant,
}

pub enum ArgumentDefinitionVariant {
    Integer,
    Block,
}

pub enum DefinitionVariant {
    Integer(IntegerDefinition),
    Block(Vec<BlockToken>),
}

pub struct IntegerDefinition {
    pub source: SourceSpan,
    pub variant: IntegerDefinitionVariant,
}

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 Invocation {
    pub name: String,
    pub source: SourceSpan,
    pub arguments: Vec<InvocationArgument>,
}

pub struct InvocationArgument {
    pub source: SourceSpan,
    pub variant: InvocationArgumentVariant,
}

pub enum InvocationArgumentVariant {
    BlockLiteral(Vec<BlockToken>),
    IntegerLiteral(usize),
    ConstantExpression(ConstantExpression),
    Reference(String),
}