lang: basic parser

This commit is contained in:
Schrottkatze 2024-04-03 00:08:00 +02:00
commit ca84af4e1b
No known key found for this signature in database
11 changed files with 362 additions and 33 deletions

View file

@ -1,8 +1,15 @@
use logos::Logos;
#[derive(Logos, Debug, PartialEq, Eq)]
#[derive(Logos, Debug, PartialEq, Eq, Clone)]
#[logos(skip r"[ \t\n\f]+")]
pub enum Token<'a> {
// hack!
// this isn't actually supposed to be in the language.
// i just can't figure out how to automatically choose between a top level declaration
// or a top level expression
// so a declaration needs the keyword def until i can figure this out
#[token("def")]
Def,
#[regex("[a-zA-Z0-9_\\-]+", |lex| lex.slice())]
Word(&'a str),
#[regex("\\$[a-zA-Z0-9_\\-]+", |lex| &lex.slice()[1..])]
@ -27,6 +34,8 @@ pub enum Token<'a> {
Equals,
#[token(":")]
Colon,
#[token(";")]
SemiColon,
#[token("[")]
BracketOpen,
#[token("]")]