Skip to content

Commit

Permalink
feat(parser): switch over to the new parser (#352)
Browse files Browse the repository at this point in the history
There are a few notable differences.

First, true and false are not reserved identifiers so they will evaluate
as identifiers. It is up to the caller to set the value for these
predeclared identifiers. This is done manually in one test and otherwise
it is done automatically in the interpreter.

Second, some of the location information changed. Notably, object
expressions start at the `{` symbol instead of the location of the first
property and call expression start at the beginning of the callee
instead of the first parenthesis. This second one is identical to what
the go parser does. The type inference tests had to be modified for this
reason.

The parser options have been removed. They seem to have been
automatically generated by pigeon and weren't applicable anymore. This
changes the type signature, but it doesn't change how it is called in a
majority of situations.

The pigeon dependency has been removed as it is no longer needed.
  • Loading branch information
jsternberg authored Dec 4, 2018
1 parent 45975b5 commit 8211239
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 8,455 deletions.
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# * All recursive Makefiles must support the targets: all and clean.
#

SUBDIRS = ast parser internal/scanner
SUBDIRS = ast internal/scanner

GO_ARGS=-tags '$(GO_TAGS)'

Expand All @@ -25,7 +25,6 @@ export GO_VET=env GO111MODULE=on go vet $(GO_ARGS)

# List of utilities to build as part of the build process
UTILS := \
bin/$(GOOS)/pigeon \
bin/$(GOOS)/cmpgen

all: $(UTILS) $(SUBDIRS)
Expand All @@ -36,9 +35,6 @@ $(SUBDIRS): $(UTILS)
clean: $(SUBDIRS)
rm -rf bin

bin/$(GOOS)/pigeon: go.mod go.sum
$(GO_BUILD) -o $@ github.com/mna/pigeon

bin/$(GOOS)/cmpgen: ./ast/asttest/cmpgen/main.go
$(GO_BUILD) -o $@ ./ast/asttest/cmpgen

Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ require (
github.com/mattn/go-runewidth v0.0.3 // indirect
github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mna/pigeon v1.0.1-0.20180808201053-bb0192cfc2ae
github.com/opentracing/opentracing-go v1.0.2
github.com/pierrec/lz4 v2.0.5+incompatible // indirect
github.com/pkg/errors v0.8.0
Expand All @@ -39,7 +38,6 @@ require (
golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 // indirect
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect
golang.org/x/sys v0.0.0-20181011152604-fa43e7bc11ba // indirect
golang.org/x/tools v0.0.0-20181121193951-91f80e683c10 // indirect
gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca
google.golang.org/appengine v1.2.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104 h1:d8RFOZ2IiFtFWBcKEH
github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mna/pigeon v1.0.1-0.20180808201053-bb0192cfc2ae h1:mQO+oxi0kpii/TX+ltfTCFuYkOjEn53JhaOObiMuvnk=
github.com/mna/pigeon v1.0.1-0.20180808201053-bb0192cfc2ae/go.mod h1:Iym28+kJVnC1hfQvv5MUtI6AiFFzvQjHcvI4RFTG/04=
github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
Expand Down Expand Up @@ -93,8 +91,6 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181121193951-91f80e683c10 h1:6aZMfwu0xab6imbp0uu++D3WXR+p0+RDYOqqb0uY8KU=
golang.org/x/tools v0.0.0-20181121193951-91f80e683c10/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca h1:PupagGYwj8+I4ubCxcmcBRk3VlUWtTg5huQpZR9flmE=
gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
gonum.org/v1/netlib v0.0.0-20181029234149-ec6d1f5cefe6 h1:4WsZyVtkthqrHTbDCJfiTs8IWNYE4uvsSDgaV6xpp+o=
Expand Down
22 changes: 22 additions & 0 deletions internal/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,28 @@ func testParser(runFn func(name string, fn func(t testing.TB))) {
},
},
},
{
name: "declare variable as an empty array",
raw: `howdy = []`,
want: &ast.Program{
BaseNode: base("1:1", "1:11"),
Body: []ast.Statement{
&ast.VariableDeclaration{
BaseNode: base("1:1", "1:11"),
Declarations: []*ast.VariableDeclarator{{
BaseNode: base("1:1", "1:11"),
ID: &ast.Identifier{
BaseNode: base("1:1", "1:6"),
Name: "howdy",
},
Init: &ast.ArrayExpression{
BaseNode: base("1:9", "1:11"),
},
}},
},
},
},
},
{
name: "use variable to declare something",
raw: `howdy = 1
Expand Down
9 changes: 7 additions & 2 deletions interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
"github.com/pkg/errors"
)

var topScope = NewScopeWithValues(map[string]values.Value{
"true": values.NewBool(true),
"false": values.NewBool(false),
})

// Interpreter used to interpret a Flux program
type Interpreter struct {
values []values.Value
Expand All @@ -21,7 +26,7 @@ type Interpreter struct {
// NewInterpreter instantiates a new Flux Interpreter whose builtin values are not mutable.
// Options are always mutable.
func NewInterpreter(options, builtins map[string]values.Value, types *TypeScope) *Interpreter {
optionScope := NewScopeWithValues(options)
optionScope := topScope.NestWithValues(options)
globalScope := optionScope.NestWithValues(builtins)
interpreter := &Interpreter{
options: optionScope,
Expand All @@ -34,7 +39,7 @@ func NewInterpreter(options, builtins map[string]values.Value, types *TypeScope)
// NewMutableInterpreter instantiates a new Flux Interpreter whose builtin values are mutable.
// Options are always mutable.
func NewMutableInterpreter(options, builtins map[string]values.Value, types *TypeScope) *Interpreter {
optionScope := NewScopeWithValues(options)
optionScope := topScope.NestWithValues(options)
globalScope := optionScope.NestWithValues(builtins)
interpreter := &Interpreter{
options: optionScope,
Expand Down
9 changes: 0 additions & 9 deletions parser/Makefile

This file was deleted.

Loading

0 comments on commit 8211239

Please sign in to comment.