This change includes some progress on actual compilation (albeit with several TODOs remaining before we can actually spit out a useful artifact). There are also some general cleanups sprinkled throughout. In a nutshell: * Add a compiler.Context object that will be available during template expansion. * Introduce a diag.Document abstraction. This is better than passing raw filenames around, and lets us embellish diagnostics as we go. In particular, we will be in a better position to provide line/column error information. * Move IO out of the Parser and into the Compiler, where it can cache and reuse Documents. This will become important as we start to load up dependencies. * Rename PosRange to Location. This reads nicer with the new Document terminology. * Rename the mu/api package to mu/schema. It's likely we will need to introduce a true AST that is decoupled from the serialization format and contains bound nodes. As a result, treating the existing types as "schema" is more honest. * Add in a big section of TODOs at the end of the compiler.Compiler.Build function.
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
package diag
|
|
|
|
// ID is a unique diagnostics identifier.
|
|
type ID int
|
|
|
|
// Diag is an instance of an error or warning generated by the compiler.
|
|
type Diag struct {
|
|
ID ID // a unique identifier for this diagnostic.
|
|
Message string // a human-friendly message for this diagnostic.
|
|
Doc *Document // the document in which this diagnostic occurred.
|
|
Loc *Location // the document location at which this diagnostic occurred.
|
|
}
|
|
|
|
// WithFile adds a file to an existing diagnostic, retaining its ID and message.
|
|
func (diag *Diag) WithFile(file string) *Diag {
|
|
return &Diag{
|
|
ID: diag.ID,
|
|
Message: diag.Message,
|
|
Doc: NewDocument(file),
|
|
Loc: &EmptyLocation,
|
|
}
|
|
}
|
|
|
|
// WithDocument adds a file to an existing diagnostic, retaining its ID and message.
|
|
func (diag *Diag) WithDocument(doc *Document) *Diag {
|
|
return &Diag{
|
|
ID: diag.ID,
|
|
Message: diag.Message,
|
|
Doc: doc,
|
|
Loc: &EmptyLocation,
|
|
}
|
|
}
|
|
|
|
// WithLocation adds a file and position to an existing diagnostic, retaining its ID and message.
|
|
func (diag *Diag) WithLocation(doc *Document, loc *Location) *Diag {
|
|
return &Diag{
|
|
ID: diag.ID,
|
|
Message: diag.Message,
|
|
Doc: doc,
|
|
Loc: loc,
|
|
}
|
|
}
|