diff --git a/std/jule/ast/node.jule b/std/jule/ast/node.jule index 69724a93f..ef8af4e9d 100644 --- a/std/jule/ast/node.jule +++ b/std/jule/ast/node.jule @@ -170,6 +170,7 @@ pub type ExprData: any // Expression. pub struct Expr { pub token: Token + pub range: bool // Packed in parentheses. // Possible types: // - &TupleExpr @@ -221,7 +222,7 @@ impl LitExpr { // Unsafe expression. pub struct UnsafeExpr { pub token: Token // Token of unsafe keyword. - pub expr: ExprData + pub expr: &Expr } // Co expression. @@ -247,19 +248,19 @@ impl IdentExpr { // Unary expression. pub struct UnaryExpr { pub op: Token - pub expr: ExprData + pub expr: &Expr } // Variadiced expression. pub struct VariadicExpr { pub token: Token - pub expr: ExprData + pub expr: &Expr } // Casting expression. pub struct CastExpr { pub kind: &TypeDecl - pub expr: ExprData + pub expr: &Expr } // Namespace identifier selection expression. @@ -271,14 +272,14 @@ pub struct NsSelectionExpr { // Object sub identifier selection expression. pub struct SubIdentExpr { pub is_self: bool // True if root selector is "self" keyword. - pub expr: ExprData // Selected object. + pub expr: &Expr // Selected object. pub ident: Token // TOken of selected identifier. } // Binary operation. pub struct BinopExpr { - pub left: ExprData - pub right: ExprData + pub left: &Expr + pub right: &Expr pub op: Token } @@ -308,7 +309,7 @@ impl FnCallExpr { // Field-Expression pair. pub struct FieldExprPair { pub field: Token // Field identifier token. - pub expr: ExprData + pub expr: &Expr } impl FieldExprPair { @@ -339,8 +340,8 @@ impl BraceLit { // Key-value pair expression. pub struct KeyValPair { - pub key: ExprData - pub val: ExprData + pub key: &Expr + pub val: &Expr pub colon: Token } @@ -348,7 +349,7 @@ pub struct KeyValPair { // Also represents array initiating expression. pub struct SliceExpr { pub token: Token - pub elems: []ExprData + pub elems: []&Expr } impl SliceExpr { @@ -361,24 +362,24 @@ impl SliceExpr { // Indexing expression. pub struct IndexingExpr { pub token: Token - pub expr: ExprData // Value expression to indexing. - pub index: ExprData // Index value expression. + pub expr: &Expr // Value expression to indexing. + pub index: &Expr // Index value expression. } // Slicing expression. pub struct SlicingExpr { pub token: Token - pub expr: ExprData // Value expression to slicing. - pub start: ExprData // Start index value expression. - pub to: ExprData // To index value expression. + pub expr: &Expr // Value expression to slicing. + pub start: &Expr // Start index value expression. + pub to: &Expr // To index value expression. } // Ternary expression. pub struct TernaryExpr { pub token: Token - pub condition: ExprData - pub true_expr: ExprData - pub false_expr: ExprData + pub condition: &Expr + pub true_expr: &Expr + pub false_expr: &Expr } // Generic type declaration. diff --git a/std/jule/parser/expr.jule b/std/jule/parser/expr.jule index 7a4d5857b..bdf98edb2 100644 --- a/std/jule/parser/expr.jule +++ b/std/jule/parser/expr.jule @@ -308,7 +308,7 @@ impl ExprBuilder { ret &UnaryExpr{ op: op, - expr: self.build(tokens), + expr: self.build_from_tokens(tokens), } } @@ -323,7 +323,7 @@ impl ExprBuilder { } ret &SubIdentExpr{ ident: ident_token, - expr: self.build(tokens), + expr: self.build_from_tokens(tokens), } } @@ -383,7 +383,7 @@ impl ExprBuilder { tokens = tokens[:tokens.len-1] // Remove variadic operator token. ret &VariadicExpr{ token: token, - expr: self.build(tokens), + expr: self.build_from_tokens(tokens), } } @@ -410,7 +410,7 @@ impl ExprBuilder { ret nil } - fn build_between_parentheses(mut self, mut tokens: []Token): ExprData { + fn build_between_parentheses(mut self, mut tokens: []Token): &Expr { let token = tokens[0] tokens = tokens[1 : tokens.len-1] // Remove parentheses. if tokens.len == 0 { @@ -418,7 +418,9 @@ impl ExprBuilder { self.push_suggestion(LogMsg.EmptyParentNotValid) ret nil } - ret self.build(tokens) + let mut expr = self.build_from_tokens(tokens) + expr.range = true + ret expr } fn try_build_cast(mut self, mut &tokens: []Token): &CastExpr { @@ -486,7 +488,7 @@ impl ExprBuilder { ret nil } expr_tokens = expr_tokens[:j] - cast.expr = self.build(expr_tokens) + cast.expr = self.build_from_tokens(expr_tokens) } } ret cast @@ -614,7 +616,7 @@ impl ExprBuilder { } ret &UnsafeExpr{ token: token, - expr: self.build_from_tokens(range_tokens).kind, + expr: self.build_from_tokens(range_tokens), } } @@ -699,7 +701,7 @@ impl ExprBuilder { field: tokens[0], } tokens = tokens[2:] // Remove field identifier and colon tokens. - pair.expr = self.build_from_tokens(tokens).kind + pair.expr = self.build_from_tokens(tokens) ret pair } @@ -756,8 +758,8 @@ impl ExprBuilder { if l != nil { ret &KeyValPair{ colon: tokens[l.len], - key: self.build_from_tokens(l).kind, - val: self.build_from_tokens(r).kind, + key: self.build_from_tokens(l), + val: self.build_from_tokens(r), } } ret self.build_from_tokens(tokens) @@ -850,12 +852,12 @@ impl ExprBuilder { ret slc } - slc.elems = make([]ExprData, 0, parts.len) + slc.elems = make([]&Expr, 0, parts.len) for (_, mut p) in parts { if p.len == 0 { continue } - slc.elems = append(slc.elems, self.build_from_tokens(p).kind) + slc.elems = append(slc.elems, self.build_from_tokens(p)) } ret slc @@ -878,8 +880,8 @@ impl ExprBuilder { } ret &IndexingExpr{ token: error_token, - expr: expr.kind, - index: index.kind, + expr: expr, + index: index, } } @@ -887,17 +889,17 @@ impl ExprBuilder { &colon: int, mut &error_token: Token): &SlicingExpr { let mut slc = &SlicingExpr{ token: error_token, - expr: self.build_from_tokens(expr_tokens).kind, + expr: self.build_from_tokens(expr_tokens), } let mut start_expr_tokens = slicing_tokens[:colon] if start_expr_tokens.len > 0 { - slc.start = self.build_from_tokens(start_expr_tokens).kind + slc.start = self.build_from_tokens(start_expr_tokens) } let mut to_expr_tokens = slicing_tokens[colon+1:] if to_expr_tokens.len > 0 { - slc.to = self.build_from_tokens(to_expr_tokens).kind + slc.to = self.build_from_tokens(to_expr_tokens) } ret slc @@ -941,7 +943,7 @@ impl ExprBuilder { self.push_err(ter.token, LogMsg.MissingExpr) } - ter.condition = self.build_kind(expr_tokens) + ter.condition = self.build_from_tokens(expr_tokens) let mut i = expr_tokens.len let mut true_expr = range(i, TokenKind.LBrace, TokenKind.RBrace, tokens) @@ -980,8 +982,8 @@ impl ExprBuilder { self.push_err(tokens[i], LogMsg.InvalidSyntax) } - ter.true_expr = self.build_kind(true_expr) - ter.false_expr = self.build_kind(false_expr) + ter.true_expr = self.build_from_tokens(true_expr) + ter.false_expr = self.build_from_tokens(false_expr) ret ter } @@ -1070,8 +1072,8 @@ impl ExprBuilder { ret nil } ret &BinopExpr{ - left: self.build(left_tokens), - right: self.build(right_tokens), + left: self.build_from_tokens(left_tokens), + right: self.build_from_tokens(right_tokens), op: tokens[i], } } diff --git a/std/jule/sema/eval.jule b/std/jule/sema/eval.jule index 9440d8427..23dfe3d94 100644 --- a/std/jule/sema/eval.jule +++ b/std/jule/sema/eval.jule @@ -797,9 +797,9 @@ impl Eval { let mut filled = false if s.elems.len == 2 { - match type s.elems[1] { + match type s.elems[1].kind { | &VariadicExpr: - if (&VariadicExpr)(s.elems[1]).expr != nil { + if (&VariadicExpr)(s.elems[1].kind).expr != nil { break } // Filled. @@ -1054,11 +1054,11 @@ impl Eval { } fn push_generics_from_index_data(mut &self, mut &decl: &IdentTypeDecl, mut &i: &IndexingExpr): bool { - match type i.index { + match type i.index.kind { | &UnaryExpr: // Unary eval catches type declarations. // Therefore use unary eval algorithm for eval related type declarations. - let mut d = self.eval_unary((&UnaryExpr)(i.index)) + let mut d = self.eval_unary((&UnaryExpr)(i.index.kind)) if !d.decl { self.push_err(i.token, LogMsg.InvalidSyntax) ret false @@ -1067,9 +1067,9 @@ impl Eval { kind: d.kind, }) | &TypeDecl: - decl.generics = append(decl.generics, (&TypeDecl)(i.index)) + decl.generics = append(decl.generics, (&TypeDecl)(i.index.kind)) | &IdentExpr: - let mut expr = (&IdentExpr)(i.index) + let mut expr = (&IdentExpr)(i.index.kind) decl.generics = append(decl.generics, &TypeDecl{ kind: &IdentTypeDecl{ token: expr.token, @@ -1077,7 +1077,7 @@ impl Eval { } }) | &TupleExpr: - for (_, mut expr) in (&TupleExpr)(i.index).expr { + for (_, mut expr) in (&TupleExpr)(i.index.kind).expr { match type expr.kind { | &TypeDecl: decl.generics = append(decl.generics, (&TypeDecl)(expr.kind)) @@ -1101,16 +1101,16 @@ impl Eval { fn eval_ident_decl_from_indexing(mut &self, mut &d: &Data, mut &i: &IndexingExpr): &Data { let mut tdecl = &TypeDecl{} let mut decl: &IdentTypeDecl = nil - match type i.expr { + match type i.expr.kind { | &IdentExpr: - let mut expr = (&IdentExpr)(i.expr) + let mut expr = (&IdentExpr)(i.expr.kind) decl = &IdentTypeDecl{ token: expr.token, ident: expr.ident, } tdecl.kind = decl | &NsSelectionExpr: - let mut expr = (&NsSelectionExpr)(i.expr) + let mut expr = (&NsSelectionExpr)(i.expr.kind) decl = &IdentTypeDecl{ token: expr.ident, ident: expr.ident.kind, @@ -2964,6 +2964,8 @@ impl Eval { fn eval_expr_kind(mut &self, mut kind: ExprData): &Data { let mut d: &Data = nil match type kind { + | &Expr: + d = self.eval_expr_kind((&Expr)(kind).kind) | &LitExpr: d = self.eval_lit((&LitExpr)(kind)) | &IdentExpr: diff --git a/std/jule/sema/scope.jule b/std/jule/sema/scope.jule index e343f557c..308a9c34b 100644 --- a/std/jule/sema/scope.jule +++ b/std/jule/sema/scope.jule @@ -1377,7 +1377,7 @@ impl ScopeChecker { self.check_ret_multi_assign(a) ret | &UnsafeExpr: - match type (&UnsafeExpr)(a.right.kind).expr { + match type (&UnsafeExpr)(a.right.kind).expr.kind { | &FnCallExpr: self.check_ret_multi_assign(a) ret diff --git a/std/jule/sema/type2.jule b/std/jule/sema/type2.jule index f55bbf4c2..9114bb6bd 100644 --- a/std/jule/sema/type2.jule +++ b/std/jule/sema/type2.jule @@ -814,16 +814,17 @@ impl StructLitChecker { match type expr { | &KeyValPair: let mut pair = (&KeyValPair)(expr) - match type pair.key { + match type pair.key.kind { | &IdentExpr: // Ok + break |: self.push_err(pair.colon, LogMsg.InvalidSyntax) ok = false continue } exprs[i] = &FieldExprPair{ - field: (&IdentExpr)(pair.key).token, + field: pair.key.token, expr: pair.val, } }