Skip to content

Commit

Permalink
Create a logger for Errorf
Browse files Browse the repository at this point in the history
  • Loading branch information
hugolgst committed Apr 20, 2020
1 parent 405cd47 commit 6eabcdb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
14 changes: 14 additions & 0 deletions log/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package log

import (
"fmt"
"github.com/gookit/color"
"os"
)

// Errorf logs as an error with the given params
func Errorf(params ...interface{}) {
red := color.BgRed.Render
fmt.Printf(fmt.Sprintf("%s %v\n", red("ERROR:"), params[0]), params[1:]...)
os.Exit(3)
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func main() {
example := `
TILLGÅNG FUNKÖN SKOGSFIBBLA hey SKOGSFIBBLA SKOGSFIBBLA nik zebi SKOGSFIBBLA ÄPPLARÖ FJÄLLBO
TILLGÅN FUNKÖN SKOGSFIBBLA hey SKOGSFIBBLA SKOGSFIBBLA nik zebi SKOGSFIBBLA ÄPPLARÖ FJÄLLBO
SMÅGLI FUNKÖN SMÅKALLT FUNKÖN SKOGSFIBBLA hey SKOGSFIBBLA ÄPPLARÖ ÄPPLARÖ FJÄLLBO
`

Expand Down
10 changes: 5 additions & 5 deletions runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package runtime

import (
"../core"
"../log"
"../parser"
"log"
)

// Run takes a given AST and runs the found functions and getters
Expand All @@ -18,16 +18,16 @@ func Run(ast []parser.Node) []parser.Node {
// Search an existent function in the map
function, getter := core.GetFunctions()[node.Value], core.GetGetters()[node.Value]
if function == nil && getter == nil {
log.Fatal("This function was not found.")
log.Errorf("This reference was not found.")
}

// Execute the found function
if function != nil {
function(params...)
// Execute the found getter and replace the content in the AST
// Execute the found getter and replace the content in the AST
} else if getter != nil {
ast[i] = parser.Node{
Type: "String",
Type: "String",
Value: getter(params...),
}
}
Expand Down Expand Up @@ -55,4 +55,4 @@ func GetParams(node parser.Node) (params []interface{}) {
}

return
}
}

0 comments on commit 6eabcdb

Please sign in to comment.