Skip to content

Commit

Permalink
vintLang vscode formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
tacheraSasi committed Nov 24, 2024
1 parent 8c1a3ff commit 30d28b8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 24 deletions.
45 changes: 30 additions & 15 deletions evaluator/assignEqual.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func evalAssignEqual(node *ast.AssignEqual, env *object.Environment) object.Obje
v := float64(arg.Value) + val.Value
return env.Set(node.Left.Token.Literal, &object.Float{Value: v})
default:
return newError("Line %d: Huwezi kutumia '+=' kujumlisha %v na %v", node.Token.Line, arg.Type(), val.Type())
// Check for invalid operation between different types
return newError("Line %d: Cannot use '+=' to add %v and %v", node.Token.Line, arg.Type(), val.Type())
}
case *object.Float:
switch val := value.(type) {
Expand All @@ -41,18 +42,21 @@ func evalAssignEqual(node *ast.AssignEqual, env *object.Environment) object.Obje
v := arg.Value + val.Value
return env.Set(node.Left.Token.Literal, &object.Float{Value: v})
default:
return newError("Line %d: Huwezi kutumia '+=' kujumlisha %v na %v", node.Token.Line, arg.Type(), val.Type())
// Check for invalid operation between different types
return newError("Line %d: Cannot use '+=' to add %v and %v", node.Token.Line, arg.Type(), val.Type())
}
case *object.String:
switch val := value.(type) {
case *object.String:
v := arg.Value + val.Value
return env.Set(node.Left.Token.Literal, &object.String{Value: v})
default:
return newError("Line %d: Huwezi kutumia '+=' kwa %v na %v", node.Token.Line, arg.Type(), val.Type())
// Check for invalid operation for non-strings
return newError("Line %d: Cannot use '+=' with %v and %v", node.Token.Line, arg.Type(), val.Type())
}
default:
return newError("Line %d: Huwezi kutumia '+=' na %v", node.Token.Line, arg.Type())
// Check for invalid operation on unsupported types
return newError("Line %d: Cannot use '+=' with %v", node.Token.Line, arg.Type())
}
case "-=":
switch arg := left.(type) {
Expand All @@ -65,7 +69,8 @@ func evalAssignEqual(node *ast.AssignEqual, env *object.Environment) object.Obje
v := float64(arg.Value) - val.Value
return env.Set(node.Left.Token.Literal, &object.Float{Value: v})
default:
return newError("Line %d: Huwezi kutumia '-=' kujumlisha %v na %v", node.Token.Line, arg.Type(), val.Type())
// Check for invalid operation between different types
return newError("Line %d: Cannot use '-=' to subtract %v and %v", node.Token.Line, arg.Type(), val.Type())
}
case *object.Float:
switch val := value.(type) {
Expand All @@ -76,10 +81,12 @@ func evalAssignEqual(node *ast.AssignEqual, env *object.Environment) object.Obje
v := arg.Value - val.Value
return env.Set(node.Left.Token.Literal, &object.Float{Value: v})
default:
return newError("Line %d: Huwezi kutumia '-=' kujumlisha %v na %v", node.Token.Line, arg.Type(), val.Type())
// Check for invalid operation between different types
return newError("Line %d: Cannot use '-=' to subtract %v and %v", node.Token.Line, arg.Type(), val.Type())
}
default:
return newError("Line %d: Huwezi kutumia '-=' na %v", node.Token.Line, arg.Type())
// Check for invalid operation on unsupported types
return newError("Line %d: Cannot use '-=' with %v", node.Token.Line, arg.Type())
}
case "*=":
switch arg := left.(type) {
Expand All @@ -95,7 +102,8 @@ func evalAssignEqual(node *ast.AssignEqual, env *object.Environment) object.Obje
v := strings.Repeat(val.Value, int(arg.Value))
return env.Set(node.Left.Token.Literal, &object.String{Value: v})
default:
return newError("Line %d: Huwezi kutumia '*=' kujumlisha %v na %v", node.Token.Line, arg.Type(), val.Type())
// Check for invalid operation between different types
return newError("Line %d: Cannot use '*=' to multiply %v and %v", node.Token.Line, arg.Type(), val.Type())
}
case *object.Float:
switch val := value.(type) {
Expand All @@ -106,18 +114,21 @@ func evalAssignEqual(node *ast.AssignEqual, env *object.Environment) object.Obje
v := arg.Value * val.Value
return env.Set(node.Left.Token.Literal, &object.Float{Value: v})
default:
return newError("Line %d: Huwezi kutumia '*=' kujumlisha %v na %v", node.Token.Line, arg.Type(), val.Type())
// Check for invalid operation between different types
return newError("Line %d: Cannot use '*=' to multiply %v and %v", node.Token.Line, arg.Type(), val.Type())
}
case *object.String:
switch val := value.(type) {
case *object.Integer:
v := strings.Repeat(arg.Value, int(val.Value))
return env.Set(node.Left.Token.Literal, &object.String{Value: v})
default:
return newError("Line %d: Huwezi kutumia '+=' kwa %v na %v", node.Token.Line, arg.Type(), val.Type())
// Check for invalid operation for non-integer multiplications
return newError("Line %d: Cannot use '*=' with %v and %v", node.Token.Line, arg.Type(), val.Type())
}
default:
return newError("Line %d: Huwezi kutumia '*=' na %v", node.Token.Line, arg.Type())
// Check for invalid operation on unsupported types
return newError("Line %d: Cannot use '*=' with %v", node.Token.Line, arg.Type())
}
case "/=":
switch arg := left.(type) {
Expand All @@ -130,7 +141,8 @@ func evalAssignEqual(node *ast.AssignEqual, env *object.Environment) object.Obje
v := float64(arg.Value) / val.Value
return env.Set(node.Left.Token.Literal, &object.Float{Value: v})
default:
return newError("Line %d: Huwezi kutumia '/=' kujumlisha %v na %v", node.Token.Line, arg.Type(), val.Type())
// Check for invalid operation between different types
return newError("Line %d: Cannot use '/=' to divide %v and %v", node.Token.Line, arg.Type(), val.Type())
}
case *object.Float:
switch val := value.(type) {
Expand All @@ -141,12 +153,15 @@ func evalAssignEqual(node *ast.AssignEqual, env *object.Environment) object.Obje
v := arg.Value / val.Value
return env.Set(node.Left.Token.Literal, &object.Float{Value: v})
default:
return newError("Line %d: Huwezi kutumia '/=' kujumlisha %v na %v", node.Token.Line, arg.Type(), val.Type())
// Check for invalid operation between different types
return newError("Line %d: Cannot use '/=' to divide %v and %v", node.Token.Line, arg.Type(), val.Type())
}
default:
return newError("Line %d: Huwezi kutumia '/=' na %v", node.Token.Line, arg.Type())
// Check for invalid operation on unsupported types
return newError("Line %d: Cannot use '/=' with %v", node.Token.Line, arg.Type())
}
default:
return newError("Line %d: Operesheni Haifahamiki %s", node.Token.Line, node.Token.Literal)
// Check for an unknown operation
return newError("Line %d: Unknown operation %s", node.Token.Line, node.Token.Literal)
}
}
9 changes: 7 additions & 2 deletions evaluator/at.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import (
"github.com/ekilie/vint-lang/object"
)

// evalAt handles the evaluation of the "@" expression.
// It checks if the "@" symbol is available in the current environment and returns its value.
// If not found, it returns an error indicating that the scope is invalid.
func evalAt(node *ast.At, env *object.Environment) object.Object {
// Checks if "@" exists in the environment
if at, ok := env.Get("@"); ok {
return at
return at // Return the value associated with "@"
}
return newError("Iko nje ya scope")
// Returns an error if "@" is not found in the scope
return newError("Out of scope")
}
18 changes: 11 additions & 7 deletions extensions/vscode/vint/syntaxes/vint.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@
},
"constant": {
"name": "constant.language.vint",
"match": "\\b(true|false)\\b"
"match": "\\b(true|false|null)\\b"
},
"operators": {
"patterns": [
{
"name": "keyword.operator.arithmetic.vint",
"match": "\\b(\\+|\\-|%|\\*|\\/|\\^)\\b"
"match": "\\b(\\+|\\-|%|\\*|\\/|\\^|\\*\\*|\\+\\+|--|\\+=|-=|\\*=|\\/=|%=)\\b"
},
{
"name": "keyword.operator.logical.vint",
"match": "\\b(==|<=|>=|<|>|&&|\\|\\|)\\b"
},
{
"name": "keyword.operator.assignment.vint",
"match": "\\b(=|:)\\b"
"match": "\\b(=|:=)\\b"
},
{
"name": "punctuation.accessor.vint",
Expand All @@ -97,19 +97,23 @@
"patterns": [
{
"name": "storage.type.function.vint",
"match": "\\b(declare|print|number|sum|end|push|fill|type|open)\\b"
"match": "\\b(func|declare|return)\\b"
},
{
"name": "storage.type.vint",
"match": "\\b(perform)\\b"
"match": "\\b(perform|let)\\b"
},
{
"name": "keyword.control.vint",
"match": "\\b(if|else|not|while|return|break|continue|empty|in|for|change|when|default|use)\\b"
"match": "\\b(if|else|while|break|continue|for|switch|case|default|in)\\b"
},
{
"name": "support.function.vint",
"match": "\\b(os|time)\\b"
"match": "\\b(os|time|print)\\b"
},
{
"name": "keyword.package.vint",
"match": "\\b(package|import)\\b"
}
]
},
Expand Down

0 comments on commit 30d28b8

Please sign in to comment.