Skip to content

Commit

Permalink
refactor: simplify token advancing in parser
Browse files Browse the repository at this point in the history
  • Loading branch information
viddrobnic committed May 29, 2024
1 parent b57925c commit b1a0376
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 261 deletions.
10 changes: 7 additions & 3 deletions parser/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::position::Range;
#[derive(Debug, PartialEq, Clone)]
pub struct Program {
pub statements: Vec<Node>,
pub comments: Vec<Comment>,
}

#[derive(Debug, PartialEq, Clone)]
Expand Down Expand Up @@ -63,7 +64,12 @@ pub enum NodeValue {
},
Return(Box<Node>),
Use(String),
Comment(String),
}

#[derive(Debug, PartialEq, Clone)]
pub struct Comment {
pub comment: String,
pub range: Range,
}

#[derive(Debug, PartialEq, Clone)]
Expand Down Expand Up @@ -161,7 +167,6 @@ impl NodeValue {
NodeValue::Break => NodeKind::Statement,
NodeValue::Continue => NodeKind::Statement,
NodeValue::Return(_) => NodeKind::Statement,
NodeValue::Comment(_) => NodeKind::Statement,
_ => NodeKind::Expression,
}
}
Expand Down Expand Up @@ -293,7 +298,6 @@ impl Display for NodeValue {
}
NodeValue::Return(ret) => write!(f, "return {ret}"),
NodeValue::Use(name) => write!(f, "use {name}"),
NodeValue::Comment(comment) => write!(f, "// {comment}"),
}
}
}
Loading

0 comments on commit b1a0376

Please sign in to comment.