Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 2 additions & 23 deletions compiler/pipec-ast/src/ast/asttree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,12 @@ use pipec_file_loader::FileId;

#[derive(Debug, Clone)]
pub struct ASTTree {
stream: Vec<ASTNode>,
pos: usize,
pub stream: Vec<ASTNode>,
pub id: FileId,
}

impl ASTTree {
pub fn new(stream: Vec<ASTNode>, id: FileId) -> Self {
Self { stream, pos: 0, id }
}
pub fn current_node(&mut self) -> Option<&ASTNode> {
self.stream.get(self.pos)
}
pub fn next_node(&mut self) -> Option<ASTNode> {
self.pos += 1;
self.stream.get(self.pos).cloned()
}
pub fn peek(&mut self) -> Option<&ASTNode> {
self.stream.get(self.pos)
}
// pub fn from_vec(vec: Vec<ASTNode>) -> Self {
// Self {
// stream: vec,
// pos: 0,
// }
// }

pub fn reset(&mut self) {
self.pos = 0;
Self { stream, id }
}
}
24 changes: 7 additions & 17 deletions compiler/pipec-ast/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ impl<'this> ASTGenerator<'this> {

#[inline]
pub(crate) fn advance_stream(&mut self) -> Option<Token> {
println!("{:#?}", self.peek_stream());
self.tokens.next_token()
}
#[inline]
Expand All @@ -82,7 +81,6 @@ impl<'this> ASTGenerator<'this> {
Token::ImplementKeyword => self.consume_implement_keyword(),
Token::AtSign => self.consume_attributes(),
_v => {
println!("{_v:#?}");
todo!();
}
},
Expand Down Expand Up @@ -450,15 +448,11 @@ impl<'this> ASTGenerator<'this> {
self.consume_whitespace();
let params = self.consume_function_parameters();
self.consume_whitespace();
let mut out_type = None;
if self.next_is(Token::FatArrow) {
self.advance_stream();
self.consume_whitespace();
out_type = Some(self.consume_a_path());
}
self.must(Token::FatArrow);
self.consume_whitespace();
let out_type = self.consume_a_path();
self.consume_whitespace();
let block = self.consume_function_block();

ASTNode::FunctionDeclaration {
name,
params,
Expand Down Expand Up @@ -538,7 +532,6 @@ impl<'this> ASTGenerator<'this> {

#[inline]
pub(crate) fn must(&mut self, val: Token) {
println!("should have {:#?}", self.peek_stream());
if self.advance_stream() != Some(val) {
// TODO : compiler error
unreachable!()
Expand Down Expand Up @@ -652,7 +645,6 @@ impl<'this> ASTGenerator<'this> {
};
}

println!("{path1:#?},{path2:#?}");
unreachable!()
}

Expand Down Expand Up @@ -1020,7 +1012,6 @@ impl<'this> ASTGenerator<'this> {
Some(Token::SwitchKeyword) => self.consume_switch_expression(),

_v => {
println!("{_v:#?}");
//TODO : compiler error
unreachable!();
}
Expand Down Expand Up @@ -1091,7 +1082,6 @@ impl<'this> ASTGenerator<'this> {
#[inline]
pub(crate) fn consume_switch_arm(&mut self) -> SwitchArm {
let expr = self.consume_an_expression();
println!("arm lhs = {expr:#?}");
let lhs = Box::new(expr);
self.consume_whitespace();
self.must(Token::ThinArrow);
Expand Down Expand Up @@ -1298,7 +1288,7 @@ pub enum ASTNode {
generics: Generics,
params: FunctionDeclarationParameters,
block: Block,
out_type: Option<Path>,
out_type: Path,
},
ViewportDeclaration {
name: Span,
Expand Down Expand Up @@ -1399,7 +1389,7 @@ pub struct FragmentsBlock {
block: Block,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Hash)]
pub enum FunctionBlockStatements {
MutableVariableDeclaration {
variablename: Span,
Expand All @@ -1425,7 +1415,7 @@ pub enum FunctionBlockStatements {
},
}

#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Clone, Hash)]
pub enum Exported {
ColorBuiltin,
PositionBuiltin,
Expand Down Expand Up @@ -1495,7 +1485,7 @@ pub enum VariableType {
Final,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Hash)]
#[allow(unused)]
pub struct Block(Vec<FunctionBlockStatements>);

Expand Down
Loading