Broken structure now gets through syntax evaluator.

This commit is contained in:
2024-03-08 18:39:13 -07:00
parent 77c4277625
commit b0cc2fc26b
12 changed files with 389 additions and 50 deletions

View File

@@ -36,12 +36,18 @@ pub enum Token {
#[token("=")]
Equals,
#[token(":")]
Colon,
#[token(";")]
Semi,
#[token(",")]
Comma,
#[token(".")]
Dot,
#[token("(")]
LeftParen,
@@ -54,17 +60,26 @@ pub enum Token {
#[token(">")]
GreaterThan,
#[token("_")]
Underscore,
#[token("{")]
OpenBrace,
#[token("}")]
CloseBrace,
#[token("->")]
SingleArrow,
#[token("λ")]
#[token("lambda")]
#[token("function")]
Function,
#[token("struct")]
Struct,
// Next we take of any reserved words; I always like to put
// these before we start recognizing more complicated regular
// expressions. I don't think it matters, but it works for me.
@@ -93,21 +108,31 @@ pub enum Token {
// letter, too.
#[regex(r"[a-z][a-zA-Z0-9_]*", |v| ArcIntern::new(v.slice().to_string()))]
Variable(ArcIntern<String>),
// Type names; these are like variables, but must start with a capital
// letter.
#[regex(r"[A-Z][a-zA-Z0-9_]*", |v| ArcIntern::new(v.slice().to_string()))]
TypeName(ArcIntern<String>),
}
impl fmt::Display for Token {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Token::Equals => write!(f, "'='"),
Token::Colon => write!(f, "':'"),
Token::Semi => write!(f, "';'"),
Token::Comma => write!(f, "','"),
Token::Dot => write!(f, "'.'"),
Token::LeftParen => write!(f, "'('"),
Token::RightParen => write!(f, "')'"),
Token::LessThan => write!(f, "<"),
Token::GreaterThan => write!(f, ">"),
Token::Underscore => write!(f, "_"),
Token::OpenBrace => write!(f, "{{"),
Token::CloseBrace => write!(f, "}}"),
Token::SingleArrow => write!(f, "->"),
Token::Function => write!(f, "function"),
Token::Struct => write!(f, "struct"),
Token::Print => write!(f, "'print'"),
Token::Operator(c) => write!(f, "'{}'", c),
Token::Number((None, otype, v)) => write!(f, "'{}{}'", v, display_optional_type(otype)),
@@ -131,6 +156,7 @@ impl fmt::Display for Token {
)
}
Token::Variable(s) => write!(f, "'{}'", s),
Token::TypeName(s) => write!(f, "'{}'", s),
}
}
}