Skip to content

Commit

Permalink
fix error test and improve error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
gravataLonga committed Jul 12, 2022
1 parent 17250ce commit cdb6edc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,17 @@ func main() {
}

file, err := ioutil.ReadFile(os.Args[1])
if err == nil {
execCode(string(file), os.Stdout)
if err != nil {
_, err := fmt.Fprintf(os.Stderr, "%v", err)
if err != nil {
os.Exit(1)
return
}
os.Exit(1)
return
}

execCode(string(file), os.Stdout)
}

func runRepl(in io.Reader, out io.Writer) {
Expand Down
4 changes: 2 additions & 2 deletions semantic/semantic.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func (s *Semantic) expectIdentifierDeclare(ident *ast.Identifier) bool {
tok := ident.Token
peek, ok := s.scopeStack.Peek()
if !ok {
s.NewError("There aren't any scope active %s", name)
return false
// probably is global environment
return true
}

v, ok := (*peek)[name]
Expand Down

0 comments on commit cdb6edc

Please sign in to comment.