diff --git a/.idea/discord.xml b/.idea/discord.xml
new file mode 100644
index 0000000..30bab2a
--- /dev/null
+++ b/.idea/discord.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/leango.iml b/.idea/leango.iml
new file mode 100644
index 0000000..7ee078d
--- /dev/null
+++ b/.idea/leango.iml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 3728beb..79763dd 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,7 +4,15 @@
-
+
+
+
+
+
+
+
+
+
@@ -18,32 +26,44 @@
-
+
+
+
+
+
+
+ {
+ "associatedIndex": 7
+}
+
+
+
- {
+ "keyToString": {
+ "DefaultGoTemplateProperty": "Go File",
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "RunOnceActivity.go.formatter.settings.were.checked": "true",
+ "RunOnceActivity.go.migrated.go.modules.settings": "true",
+ "RunOnceActivity.go.modules.automatic.dependencies.download": "true",
+ "RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
+ "git-widget-placeholder": "master",
+ "go.import.settings.migrated": "true",
+ "go.sdk.automatically.set": "true",
+ "last_opened_file_path": "/Users/mohammed/Me/projects/leango",
+ "node.js.detected.package.eslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm"
}
-}]]>
+}
+
@@ -52,7 +72,7 @@
-
+
@@ -61,7 +81,7 @@
-
+
diff --git a/Logger/logger.go b/Logger/logger.go
new file mode 100644
index 0000000..fbcdc34
--- /dev/null
+++ b/Logger/logger.go
@@ -0,0 +1,17 @@
+package Logger
+
+import (
+ log "github.com/sirupsen/logrus"
+)
+
+func Fatal(nbLine int, mes string) {
+ log.WithFields(log.Fields{
+ "line": nbLine,
+ }).Fatal(mes)
+}
+
+func Info(nbLine int, mes string) {
+ log.WithFields(log.Fields{
+ "line": nbLine,
+ }).Fatal(mes)
+}
diff --git a/Token/handler.go b/Token/handler.go
index dbde206..5236d29 100644
--- a/Token/handler.go
+++ b/Token/handler.go
@@ -2,13 +2,14 @@ package Token
import (
"fmt"
+ "leango/Logger"
"leango/Variable"
"slices"
+ "strconv"
)
var availableTokens = []string{"let", "const", "lean"}
-var availableMutableVariables = make(map[string]Variable.Variable)
-var availableNonMutableVariables = make(map[string]Variable.Variable)
+var availableVariables = make(map[string]Variable.Variable)
func TokenHandler() map[string]func([]string, int) {
var TokenMapFunction = make(map[string]func([]string, int))
@@ -19,20 +20,32 @@ func TokenHandler() map[string]func([]string, int) {
return TokenMapFunction
}
-func isLet(rows []string, line int) {
- index := slices.Index(rows, "=")
+func isLet(rows []string, nbLine int) {
+ indexEqualSign := slices.Index(rows, "=")
+ lenRows := len(rows)
+ var tokenValue []string
- if len(rows) == 1 {
- panic(fmt.Sprintf("Nothing found after the declaration of let at line %d", line))
+ if lenRows < 2 {
+ Logger.Fatal(nbLine, "Nothing found after the declaration of let")
}
-
- if index == -1 {
- panic(fmt.Sprintf("A value was not set for %s", rows[1]))
+ fmt.Println(indexEqualSign)
+ if indexEqualSign == 2 && lenRows == 3 {
+ Logger.Fatal(nbLine, fmt.Sprintf("A value was not set for %s", rows[1]))
+ }
+ if _, varNameExists := availableVariables[rows[1]]; varNameExists {
+ Logger.Fatal(nbLine, fmt.Sprintf("A variable aleady exists with the same name %s: line %d", rows[1], nbLine))
+ }
+ if indexEqualSign == 2 {
+ tokenValue = rows[indexEqualSign+1:]
+
+ if intValue, err := strconv.Atoi(tokenValue[0]); err == nil {
+ availableVariables[rows[1]] = Variable.Variable{IsNumeric: true, Value: intValue}
+ } else {
+ availableVariables[rows[1]] = Variable.Variable{IsNumeric: true, Value: intValue}
+ }
+ } else {
+ availableVariables[rows[1]] = Variable.Variable{Value: nil}
}
-
- value := rows[index+1:]
- fmt.Println(value)
- fmt.Println("Is a let variable and the value is = ")
}
func isConst(rows []string, line int) {
diff --git a/Variable/variable.go b/Variable/variable.go
index 519d407..b8dbe09 100644
--- a/Variable/variable.go
+++ b/Variable/variable.go
@@ -1,8 +1,8 @@
package Variable
type Variable struct {
- isNumeric bool
- isString bool
- isArray bool
- value any
+ IsNumeric bool
+ IsString bool
+ IsMutable bool
+ Value any
}
diff --git a/examples/foo.leango b/examples/foo.leango
index d887a70..22df79e 100644
--- a/examples/foo.leango
+++ b/examples/foo.leango
@@ -1,4 +1,4 @@
-let foo = 1
+let foo
let bar = foo + 1
const john = 90
diff --git a/examples/let/errors/no_value_after_equal_sing.leango b/examples/let/errors/no_value_after_equal_sing.leango
new file mode 100644
index 0000000..7a708b4
--- /dev/null
+++ b/examples/let/errors/no_value_after_equal_sing.leango
@@ -0,0 +1 @@
+let foo =
\ No newline at end of file
diff --git a/examples/let/errors/same_name_variables.leango b/examples/let/errors/same_name_variables.leango
new file mode 100644
index 0000000..1be01e5
--- /dev/null
+++ b/examples/let/errors/same_name_variables.leango
@@ -0,0 +1,2 @@
+let foo
+let foo
diff --git a/go.mod b/go.mod
index 7b87b1a..e045189 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,8 @@
module leango
go 1.22.0
+
+require (
+ github.com/sirupsen/logrus v1.9.3 // indirect
+ golang.org/x/sys v0.18.0 // indirect
+)
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..11b6d08
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,12 @@
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
+github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
+golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/main.go b/main.go
index 737c206..715baa2 100644
--- a/main.go
+++ b/main.go
@@ -2,6 +2,7 @@ package main
import (
"fmt"
+ logger "github.com/sirupsen/logrus"
"leango/Token"
"log"
"os"
@@ -42,5 +43,8 @@ func main() {
if len(os.Args) != 2 {
log.Default().Fatal("Not enough arguments\n./leango [filepath]")
}
+ if !(strings.HasSuffix(os.Args[1], ".leango")) {
+ logger.WithFields(logger.Fields{}).Fatal(fmt.Sprintf("Incorrect file extension [%s]", os.Args[1]))
+ }
parseFile(os.Args[1])
}