-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose errors (for bot). #35
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,14 +48,15 @@ func EvalAll(s, macroState *eval.State, in io.Reader, out io.Writer, options Opt | |
} | ||
|
||
// EvalString can be used from playground etc for single eval. | ||
func EvalString(what string) string { | ||
// returns the eval errors and an array of errors if any. | ||
func EvalString(what string) (string, []string) { | ||
s := eval.NewState() | ||
macroState := eval.NewState() | ||
out := &strings.Builder{} | ||
s.Out = out | ||
s.NoLog = true | ||
EvalOne(s, macroState, what, out, Options{All: true, ShowEval: true, NoColor: true}) | ||
return out.String() | ||
_, errs := EvalOne(s, macroState, what, out, Options{All: true, ShowEval: true, NoColor: true}) | ||
return out.String(), errs | ||
} | ||
|
||
func Interactive(in io.Reader, out io.Writer, options Options) { | ||
|
@@ -72,7 +73,7 @@ func Interactive(in io.Reader, out io.Writer, options Options) { | |
return | ||
} | ||
l := prev + scanner.Text() | ||
contNeeded := EvalOne(s, macroState, l, out, options) | ||
contNeeded, _ := EvalOne(s, macroState, l, out, options) | ||
if contNeeded { | ||
prev = l + "\n" | ||
prompt = CONTINUATION | ||
|
@@ -84,7 +85,8 @@ func Interactive(in io.Reader, out io.Writer, options Options) { | |
} | ||
|
||
// Returns true in line mode if more should be fed to the parser. | ||
func EvalOne(s, macroState *eval.State, what string, out io.Writer, options Options) bool { | ||
// TODO: this one size fits 3 different calls (file, interactive, bot) is getting spaghetti. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ccoVeille I realize ^ |
||
func EvalOne(s, macroState *eval.State, what string, out io.Writer, options Options) (bool, []string) { | ||
var l *lexer.Lexer | ||
if options.All { | ||
l = lexer.New(what) | ||
|
@@ -94,10 +96,10 @@ func EvalOne(s, macroState *eval.State, what string, out io.Writer, options Opti | |
p := parser.New(l) | ||
program := p.ParseProgram() | ||
if logParserErrors(p) { | ||
return false | ||
return false, p.Errors() | ||
} | ||
if p.ContinuationNeeded() { | ||
return true | ||
return true, nil | ||
} | ||
if options.ShowParse { | ||
fmt.Fprint(out, "== Parse ==> ") | ||
|
@@ -122,7 +124,11 @@ func EvalOne(s, macroState *eval.State, what string, out io.Writer, options Opti | |
} | ||
obj := s.Eval(program) | ||
if !options.ShowEval { | ||
return false | ||
return false, nil | ||
} | ||
var errs []string | ||
if obj.Type() == object.ERROR { | ||
errs = append(errs, obj.Inspect()) | ||
} | ||
if !options.NoColor { | ||
if obj.Type() == object.ERROR { | ||
|
@@ -135,5 +141,5 @@ func EvalOne(s, macroState *eval.State, what string, out io.Writer, options Opti | |
if !options.NoColor { | ||
fmt.Fprint(out, log.ANSIColors.Reset) | ||
} | ||
return false | ||
return false, errs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ignoring errors here?
Maybe it's OK, but a comment would help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's because they've been printed interactively, which is kinda why the spagheti of ifs and modes in EvalOne isn't great, I probably should just copy paste exactly for 3 modes, or ... clean up somehow
agreed on comment, adding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c09493c