mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
The compiler no longer takes name and source.
This commit is contained in:
parent
9a2c30dd3e
commit
be3b938bcf
|
@ -119,7 +119,6 @@ func (ed *Editor) notify(format string, args ...interface{}) {
|
|||
|
||||
func (ed *Editor) refresh(fullRefresh bool, tips bool) error {
|
||||
// Re-lex the line, unless we are in modeCompletion
|
||||
name := "[interacitve]"
|
||||
src := ed.line
|
||||
if ed.mode != modeCompletion {
|
||||
n, err := parse.Parse(src)
|
||||
|
@ -134,7 +133,7 @@ func (ed *Editor) refresh(fullRefresh bool, tips bool) error {
|
|||
ed.tokens = []Token{{ParserError, src, nil, ""}}
|
||||
} else {
|
||||
ed.tokens = tokenize(src, n)
|
||||
_, err := ed.evaler.Compile(name, src, n)
|
||||
_, err := ed.evaler.Compile(n)
|
||||
if err != nil {
|
||||
if tips && !atEnd(err, len(src)) {
|
||||
ed.addTip("compiler error: %s", err)
|
||||
|
|
|
@ -197,7 +197,8 @@ func compileUse(cp *compiler, fn *parse.Form) Op {
|
|||
n, err := parse.Parse(source)
|
||||
maybeThrow(err)
|
||||
|
||||
op, err := newEc.Compile(filename, source, n)
|
||||
op, err := newEc.Compile(n)
|
||||
// TODO the err originates in another source, should add appropriate information.
|
||||
maybeThrow(err)
|
||||
|
||||
op(newEc)
|
||||
|
|
|
@ -3,6 +3,8 @@ package eval
|
|||
//go:generate ./boilerplate.py
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/elves/elvish/parse"
|
||||
"github.com/elves/elvish/util"
|
||||
)
|
||||
|
@ -20,24 +22,20 @@ type (
|
|||
// compiler maintains the set of states needed when compiling a single source
|
||||
// file.
|
||||
type compiler struct {
|
||||
// Used in error messages.
|
||||
name, source string
|
||||
// Lexical scopes.
|
||||
scopes []scope
|
||||
// Variables captured from outer scopes.
|
||||
capture scope
|
||||
// Stored error.
|
||||
error error
|
||||
}
|
||||
|
||||
func compile(name, source string, sc scope, n *parse.Chunk) (op Op, err error) {
|
||||
cp := &compiler{name, source, []scope{sc}, scope{}, nil}
|
||||
func compile(sc scope, n *parse.Chunk) (op Op, err error) {
|
||||
cp := &compiler{[]scope{sc}, scope{}}
|
||||
defer util.Catch(&err)
|
||||
return cp.chunk(n), nil
|
||||
}
|
||||
|
||||
func (cp *compiler) errorf(p int, format string, args ...interface{}) {
|
||||
throw(util.NewContextualError(cp.name, "syntax error", cp.source, p, format, args...))
|
||||
throw(&util.PosError{p, p, fmt.Errorf(format, args...)})
|
||||
}
|
||||
|
||||
func (cp *compiler) thisScope() scope {
|
||||
|
|
|
@ -130,7 +130,7 @@ func makeScope(s Namespace) scope {
|
|||
// Eval evaluates a chunk node n. The supplied name and text are used in
|
||||
// diagnostic messages.
|
||||
func (ev *Evaler) Eval(name, text string, n *parse.Chunk, ports []*Port) error {
|
||||
op, err := ev.Compile(name, text, n)
|
||||
op, err := ev.Compile(n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -164,8 +164,8 @@ func (ev *Evaler) EvalInteractive(text string, n *parse.Chunk) error {
|
|||
}
|
||||
|
||||
// Compile compiles elvish code in the global scope.
|
||||
func (ev *Evaler) Compile(name, text string, n *parse.Chunk) (Op, error) {
|
||||
return compile(name, text, makeScope(ev.global), n)
|
||||
func (ev *Evaler) Compile(n *parse.Chunk) (Op, error) {
|
||||
return compile(makeScope(ev.global), n)
|
||||
}
|
||||
|
||||
// PEval evaluates an op in a protected environment so that calls to errorf are
|
||||
|
|
Loading…
Reference in New Issue
Block a user