Skip to content

Commit

Permalink
Merge pull request #68 from LunaStev/develop
Browse files Browse the repository at this point in the history
Refactor and Add Type Handling in AST
  • Loading branch information
LunaStev authored Jan 23, 2025
2 parents 223fc54 + 9cf03ef commit 734c276
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ pub fn extract_parameters(tokens: &mut Peekable<Iter<Token>>) -> Vec<ParameterNo
continue;
};

let param_type = if let Some(Token { token_type: TokenType::TypeInt(_), lexeme, .. }) = tokens.next() {
lexeme.clone()
} else {
"unknown".to_string()
// 타입 추출
let param_type = match tokens.next() {
Some(Token { token_type: TokenType::TypeInt(_), lexeme, .. }) => lexeme.clone(),
Some(Token { token_type: TokenType::TypeFloat(_), lexeme, .. }) => lexeme.clone(),
Some(Token { token_type: TokenType::STRING(_), lexeme, .. }) => lexeme.clone(),
_ => "unknown".to_string(),
};

let initial_value = if let Some(Token { token_type: TokenType::EQUAL, .. }) = tokens.peek() {
Expand Down Expand Up @@ -67,12 +69,13 @@ pub fn extract_body<'a>(tokens: &mut Peekable<Iter<'a, Token>>) -> Vec<ASTNode>

while let Some(token) = tokens.next() {
match &token.token_type {
TokenType::EOF => break,
/*
TokenType::VAR => {
if let Some(ast_node) = parse_var(tokens) {
body.push(ast_node);
}
}
*/
TokenType::PRINTLN => {
if let Some(ast_node) = parse_println(tokens) {
body.push(ast_node);
Expand Down Expand Up @@ -133,7 +136,7 @@ pub fn parse_function(tokens: &mut Peekable<Iter<Token>>) -> Option<ASTNode> {
}))
}


/*
// VAR parsing
fn parse_var(tokens: &mut Peekable<Iter<'_, Token>>) -> Option<ASTNode> {
if let Some(Token { token_type: TokenType::IDENTIFIER(name), .. }) = tokens.next() {
Expand Down Expand Up @@ -226,6 +229,8 @@ fn parse_var(tokens: &mut Peekable<Iter<'_, Token>>) -> Option<ASTNode> {
None
}
*/

// PRINTLN parsing
fn parse_println(tokens: &mut Peekable<Iter<Token>>) -> Option<ASTNode> {
if let Some(Token { token_type: TokenType::LPAREN, .. }) = tokens.next() {
Expand Down

0 comments on commit 734c276

Please sign in to comment.