From ba8f867bd9110beeb05d54107c0cf26759e83668 Mon Sep 17 00:00:00 2001 From: SimonFJ20 Date: Sun, 22 Jan 2023 03:40:01 +0100 Subject: [PATCH] parser is hard --- src/bong/parser.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/bong/parser.rs b/src/bong/parser.rs index 37bfd36..4ab69f5 100644 --- a/src/bong/parser.rs +++ b/src/bong/parser.rs @@ -27,6 +27,13 @@ pub struct Parser { type ParserError = String; +enum ElementField { + Id(String), + Class(String), + Property(Box), + Value(Node), +} + impl Parser { pub fn new(tokens: Vec) -> Self { Self { tokens, index: 0 } @@ -49,10 +56,20 @@ impl Parser { todo!() } - fn parse_singe_line_field(&mut self) -> Result { + fn parse_singe_line_fields(&mut self) -> Result, ParserError> { + let mut fields = Vec::::new(); match self.current() { + Some(Token::Id(value)) => { + fields.push(ElementField::Id(value.clone())); + self.step(); + } + Some(Token::Class(value)) => { + fields.push(ElementField::Class(value.clone())); + self.step(); + } _ => todo!(), } + Ok(fields) } fn parse_value(&mut self) -> Result {