Skip to content

Commit 0419485

Browse files
committed
feat: add semantic error handling utilities
- Create semantic_error.go with error reporting functions - Introduce PrintSemanticError for reporting errors to stderr - Add MakeSemanticError for creating semantic error instances - Include HadSemanticError flag to track semantic error state
1 parent 3ff2f9d commit 0419485

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

internal/lox/semantic_error.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package lox
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
// PrintSemanticError reports a semantic error
9+
func PrintSemanticError(message string) {
10+
fmt.Fprintf(os.Stderr, "%v\n", message)
11+
HadSemanticError = true
12+
}
13+
14+
// MakeSemanticError creates a new semantic error
15+
func MakeSemanticError(message string) error {
16+
return fmt.Errorf("%s", message)
17+
}
18+
19+
// HadSemanticError is true if an evaluation error was encountered
20+
var HadSemanticError = false

0 commit comments

Comments
 (0)