added float and as
This commit is contained in:
+9
-1
@@ -72,7 +72,7 @@ const SYNTAX: [Node; 14] = [
|
|||||||
},
|
},
|
||||||
Node {
|
Node {
|
||||||
token_type: TokenType::Keyword,
|
token_type: TokenType::Keyword,
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^(mut|try|catch|return|fn|let|use|cb|struct|impl|for|in)\b").unwrap())
|
token_regex: Lazy::new(|| Regex::new(r"^(mut|try|catch|return|fn|let|use|cb|struct|impl|for|in|as)\b").unwrap())
|
||||||
},
|
},
|
||||||
Node {
|
Node {
|
||||||
token_type: TokenType::Identifier,
|
token_type: TokenType::Identifier,
|
||||||
@@ -386,6 +386,14 @@ pub fn lex(mut code: &str, use_whitespace: bool, state: LexerState) -> Result<Ve
|
|||||||
column: state.column
|
column: state.column
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
"float" => {
|
||||||
|
tokens.push(Token {
|
||||||
|
token_type: s.token_type,
|
||||||
|
value: "f32".to_string(),
|
||||||
|
line: state.line,
|
||||||
|
column: state.column
|
||||||
|
});
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
tokens.push(Token {
|
tokens.push(Token {
|
||||||
token_type: s.token_type,
|
token_type: s.token_type,
|
||||||
|
|||||||
+1
-9
@@ -114,21 +114,13 @@ impl Parser {
|
|||||||
ast_res.tokens.push(self.tokens[index+1].clone());
|
ast_res.tokens.push(self.tokens[index+1].clone());
|
||||||
ast_res.ast_type = AstType::VariableDeceleration;
|
ast_res.ast_type = AstType::VariableDeceleration;
|
||||||
self.index += 1;
|
self.index += 1;
|
||||||
} else if self.tokens[index+2].token_type==TokenType::Identifier && self.tokens[index+1].token_type==TokenType::Angle {
|
} else if self.tokens.len()-index > 2 && self.tokens[index+2].token_type==TokenType::Identifier && self.tokens[index+1].token_type==TokenType::Angle {
|
||||||
ast_res.tokens.push(self.tokens[index+2].clone());
|
ast_res.tokens.push(self.tokens[index+2].clone());
|
||||||
ast_res.tokens[0].value += "<";
|
ast_res.tokens[0].value += "<";
|
||||||
ast_res.tokens[0].value += self.tokens[index+1].value.as_str();
|
ast_res.tokens[0].value += self.tokens[index+1].value.as_str();
|
||||||
ast_res.tokens[0].value += ">";
|
ast_res.tokens[0].value += ">";
|
||||||
ast_res.ast_type = AstType::VariableDeceleration;
|
ast_res.ast_type = AstType::VariableDeceleration;
|
||||||
self.index += 2;
|
self.index += 2;
|
||||||
} else if self.tokens[index+1].value=="mut" && self.tokens[index+2].token_type==TokenType::Identifier {
|
|
||||||
ast_res.tokens.push(self.tokens[index+2].clone());
|
|
||||||
ast_res.ast_type = AstType::MutVariableDeceleration;
|
|
||||||
self.index += 2;
|
|
||||||
} else if self.tokens[index+1].value=="*" && self.tokens[index+2].token_type==TokenType::Identifier {
|
|
||||||
ast_res.tokens.push(self.tokens[index+2].clone());
|
|
||||||
ast_res.ast_type = AstType::PointerDeceleration;
|
|
||||||
self.index += 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-14
@@ -32,6 +32,18 @@ pub fn transpile(input: String, indent: u32, state: LexerState, options: Options
|
|||||||
while full_ast.tokens.len() > full_ast.index as usize {
|
while full_ast.tokens.len() > full_ast.index as usize {
|
||||||
let ast = full_ast.next();
|
let ast = full_ast.next();
|
||||||
println!("{ast}");
|
println!("{ast}");
|
||||||
|
if last_ast.tokens.len() > 0 {
|
||||||
|
let mut fl = 0;
|
||||||
|
for t in &last_ast.tokens { fl+=t.value.len() }
|
||||||
|
// if ast.tokens[ast.tokens.len()-1].line > last_ast.tokens[last_ast.tokens.len()-1].line {
|
||||||
|
// // result += ("\n".to_string() + " ".repeat(((indent+1) as usize)*2).as_str()).repeat(ast.tokens[ast.tokens.len()-1].line - last_ast.tokens[last_ast.tokens.len()-1].line).as_str();
|
||||||
|
// result += "\n".repeat(ast.tokens[ast.tokens.len()-1].line - last_ast.tokens[last_ast.tokens.len()-1].line).as_str();
|
||||||
|
// }
|
||||||
|
if ast.tokens[ast.tokens.len()-1].column > last_ast.tokens[last_ast.tokens.len()-1].column+fl {
|
||||||
|
result += " ".repeat(ast.tokens[ast.tokens.len()-1].column - (last_ast.tokens[last_ast.tokens.len()-1].column+fl)).as_str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
last_ast = Ast {ast_type: ast.ast_type.clone(), tokens: ast.tokens.clone()};
|
||||||
|
|
||||||
if ast.ast_type == AstType::FunctionDeceleration {
|
if ast.ast_type == AstType::FunctionDeceleration {
|
||||||
result += format!(
|
result += format!(
|
||||||
@@ -95,7 +107,7 @@ pub fn transpile(input: String, indent: u32, state: LexerState, options: Options
|
|||||||
}
|
}
|
||||||
} else if ast.ast_type == AstType::MutVariableDeceleration {
|
} else if ast.ast_type == AstType::MutVariableDeceleration {
|
||||||
result += format!("let mut {}: {}", ast.tokens[1].value, ast.tokens[0].value).as_str();
|
result += format!("let mut {}: {}", ast.tokens[1].value, ast.tokens[0].value).as_str();
|
||||||
} else if ast.tokens.len() == 1 && ast.tokens[0].token_type == TokenType::Round {
|
} else if ast.ast_type == AstType::Other && ast.tokens[0].token_type == TokenType::Round {
|
||||||
result += format!(
|
result += format!(
|
||||||
"({})",
|
"({})",
|
||||||
transpile_round(ast.tokens[0].value.clone(), LexerState {
|
transpile_round(ast.tokens[0].value.clone(), LexerState {
|
||||||
@@ -148,25 +160,23 @@ pub fn transpile(input: String, indent: u32, state: LexerState, options: Options
|
|||||||
result += ";\n";
|
result += ";\n";
|
||||||
result += " ".repeat((indent as usize) * 2).as_str();
|
result += " ".repeat((indent as usize) * 2).as_str();
|
||||||
} else {
|
} else {
|
||||||
if last_ast.tokens.len() > 0 && (
|
// if last_ast.tokens.len() > 0 && (
|
||||||
ast.tokens[0].token_type == TokenType::Identifier ||
|
// last_ast.tokens[last_ast.tokens.len()-1].token_type == TokenType::Identifier ||
|
||||||
ast.tokens[0].token_type == TokenType::Keyword ||
|
// last_ast.tokens[last_ast.tokens.len()-1].token_type == TokenType::Keyword ||
|
||||||
ast.tokens[0].token_type == TokenType::Number
|
// last_ast.tokens[last_ast.tokens.len()-1].token_type == TokenType::Number
|
||||||
) {
|
// ) {
|
||||||
let ltkn = last_ast.tokens[last_ast.tokens.len()-1].token_type;
|
// let ltkn = last_ast.tokens[last_ast.tokens.len()-1].token_type;
|
||||||
if ltkn == TokenType::Identifier ||
|
// if ltkn == TokenType::Identifier ||
|
||||||
ltkn == TokenType::Keyword ||
|
// ltkn == TokenType::Keyword ||
|
||||||
ltkn == TokenType::Number {
|
// ltkn == TokenType::Number {
|
||||||
result += " ";
|
// }
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
result += ast.tokens[0].value.as_str();
|
result += ast.tokens[0].value.as_str();
|
||||||
if options.auto_macro && options.macros.contains(&ast.tokens[0].value.as_str().to_string()) {
|
if options.auto_macro && options.macros.contains(&ast.tokens[0].value.as_str().to_string()) {
|
||||||
result += "!";
|
result += "!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
last_ast = ast;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result = result.trim_end().to_string();
|
result = result.trim_end().to_string();
|
||||||
|
|||||||
Reference in New Issue
Block a user