Skip to content

Commit

Permalink
refactor parser
Browse files Browse the repository at this point in the history
  • Loading branch information
tahadostifam committed Feb 10, 2025
1 parent e2770a0 commit db4c436
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 37 deletions.
22 changes: 2 additions & 20 deletions examples/main.cy
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
#a = (1 + 2);
#b = "kir" as string;

struct Person {
name: string;
age: i32;

pub fn new(name: string, age: i32): Person {
return Person {
name: "Taha",
age: 17
};
}

fn info(self: *Person) {
cprintf("Name: %s\n", (*self).name);
cprintf("Age: %d\n", (*self).age);
}
}

pub fn main() {
Person.new("Taha", 17).info();
// Person.new("Taha", 17).info();
Person.name.aassad;
}
21 changes: 5 additions & 16 deletions parser/src/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ impl<'a> Parser<'a> {
loc: self.current_location(),
};


if self.peek_token_is(TokenKind::Increment) {
self.next_token();
Expression::UnaryOperator(UnaryOperator {
Expand Down Expand Up @@ -151,9 +150,7 @@ impl<'a> Parser<'a> {

Expression::Literal(Literal::Bool(BoolLiteral { raw, span }))
}
TokenKind::Literal(value) => {
Expression::Literal(value.clone())
}
TokenKind::Literal(value) => Expression::Literal(value.clone()),
TokenKind::Minus | TokenKind::Bang => {
let start = self.current_token.span.start;
let prefix_operator = self.current_token.clone();
Expand Down Expand Up @@ -444,16 +441,7 @@ impl<'a> Parser<'a> {
self.next_token(); // consume method name

let arguments = self.parse_expression_series(TokenKind::RightParen)?.0;
if !self.current_token_is(TokenKind::RightParen) {
return Err(CompileTimeError {
location: self.current_location(),
etype: ParserErrorType::MissingClosingParen,
file_name: Some(self.lexer.file_name.clone()),
code_raw: Some(self.lexer.select(start..self.current_token.span.end)),
verbose: None,
caret: true,
});
}
self.expect_current(TokenKind::RightParen)?;

let method_call = FuncCall {
func_name: method_name,
Expand Down Expand Up @@ -515,6 +503,7 @@ impl<'a> Parser<'a> {
})
}
};
self.next_token();

chains.push(FieldAccessOrMethodCall {
method_call: None,
Expand All @@ -524,8 +513,8 @@ impl<'a> Parser<'a> {
loc: self.current_location(),
}),
});

match self.peek_token.kind {
match self.current_token.kind {
TokenKind::Dot => {
self.next_token(); // consume field_name
continue;
Expand Down
1 change: 0 additions & 1 deletion parser/src/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ impl<'a> Parser<'a> {
self.next_token();
}
//
//

if !self.current_token_is(TokenKind::Semicolon) {
return Err(CompileTimeError {
Expand Down

0 comments on commit db4c436

Please sign in to comment.