lang: ast, interfaces: Move textarea to a common package

We're going to use it everywhere. We also make it more forgiving in the
meanwhile while we're porting things over.
This commit is contained in:
James Shubin
2025-06-06 00:32:13 -04:00
parent 4189a1299a
commit 6ac72974eb
3 changed files with 253 additions and 184 deletions

View File

@@ -183,7 +183,8 @@ var (
// StmtBind is a representation of an assignment, which binds a variable to an
// expression.
type StmtBind struct {
Textarea
interfaces.Textarea
data *interfaces.Data
Ident string
@@ -378,7 +379,8 @@ func (obj *StmtBind) Output(map[interfaces.Func]types.Value) (*interfaces.Output
// TODO: Consider expanding Name to have this return a list of Res's in the
// Output function if it is a map[name]struct{}, or even a map[[]name]struct{}.
type StmtRes struct {
Textarea
interfaces.Textarea
data *interfaces.Data
Kind string // kind of resource, eg: pkg, file, svc, etc...
@@ -1594,7 +1596,8 @@ type StmtResContents interface {
// StmtResField represents a single field in the parsed resource representation.
// This does not satisfy the Stmt interface.
type StmtResField struct {
Textarea
interfaces.Textarea
data *interfaces.Data
Field string
@@ -1879,7 +1882,8 @@ func (obj *StmtResField) Graph(env *interfaces.Env) (*pgraph.Graph, error) {
// StmtResEdge represents a single edge property in the parsed resource
// representation. This does not satisfy the Stmt interface.
type StmtResEdge struct {
Textarea
interfaces.Textarea
data *interfaces.Data
Property string // TODO: iota constant instead?
@@ -2129,7 +2133,8 @@ func (obj *StmtResEdge) Graph(env *interfaces.Env) (*pgraph.Graph, error) {
// correspond to the particular meta parameter specified. This does not satisfy
// the Stmt interface.
type StmtResMeta struct {
Textarea
interfaces.Textarea
data *interfaces.Data
Property string // TODO: iota constant instead?
@@ -2683,7 +2688,8 @@ func (obj *StmtResCollect) Graph(env *interfaces.Env) (*pgraph.Graph, error) {
// names are compatible and listed. In this case of Send/Recv, only lists of
// length two are legal.
type StmtEdge struct {
Textarea
interfaces.Textarea
data *interfaces.Data
EdgeHalfList []*StmtEdgeHalf // represents a chain of edges
@@ -3032,7 +3038,8 @@ func (obj *StmtEdge) Output(table map[interfaces.Func]types.Value) (*interfaces.
// is assumed that a list of strings should be expected. More mechanisms to
// determine if the value is static may be added over time.
type StmtEdgeHalf struct {
Textarea
interfaces.Textarea
data *interfaces.Data
Kind string // kind of resource, eg: pkg, file, svc, etc...
@@ -3203,7 +3210,8 @@ func (obj *StmtEdgeHalf) Graph(env *interfaces.Env) (*pgraph.Graph, error) {
// optional, it is the else branch, although this struct allows either to be
// optional, even if it is not commonly used.
type StmtIf struct {
Textarea
interfaces.Textarea
data *interfaces.Data
Condition interfaces.Expr
@@ -3569,7 +3577,8 @@ func (obj *StmtIf) Output(table map[interfaces.Func]types.Value) (*interfaces.Ou
// StmtFor represents an iteration over a list. The body contains statements.
type StmtFor struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope // store for referencing this later
@@ -4077,7 +4086,8 @@ func (obj *StmtFor) Output(table map[interfaces.Func]types.Value) (*interfaces.O
// StmtForKV represents an iteration over a map. The body contains statements.
type StmtForKV struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope // store for referencing this later
@@ -4583,7 +4593,8 @@ func (obj *StmtForKV) Output(table map[interfaces.Func]types.Value) (*interfaces
// the bind statement's are correctly applied in this scope, and irrespective of
// their order of definition.
type StmtProg struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope // store for use by imports
@@ -6177,7 +6188,8 @@ func (obj *StmtProg) IsModuleUnsafe() error { // TODO: rename this function?
// the supplied function in the current scope and irrespective of the order of
// definition.
type StmtFunc struct {
Textarea
interfaces.Textarea
data *interfaces.Data
Name string
@@ -6391,7 +6403,8 @@ func (obj *StmtFunc) Output(map[interfaces.Func]types.Value) (*interfaces.Output
// TODO: We don't currently support defining polymorphic classes (eg: different
// signatures for the same class name) but it might be something to consider.
type StmtClass struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope // store for referencing this later
@@ -6601,7 +6614,8 @@ func (obj *StmtClass) Output(table map[interfaces.Func]types.Value) (*interfaces
// to call a class except that it produces output instead of a value. Most of
// the interesting logic for classes happens here or in StmtProg.
type StmtInclude struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope
@@ -7099,7 +7113,8 @@ func (obj *StmtInclude) Output(table map[interfaces.Func]types.Value) (*interfac
// file. As with any statement, it produces output, but that output is empty. To
// benefit from its inclusion, reference the scope definitions you want.
type StmtImport struct {
Textarea
interfaces.Textarea
data *interfaces.Data
Name string
@@ -7208,7 +7223,7 @@ func (obj *StmtImport) Output(map[interfaces.Func]types.Value) (*interfaces.Outp
// formatting) but so that they can exist anywhere in the code. Currently these
// are dropped by the lexer.
type StmtComment struct {
Textarea
interfaces.Textarea
Value string
}
@@ -7290,7 +7305,8 @@ func (obj *StmtComment) Output(map[interfaces.Func]types.Value) (*interfaces.Out
// ExprBool is a representation of a boolean.
type ExprBool struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope // store for referencing this later
@@ -7443,7 +7459,8 @@ func (obj *ExprBool) Value() (types.Value, error) {
// ExprStr is a representation of a string.
type ExprStr struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope // store for referencing this later
@@ -7645,7 +7662,8 @@ func (obj *ExprStr) Value() (types.Value, error) {
// ExprInt is a representation of an int.
type ExprInt struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope // store for referencing this later
@@ -7797,7 +7815,8 @@ func (obj *ExprInt) Value() (types.Value, error) {
// ExprFloat is a representation of a float.
type ExprFloat struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope // store for referencing this later
@@ -7951,7 +7970,8 @@ func (obj *ExprFloat) Value() (types.Value, error) {
// ExprList is a representation of a list.
type ExprList struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope // store for referencing this later
typ *types.Type
@@ -8315,7 +8335,8 @@ func (obj *ExprList) Value() (types.Value, error) {
// ExprMap is a representation of a (dictionary) map.
type ExprMap struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope // store for referencing this later
typ *types.Type
@@ -8804,7 +8825,7 @@ func (obj *ExprMap) Value() (types.Value, error) {
// ExprMapKV represents a key and value pair in a (dictionary) map. This does
// not satisfy the Expr interface.
type ExprMapKV struct {
Textarea
interfaces.Textarea
Key interfaces.Expr // keys can be strings, int's, etc...
Val interfaces.Expr
@@ -8812,7 +8833,8 @@ type ExprMapKV struct {
// ExprStruct is a representation of a struct.
type ExprStruct struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope // store for referencing this later
typ *types.Type
@@ -9208,7 +9230,7 @@ func (obj *ExprStruct) Value() (types.Value, error) {
// ExprStructField represents a name value pair in a struct field. This does not
// satisfy the Expr interface.
type ExprStructField struct {
Textarea
interfaces.Textarea
Name string
Value interfaces.Expr
@@ -9224,7 +9246,8 @@ type ExprStructField struct {
// 4. A pure built-in function (set Values to a singleton)
// 5. A pure polymorphic built-in function (set Values to a list)
type ExprFunc struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope // store for referencing this later
typ *types.Type
@@ -10139,7 +10162,8 @@ func (obj *ExprFunc) Value() (types.Value, error) {
// declaration or implementation of a new function value. This struct has an
// analogous symmetry with ExprVar.
type ExprCall struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope // store for referencing this later
typ *types.Type
@@ -11118,7 +11142,8 @@ func (obj *ExprCall) Value() (types.Value, error) {
// ExprVar is a representation of a variable lookup. It returns the expression
// that that variable refers to.
type ExprVar struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope // store for referencing this later
typ *types.Type
@@ -12322,7 +12347,8 @@ func (obj *ExprSingleton) Value() (types.Value, error) {
// returns a value. As a result, it has a type. This is different from a StmtIf,
// which does not need to have both branches, and which does not return a value.
type ExprIf struct {
Textarea
interfaces.Textarea
data *interfaces.Data
scope *interfaces.Scope // store for referencing this later
typ *types.Type