Var definition without type
This commit is contained in:
@@ -15,7 +15,8 @@ static_path = { identifier ~ ("::" ~ identifier)* }
|
|||||||
export = { "public" }
|
export = { "public" }
|
||||||
mutable = { "mut" }
|
mutable = { "mut" }
|
||||||
sharp = _{ "#" }
|
sharp = _{ "#" }
|
||||||
var_decl = { type_expr ~ mutable? ~ identifier }
|
var = { "var" }
|
||||||
|
var_decl = { (var | type_expr) ~ mutable? ~ identifier }
|
||||||
semicolon = _{ ";" }
|
semicolon = _{ ";" }
|
||||||
|
|
||||||
// ================= TOP LEVEL =================
|
// ================= TOP LEVEL =================
|
||||||
|
|||||||
+7
-1
@@ -516,7 +516,13 @@ impl From<pest::iterators::Pair<'_, Rule>> for VarDecl {
|
|||||||
Rule::var_decl => {
|
Rule::var_decl => {
|
||||||
let mut inner = pair.into_inner();
|
let mut inner = pair.into_inner();
|
||||||
|
|
||||||
let type_ = Some(inner.next().map(TypeExpr::from).unwrap());
|
let type_ = inner.next().and_then(|pair| {
|
||||||
|
if pair.as_str().trim() == "var" {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(TypeExpr::from(pair))
|
||||||
|
}
|
||||||
|
});
|
||||||
let mutable = if inner.peek().unwrap().as_rule() == Rule::mutable {
|
let mutable = if inner.peek().unwrap().as_rule() == Rule::mutable {
|
||||||
inner.next();
|
inner.next();
|
||||||
true
|
true
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
void main() {
|
void main() {
|
||||||
Vec<i32> iter = vec!(1, 2, 3, 4, 5);
|
var iter = vec!(1, 2, 3, 4, 5);
|
||||||
|
|
||||||
for (i in iter) {
|
for (i in iter) {
|
||||||
println!("{i}");
|
println!("{i}");
|
||||||
|
|||||||
Reference in New Issue
Block a user