diff --git a/desugarer.go b/desugarer.go index 6a6083a..d5c6f04 100644 --- a/desugarer.go +++ b/desugarer.go @@ -24,6 +24,7 @@ import ( "unicode/utf8" "github.com/google/go-jsonnet/ast" + "github.com/google/go-jsonnet/parser" ) func makeStr(s string) *ast.LiteralString { @@ -39,7 +40,7 @@ func stringUnescape(loc *ast.LocationRange, s string) (string, error) { switch r { case '\\': if i >= len(s) { - return "", MakeStaticError("Truncated escape sequence in string literal.", *loc) + return "", parser.MakeStaticError("Truncated escape sequence in string literal.", *loc) } r2, w := utf8.DecodeRuneInString(s[i:]) i += w @@ -64,17 +65,17 @@ func stringUnescape(loc *ast.LocationRange, s string) (string, error) { buf.WriteRune('\t') case 'u': if i+4 > len(s) { - return "", MakeStaticError("Truncated unicode escape sequence in string literal.", *loc) + return "", parser.MakeStaticError("Truncated unicode escape sequence in string literal.", *loc) } codeBytes, err := hex.DecodeString(s[i : i+4]) if err != nil { - return "", MakeStaticError(fmt.Sprintf("Unicode escape sequence was malformed: %s", s[0:4]), *loc) + return "", parser.MakeStaticError(fmt.Sprintf("Unicode escape sequence was malformed: %s", s[0:4]), *loc) } code := int(codeBytes[0])*256 + int(codeBytes[1]) buf.WriteRune(rune(code)) i += 4 default: - return "", MakeStaticError(fmt.Sprintf("Unknown escape sequence in string literal: \\%c", r2), *loc) + return "", parser.MakeStaticError(fmt.Sprintf("Unknown escape sequence in string literal: \\%c", r2), *loc) } default: @@ -348,7 +349,7 @@ func desugar(astPtr *ast.Node, objLevel int) (err error) { case *ast.Dollar: if objLevel == 0 { - return MakeStaticError("No top-level object found.", *node.Loc()) + return parser.MakeStaticError("No top-level object found.", *node.Loc()) } *astPtr = &ast.Var{NodeBase: node.NodeBase, Id: ast.Identifier("$")} diff --git a/error_formatter.go b/error_formatter.go index e8b0879..49472d9 100644 --- a/error_formatter.go +++ b/error_formatter.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/google/go-jsonnet/ast" + "github.com/google/go-jsonnet/parser" ) type ErrorFormatter struct { @@ -36,7 +37,7 @@ func (ef *ErrorFormatter) format(err error) string { switch err := err.(type) { case RuntimeError: return ef.formatRuntime(&err) - case StaticError: + case parser.StaticError: return ef.formatStatic(&err) default: return ef.formatInternal(err) @@ -48,7 +49,7 @@ func (ef *ErrorFormatter) formatRuntime(err *RuntimeError) string { // TODO(sbarzowski) pretty stuff } -func (ef *ErrorFormatter) formatStatic(err *StaticError) string { +func (ef *ErrorFormatter) formatStatic(err *parser.StaticError) string { return err.Error() + "\n" // TODO(sbarzowski) pretty stuff } diff --git a/lexer.go b/parser/lexer.go similarity index 99% rename from lexer.go rename to parser/lexer.go index 548a2f4..785fa5d 100644 --- a/lexer.go +++ b/parser/lexer.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package jsonnet +package parser import ( "bytes" diff --git a/lexer_test.go b/parser/lexer_test.go similarity index 99% rename from lexer_test.go rename to parser/lexer_test.go index 0231b9b..14a3250 100644 --- a/lexer_test.go +++ b/parser/lexer_test.go @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package jsonnet +package parser import ( "testing" diff --git a/literalfield_set.go b/parser/literalfield_set.go similarity index 99% rename from literalfield_set.go rename to parser/literalfield_set.go index 2eb6dd0..983ed5c 100644 --- a/literalfield_set.go +++ b/parser/literalfield_set.go @@ -2,7 +2,7 @@ // TypeWriter: set // Directive: +gen on literalField -package jsonnet +package parser // Set is a modification of https://github.com/deckarep/golang-set // The MIT License (MIT) diff --git a/parser.go b/parser/parser.go similarity index 99% rename from parser.go rename to parser/parser.go index ac19938..ebcf518 100644 --- a/parser.go +++ b/parser/parser.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package jsonnet +package parser import ( "fmt" diff --git a/parser_test.go b/parser/parser_test.go similarity index 99% rename from parser_test.go rename to parser/parser_test.go index a19d1f0..4577d7a 100644 --- a/parser_test.go +++ b/parser/parser_test.go @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package jsonnet +package parser import ( "testing" diff --git a/static_error.go b/parser/static_error.go similarity index 98% rename from static_error.go rename to parser/static_error.go index 5acac10..9a826ae 100644 --- a/static_error.go +++ b/parser/static_error.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package jsonnet +package parser import ( "fmt" diff --git a/static_analyzer.go b/static_analyzer.go index 95bbbca..c5b026e 100644 --- a/static_analyzer.go +++ b/static_analyzer.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/google/go-jsonnet/ast" + "github.com/google/go-jsonnet/parser" ) type analysisState struct { @@ -77,7 +78,7 @@ func analyzeVisit(a ast.Node, inObject bool, vars ast.IdentifierSet) error { //nothing to do here case *ast.SuperIndex: if !inObject { - return MakeStaticError("Can't use super outside of an object.", *a.Loc()) + return parser.MakeStaticError("Can't use super outside of an object.", *a.Loc()) } visitNext(a.Index, inObject, vars, s) case *ast.Index: @@ -121,13 +122,13 @@ func analyzeVisit(a ast.Node, inObject bool, vars ast.IdentifierSet) error { panic("Comprehensions not supported yet") case *ast.Self: if !inObject { - return MakeStaticError("Can't use self outside of an object.", *a.Loc()) + return parser.MakeStaticError("Can't use self outside of an object.", *a.Loc()) } case *ast.Unary: visitNext(a.Expr, inObject, vars, s) case *ast.Var: if !vars.Contains(a.Id) { - return MakeStaticError(fmt.Sprintf("Unknown variable: %v", a.Id), *a.Loc()) + return parser.MakeStaticError(fmt.Sprintf("Unknown variable: %v", a.Id), *a.Loc()) } s.freeVars.Add(a.Id) default: diff --git a/vm.go b/vm.go index a16f584..3e52a0d 100644 --- a/vm.go +++ b/vm.go @@ -22,6 +22,7 @@ import ( "runtime/debug" "github.com/google/go-jsonnet/ast" + "github.com/google/go-jsonnet/parser" ) // Note: There are no garbage collection params because we're using the native @@ -98,11 +99,11 @@ func (vm *VM) EvaluateSnippet(filename string, snippet string) (json string, for } func snippetToAST(filename string, snippet string) (ast.Node, error) { - tokens, err := Lex(filename, snippet) + tokens, err := parser.Lex(filename, snippet) if err != nil { return nil, err } - node, err := Parse(tokens) + node, err := parser.Parse(tokens) if err != nil { return nil, err }