summaryrefslogtreecommitdiff
path: root/src/syntactic_token.rs
blob: ee473e26063831165b169886278d46e57593bd78 (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
use crate::*;

pub enum SyntacticTokenType {
    Reference(String),

    LabelDefinition(String),
    MacroDefinition(String),
    MacroTerminator,

    Pad(u16),
    Byte(u8),
    Short(u16),
    Instruction(u8),

    Comment,
}

pub struct SyntacticToken {
    pub r#type: SyntacticTokenType,
    pub source_location: SourceLocation,
    pub error: Option<Error>,
}

impl SyntacticToken {
    // Call when this token is found inside a macro definition.
    pub fn use_in_macro_body(&mut self) {
        match self.r#type {
            SyntacticTokenType::LabelDefinition(..) |
            SyntacticTokenType::MacroDefinition(..) => {
                self.set_error(Error::InvalidTypeInMacroDefinition)
            }
            _ => (),
        };
    }

    pub fn set_error(&mut self, error: Error) {
        self.error = Some(error);
    }

    pub fn is_macro_terminator(&self) -> bool {
        if let SyntacticTokenType::MacroTerminator = self.r#type {true} else {false}
    }
}