Location is now included in structs via composition
This commit is contained in:
parent
4c01d41723
commit
729ae78eae
@ -16,7 +16,7 @@ var validArgumentStartTokens = []lexer.TokenKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (parser *ParsingOperation) parseArgument () (argument Argument, err error) {
|
func (parser *ParsingOperation) parseArgument () (argument Argument, err error) {
|
||||||
argument.location = parser.token.Location()
|
argument.setLocation(parser.token.Location())
|
||||||
|
|
||||||
err = parser.expect(validArgumentStartTokens...)
|
err = parser.expect(validArgumentStartTokens...)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
@ -44,7 +44,6 @@ func (parser *ParsingOperation) parseArgument () (argument Argument, err error)
|
|||||||
|
|
||||||
argument.kind = ArgumentKindDeclaration
|
argument.kind = ArgumentKindDeclaration
|
||||||
argument.value = Declaration {
|
argument.value = Declaration {
|
||||||
location: argument.location,
|
|
||||||
name: identifier.trail[0],
|
name: identifier.trail[0],
|
||||||
what: what,
|
what: what,
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,8 @@ func (parser *ParsingOperation) parseDataSection () (
|
|||||||
err = parser.expect(lexer.TokenKindName)
|
err = parser.expect(lexer.TokenKindName)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
section = &DataSection { location: parser.token.Location() }
|
section = &DataSection { }
|
||||||
|
section.setLocation(parser.token.Location())
|
||||||
|
|
||||||
err = parser.nextToken(lexer.TokenKindPermission)
|
err = parser.nextToken(lexer.TokenKindPermission)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
@ -11,7 +11,8 @@ func (parser *ParsingOperation) parseEnumSection () (
|
|||||||
err = parser.expect(lexer.TokenKindName)
|
err = parser.expect(lexer.TokenKindName)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
section = &EnumSection { location: parser.token.Location() }
|
section = &EnumSection { }
|
||||||
|
section.setLocation(parser.token.Location())
|
||||||
|
|
||||||
// get permission
|
// get permission
|
||||||
err = parser.nextToken(lexer.TokenKindPermission)
|
err = parser.nextToken(lexer.TokenKindPermission)
|
||||||
|
@ -13,9 +13,9 @@ func (parser *ParsingOperation) parseFaceSection () (
|
|||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
section = &FaceSection {
|
section = &FaceSection {
|
||||||
location: parser.token.Location(),
|
|
||||||
behaviors: make(map[string] FaceBehavior),
|
behaviors: make(map[string] FaceBehavior),
|
||||||
}
|
}
|
||||||
|
section.setLocation(parser.token.Location())
|
||||||
|
|
||||||
// get permission
|
// get permission
|
||||||
err = parser.nextToken(lexer.TokenKindPermission)
|
err = parser.nextToken(lexer.TokenKindPermission)
|
||||||
|
@ -12,7 +12,8 @@ func (parser *ParsingOperation) parseFuncSection () (
|
|||||||
err = parser.expect(lexer.TokenKindName)
|
err = parser.expect(lexer.TokenKindName)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
section = &FuncSection { location: parser.token.Location() }
|
section = &FuncSection { }
|
||||||
|
section.setLocation(parser.token.Location())
|
||||||
|
|
||||||
// get permission
|
// get permission
|
||||||
err = parser.nextToken(lexer.TokenKindPermission)
|
err = parser.nextToken(lexer.TokenKindPermission)
|
||||||
|
30
parser/node-traits.go
Normal file
30
parser/node-traits.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package parser
|
||||||
|
|
||||||
|
import "git.tebibyte.media/arf/arf/file"
|
||||||
|
import "git.tebibyte.media/arf/arf/infoerr"
|
||||||
|
|
||||||
|
// locatable allows a tree node to have a location.
|
||||||
|
type locatable struct {
|
||||||
|
location file.Location
|
||||||
|
}
|
||||||
|
|
||||||
|
// Location returns the location of the node.
|
||||||
|
func (trait locatable) Location (location file.Location) {
|
||||||
|
location = trait.location
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// setLocation sets the location of the node.
|
||||||
|
func (trait locatable) setLocation (location file.Location) {
|
||||||
|
trait.location = location
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewError creates a new error at the node's location.
|
||||||
|
func (trait locatable) NewError (
|
||||||
|
message string,
|
||||||
|
kind infoerr.ErrorKind,
|
||||||
|
) (
|
||||||
|
err infoerr.Error,
|
||||||
|
) {
|
||||||
|
return infoerr.NewError(trait.location, message, kind)
|
||||||
|
}
|
@ -13,7 +13,8 @@ func (parser *ParsingOperation) parseObjtSection () (
|
|||||||
err = parser.expect(lexer.TokenKindName)
|
err = parser.expect(lexer.TokenKindName)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
section = &ObjtSection { location: parser.token.Location() }
|
section = &ObjtSection { }
|
||||||
|
section.setLocation(parser.token.Location())
|
||||||
|
|
||||||
// get permission
|
// get permission
|
||||||
err = parser.nextToken(lexer.TokenKindPermission)
|
err = parser.nextToken(lexer.TokenKindPermission)
|
||||||
|
@ -21,7 +21,7 @@ type SyntaxTree struct {
|
|||||||
|
|
||||||
// Identifier represents a chain of arguments separated by a dot.
|
// Identifier represents a chain of arguments separated by a dot.
|
||||||
type Identifier struct {
|
type Identifier struct {
|
||||||
location file.Location
|
locatable
|
||||||
trail []string
|
trail []string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ const (
|
|||||||
|
|
||||||
// Type represents a type specifier
|
// Type represents a type specifier
|
||||||
type Type struct {
|
type Type struct {
|
||||||
location file.Location
|
locatable
|
||||||
|
|
||||||
mutable bool
|
mutable bool
|
||||||
kind TypeKind
|
kind TypeKind
|
||||||
@ -60,7 +60,7 @@ type Type struct {
|
|||||||
|
|
||||||
// Declaration represents a variable declaration.
|
// Declaration represents a variable declaration.
|
||||||
type Declaration struct {
|
type Declaration struct {
|
||||||
location file.Location
|
locatable
|
||||||
name string
|
name string
|
||||||
what Type
|
what Type
|
||||||
}
|
}
|
||||||
@ -68,14 +68,14 @@ type Declaration struct {
|
|||||||
// ObjectInitializationValues represents a list of object member initialization
|
// ObjectInitializationValues represents a list of object member initialization
|
||||||
// attributes.
|
// attributes.
|
||||||
type ObjectInitializationValues struct {
|
type ObjectInitializationValues struct {
|
||||||
location file.Location
|
locatable
|
||||||
attributes map[string] Argument
|
attributes map[string] Argument
|
||||||
}
|
}
|
||||||
|
|
||||||
// ArrayInitializationValues represents a list of attributes initializing an
|
// ArrayInitializationValues represents a list of attributes initializing an
|
||||||
// array.
|
// array.
|
||||||
type ArrayInitializationValues struct {
|
type ArrayInitializationValues struct {
|
||||||
location file.Location
|
locatable
|
||||||
values []Argument
|
values []Argument
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ const (
|
|||||||
// Argument represents a value that can be placed anywhere a value goes. This
|
// Argument represents a value that can be placed anywhere a value goes. This
|
||||||
// allows things like phrases being arguments to other phrases.
|
// allows things like phrases being arguments to other phrases.
|
||||||
type Argument struct {
|
type Argument struct {
|
||||||
location file.Location
|
locatable
|
||||||
kind ArgumentKind
|
kind ArgumentKind
|
||||||
value any
|
value any
|
||||||
// TODO: if there is an argument expansion operator its existence should
|
// TODO: if there is an argument expansion operator its existence should
|
||||||
@ -148,7 +148,7 @@ type Argument struct {
|
|||||||
|
|
||||||
// DataSection represents a global variable.
|
// DataSection represents a global variable.
|
||||||
type DataSection struct {
|
type DataSection struct {
|
||||||
location file.Location
|
locatable
|
||||||
name string
|
name string
|
||||||
|
|
||||||
what Type
|
what Type
|
||||||
@ -158,7 +158,7 @@ type DataSection struct {
|
|||||||
|
|
||||||
// TypeSection represents a blind type definition.
|
// TypeSection represents a blind type definition.
|
||||||
type TypeSection struct {
|
type TypeSection struct {
|
||||||
location file.Location
|
locatable
|
||||||
name string
|
name string
|
||||||
|
|
||||||
inherits Type
|
inherits Type
|
||||||
@ -168,7 +168,7 @@ type TypeSection struct {
|
|||||||
|
|
||||||
// ObjtMember represents a part of an object type definition.
|
// ObjtMember represents a part of an object type definition.
|
||||||
type ObjtMember struct {
|
type ObjtMember struct {
|
||||||
location file.Location
|
locatable
|
||||||
name string
|
name string
|
||||||
|
|
||||||
what Type
|
what Type
|
||||||
@ -179,7 +179,7 @@ type ObjtMember struct {
|
|||||||
|
|
||||||
// ObjtSection represents an object type definition.
|
// ObjtSection represents an object type definition.
|
||||||
type ObjtSection struct {
|
type ObjtSection struct {
|
||||||
location file.Location
|
locatable
|
||||||
name string
|
name string
|
||||||
|
|
||||||
inherits Identifier
|
inherits Identifier
|
||||||
@ -189,14 +189,14 @@ type ObjtSection struct {
|
|||||||
|
|
||||||
// EnumMember represents a member of an enum section.
|
// EnumMember represents a member of an enum section.
|
||||||
type EnumMember struct {
|
type EnumMember struct {
|
||||||
location file.Location
|
locatable
|
||||||
name string
|
name string
|
||||||
value Argument
|
value Argument
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnumSection represents an enumerated type section.
|
// EnumSection represents an enumerated type section.
|
||||||
type EnumSection struct {
|
type EnumSection struct {
|
||||||
location file.Location
|
locatable
|
||||||
name string
|
name string
|
||||||
|
|
||||||
what Type
|
what Type
|
||||||
@ -206,7 +206,7 @@ type EnumSection struct {
|
|||||||
|
|
||||||
// FaceBehavior represents a behavior of an interface section.
|
// FaceBehavior represents a behavior of an interface section.
|
||||||
type FaceBehavior struct {
|
type FaceBehavior struct {
|
||||||
location file.Location
|
locatable
|
||||||
name string
|
name string
|
||||||
|
|
||||||
inputs []Declaration
|
inputs []Declaration
|
||||||
@ -215,7 +215,7 @@ type FaceBehavior struct {
|
|||||||
|
|
||||||
// FaceSection represents an interface type section.
|
// FaceSection represents an interface type section.
|
||||||
type FaceSection struct {
|
type FaceSection struct {
|
||||||
location file.Location
|
locatable
|
||||||
name string
|
name string
|
||||||
inherits Identifier
|
inherits Identifier
|
||||||
|
|
||||||
@ -268,7 +268,7 @@ type FuncOutput struct {
|
|||||||
|
|
||||||
// FuncSection represents a function section.
|
// FuncSection represents a function section.
|
||||||
type FuncSection struct {
|
type FuncSection struct {
|
||||||
location file.Location
|
locatable
|
||||||
name string
|
name string
|
||||||
permission types.Permission
|
permission types.Permission
|
||||||
|
|
||||||
|
@ -13,7 +13,8 @@ func (parser *ParsingOperation) parseTypeSection () (
|
|||||||
err = parser.expect(lexer.TokenKindName)
|
err = parser.expect(lexer.TokenKindName)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
section = &TypeSection { location: parser.token.Location() }
|
section = &TypeSection { }
|
||||||
|
section.setLocation(parser.token.Location())
|
||||||
|
|
||||||
// get permission
|
// get permission
|
||||||
err = parser.nextToken(lexer.TokenKindPermission)
|
err = parser.nextToken(lexer.TokenKindPermission)
|
||||||
|
Reference in New Issue
Block a user