rust bing bong
This commit is contained in:
parent
cfdfc42918
commit
91b2f4b43f
@ -103,15 +103,25 @@ MultiLineWhitespace -> [ \t\n\r\f\v]+
|
||||
SingleLineComment -> \/\/[^\n]+
|
||||
MultiLineComment -> \/\*.*?\*\/
|
||||
|
||||
Name -> [a-zA-Z_][a-zA-Z0-9_]*
|
||||
Id -> #[a-zA-Z0-9_]+
|
||||
Class \.[a-zA-Z0-9_]+
|
||||
|
||||
Int -> [0-9]+
|
||||
Float -> [0-9]+\.[0-9]*
|
||||
Int -> [0-9]+
|
||||
String -> "<sequence of optionally escaped characters \
|
||||
and escaped special character placeholders \
|
||||
terminated by an unescaped '"'>
|
||||
Null -> "null"
|
||||
False -> "false"
|
||||
True -> "true"
|
||||
|
||||
Name -> [a-zA-Z_][a-zA-Z0-9_]*
|
||||
Id -> #[a-zA-Z0-9_]+
|
||||
Class \.[a-zA-Z0-9_]+
|
||||
|
||||
LBrace -> "("
|
||||
RBrace -> ")"
|
||||
LBracket -> "["
|
||||
RBracket -> "]"
|
||||
|
||||
Equal -> "="
|
||||
Colon -> ":"
|
||||
SemiColon -> ";"
|
||||
Comma -> ","
|
||||
|
68
src/bong/lexer.rs
Normal file
68
src/bong/lexer.rs
Normal file
@ -0,0 +1,68 @@
|
||||
use std::{iter::Peekable, str::Chars};
|
||||
|
||||
pub enum TokenType {
|
||||
SinglelineWhitespace,
|
||||
MultilineWhitespace,
|
||||
SinglelineComment,
|
||||
MultilineComment,
|
||||
|
||||
Name,
|
||||
Id,
|
||||
Class,
|
||||
|
||||
Int,
|
||||
Float,
|
||||
String,
|
||||
Null,
|
||||
False,
|
||||
True,
|
||||
|
||||
LBrace,
|
||||
RBrace,
|
||||
LBracket,
|
||||
RBracket,
|
||||
|
||||
Equal,
|
||||
Colon,
|
||||
SemiColon,
|
||||
Comma,
|
||||
}
|
||||
|
||||
pub struct Token<'a> {
|
||||
token_type: TokenType,
|
||||
value: &'a str,
|
||||
line: u32,
|
||||
col: u32,
|
||||
}
|
||||
|
||||
pub struct LexerError {
|
||||
line: u32,
|
||||
col: u32,
|
||||
message: String,
|
||||
}
|
||||
|
||||
impl LexerError {
|
||||
pub fn new(line: u32, col: u32, message: String) -> Self {
|
||||
Self { line, col, message }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Lexer<'a> {
|
||||
phantom: std::marker::PhantomData<&'a u32>,
|
||||
}
|
||||
|
||||
impl<'a> Lexer<'a> {
|
||||
pub fn new(text: &'a str) -> Self {
|
||||
Self {
|
||||
phantom: std::marker::PhantomData {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for Lexer<'a> {
|
||||
type Item = Result<Token<'a>, String>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
todo!()
|
||||
}
|
||||
}
|
2
src/bong/mod.rs
Normal file
2
src/bong/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
mod lexer;
|
||||
mod parser;
|
29
src/bong/parser.rs
Normal file
29
src/bong/parser.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use std::iter::Map;
|
||||
|
||||
use crate::bong::lexer::Lexer;
|
||||
|
||||
pub enum Node {
|
||||
Element {
|
||||
name: String,
|
||||
ids: Vec<String>,
|
||||
classes: Vec<String>,
|
||||
properties: Map<String, Box<Node>>,
|
||||
values: Vec<Node>,
|
||||
},
|
||||
Object(Map<String, Box<Node>>),
|
||||
Array(Vec<Node>),
|
||||
Int(i64),
|
||||
Float(f64),
|
||||
String(String),
|
||||
Bool(bool),
|
||||
}
|
||||
|
||||
pub struct Parser<'a> {
|
||||
lexer: Lexer<'a>,
|
||||
}
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
pub fn new(lexer: Lexer<'a>) -> Self {
|
||||
Self { lexer }
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
mod bong;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user