Remove entity dependency on participle

This commit is contained in:
Sasha Koshka 2024-02-05 15:16:11 -05:00
parent eab8163cf1
commit decc5939a1
5 changed files with 80 additions and 80 deletions

View File

@ -1,7 +1,7 @@
package entity
import "fmt"
import "github.com/alecthomas/participle/v2/lexer"
import "git.tebibyte.media/sashakoshka/fspl/errors"
// Expression is any construct that can be evaluated.
type Expression interface {
@ -22,7 +22,7 @@ type Statement interface {
// location expression.
type Variable struct {
// Syntax
Pos lexer.Position
Position errors.Position
Name string `parser:" @Ident "`
// Semantics
@ -41,9 +41,9 @@ func (this *Variable) String () string {
// assigned to an interface. A declaration is always a valid location
// expression.
type Declaration struct {
Pos lexer.Position
Name string `parser:" @Ident "`
Ty Type `parser:" ':' @@ "`
Position errors.Position
Name string `parser:" @Ident "`
Ty Type `parser:" ':' @@ "`
}
func (*Declaration) expression(){}
func (*Declaration) statement(){}
@ -60,7 +60,7 @@ func (this *Declaration) String () string {
// expression.
type Call struct {
// Syntax
Pos lexer.Position
Position errors.Position
Module string `parser:" (@Ident '::')? "`
Name string `parser:" '[' @Ident "`
Arguments []Expression `parser:" @@* ']' "`
@ -91,7 +91,7 @@ func (this *Call) String () string {
// A method call is never a valid location expression.
type MethodCall struct {
// Syntax
Pos lexer.Position
Position errors.Position
Source *Variable `parser:" @@ '.' "`
Name string `parser:" '[' @Ident "`
Arguments []Expression `parser:" @@* ']' "`
@ -125,9 +125,9 @@ func (this *MethodCall) String () string {
// valid location expression only if the array being subscripted is.
type Subscript struct {
// Syntax
Pos lexer.Position
Slice Expression `parser:" '[' '.' @@ "`
Offset Expression `parser:" @@ ']' "`
Position errors.Position
Slice Expression `parser:" '[' '.' @@ "`
Offset Expression `parser:" @@ ']' "`
// Semantics
Ty Type
@ -145,10 +145,10 @@ func (this *Subscript) String () string {
// is operating on. A slice is never a valid location expression.
type Slice struct {
// Syntax
Pos lexer.Position
Slice Expression `parser:" '[' '\\\\' @@ "`
Start Expression `parser:" @@? "`
End Expression `parser:" ':' @@? ']' "`
Position errors.Position
Slice Expression `parser:" '[' '\\\\' @@ "`
Start Expression `parser:" @@? "`
End Expression `parser:" ':' @@? ']' "`
}
func (*Slice) expression(){}
func (*Slice) statement(){}
@ -188,8 +188,8 @@ func (this *Length) String () string {
// if the pointer being dereferenced is.
type Dereference struct {
// Syntax
Pos lexer.Position
Pointer Expression `parser:" '[' '.' @@ ']' "`
Position errors.Position
Pointer Expression `parser:" '[' '.' @@ ']' "`
// Semantics
Ty Type
@ -210,8 +210,8 @@ func (this *Dereference) String () string {
// expression.
type Reference struct {
// Syntax
Pos lexer.Position
Value Expression `parser:" '[' '@' @@ ']' "`
Position errors.Position
Value Expression `parser:" '[' '@' @@ ']' "`
// Semantics
Ty Type
@ -227,9 +227,9 @@ func (this *Reference) String () string {
// contains inherent type information, it may be directly assigned to an
// interface. A value cast is never a valid location expression.
type ValueCast struct {
Pos lexer.Position
Ty Type `parser:" '[' '~' @@ "`
Value Expression `parser:" @@ ']' "`
Position errors.Position
Ty Type `parser:" '[' '~' @@ "`
Value Expression `parser:" @@ ']' "`
}
func (*ValueCast) expression(){}
func (*ValueCast) statement(){}
@ -243,9 +243,9 @@ func (this *ValueCast) String () string {
// it may be directly assigned to an interface. A bit cast is never a valid
// location expression.
type BitCast struct {
Pos lexer.Position
Ty Type `parser:" '[' '~~' @@ "`
Value Expression `parser:" @@ ']' "`
Position errors.Position
Ty Type `parser:" '[' '~~' @@ "`
Value Expression `parser:" @@ ']' "`
}
func (*BitCast) expression(){}
func (*BitCast) statement(){}
@ -260,8 +260,8 @@ func (this *BitCast) String () string {
// be assigned to interfaces. An operation is never a valid location expression.
type Operation struct {
// Syntax
Pos lexer.Position
Operator Operator `parser:" '[' @('++' | '+' | '--' | '-' | '*' | '/' | '%' | '!!' | '||' | '&&' | '^^' | '!' | '|' | '&' | '^' | '<<' | '>>' | '<' | '>' | '<=' | '>=' | '=') "`
Position errors.Position
Operator Operator `parser:" '[' @('++' | '+' | '--' | '-' | '*' | '/' | '%' | '!!' | '||' | '&&' | '^^' | '!' | '|' | '&' | '^' | '<<' | '>>' | '<' | '>' | '<=' | '>=' | '=') "`
Arguments []Expression `parser:" @@+ ']' "`
// Semantics
@ -285,8 +285,8 @@ func (this *Operation) String () string {
// expression.
type Block struct {
// Syntax
Pos lexer.Position
Steps []Statement `parser:" '{' @@* '}' "`
Position errors.Position
Steps []Statement `parser:" '{' @@* '}' "`
// Semantics
Ty Type
@ -312,9 +312,9 @@ func (this *Block) String () string {
// struct being accessed is.
type MemberAccess struct {
// Syntax
Pos lexer.Position
Source *Variable `parser:" @@ "`
Member string `parser:" '.' @Ident "`
Position errors.Position
Source *Variable `parser:" @@ "`
Member string `parser:" '.' @Ident "`
// Semantics
Ty Type
@ -333,7 +333,7 @@ func (this *MemberAccess) String () string {
// expressions. An If/else is never a valid location expression.
type IfElse struct {
// Syntax
Pos lexer.Position
Position errors.Position
Condition Expression `parser:" 'if' @@ "`
True Expression `parser:" 'then' @@ "`
False Expression `parser:" ('else' @@)? "`
@ -361,8 +361,8 @@ func (this *IfElse) String () string {
// loop's expression is never used. A loop is never a valid location expression.
type Loop struct {
// Syntax
Pos lexer.Position
Body Expression `parser:" 'loop' @@ "`
Position errors.Position
Body Expression `parser:" 'loop' @@ "`
// Semantics
Ty Type
@ -378,8 +378,8 @@ func (this *Loop) String () string {
// to anything. It is never a valid location expression.
type Break struct {
// Syntax
Pos lexer.Position
Value Expression `parser:" '[' 'break' @@? ']' "`
Position errors.Position
Value Expression `parser:" '[' 'break' @@? ']' "`
// Semantics
Loop *Loop
@ -401,8 +401,8 @@ func (this *Break) String () string {
// to anything. A return statement is never a valid location expression.
type Return struct {
// Syntax
Pos lexer.Position
Value Expression `parser:" '[' 'return' @@? ']' "`
Position errors.Position
Value Expression `parser:" '[' 'return' @@? ']' "`
// Semantics
Declaration TopLevel
@ -423,7 +423,7 @@ func (this *Return) String () string {
// not be assigned to anything. An assignment statement is never a valid
// location expression.
type Assignment struct {
Pos lexer.Position
Position errors.Position
Location Expression `parser:" @@ "`
Value Expression `parser:" '=' @@ "`
}

View File

@ -2,7 +2,7 @@ package entity
import "fmt"
import "unicode"
import "github.com/alecthomas/participle/v2/lexer"
import "git.tebibyte.media/sashakoshka/fspl/errors"
// LiteralInt specifies an integer value. It can be assigned to any type that is
// derived from an integer or a float, as long as the value fo the literal can
@ -11,7 +11,7 @@ import "github.com/alecthomas/participle/v2/lexer"
// be used for this purpose.
type LiteralInt struct {
// Syntax
Pos lexer.Position
Position errors.Position
Value int `parser:" @Int "`
// Semantics
@ -30,7 +30,7 @@ func (this *LiteralInt) String () string {
// for this purpose.
type LiteralFloat struct {
// Syntax
Pos lexer.Position
Position errors.Position
Value float64 `parser:" @Float "`
// Semantics
@ -60,7 +60,7 @@ func (this *LiteralFloat) String () string {
// purpose.
type LiteralString struct {
// Syntax
Pos lexer.Position
Position errors.Position
ValueUTF8 string `parser:" @String "`
ValueUTF16 []uint16
ValueUTF32 []rune
@ -94,7 +94,7 @@ func (this *LiteralString) String () string {
// inherent type information. A value cast may be used for this purpose.
type LiteralArray struct {
// Syntax
Pos lexer.Position
Position errors.Position
Elements []Expression `parser:" '(' '*' @@* ')' "`
// Semantics
@ -120,8 +120,8 @@ func (this *LiteralArray) String () string {
// inherent type information. A value cast may be used for this purpose.
type LiteralStruct struct {
// Syntax
Pos lexer.Position
Members []*Member `parser:" '(' @@* ')' "`
Position errors.Position
Members []*Member `parser:" '(' @@* ')' "`
// Semantics
Ty Type
@ -146,8 +146,8 @@ func (this *LiteralStruct) String () string {
// value cast may be used for this purpose.
type LiteralBoolean struct {
// Syntax
Pos lexer.Position
Value *Boolean `parser:" @('true' | 'false') "`
Position errors.Position
Value *Boolean `parser:" @('true' | 'false') "`
// Semantics
Ty Type
@ -172,8 +172,8 @@ func (this *Boolean) Capture (values []string) error {
type LiteralNil struct {
// Syntax
Pos lexer.Position
Value string `parser:" @'nil' "`
Position errors.Position
Value string `parser:" @'nil' "`
// Semantics
Ty Type

View File

@ -2,14 +2,14 @@ package entity
import "fmt"
import "strings"
import "github.com/alecthomas/participle/v2/lexer"
import "git.tebibyte.media/sashakoshka/fspl/errors"
// Signature is a function or method signature that is used in functions,
// methods, and specifying interface behaviors. It defines the type of a
// function.
type Signature struct {
// Syntax
Pos lexer.Position
Position errors.Position
Name string `parser:" '[' @Ident "`
Arguments []*Declaration `parser:" @@* ']' "`
Return Type `parser:" ( ':' @@ )? "`
@ -48,9 +48,9 @@ func (this *Signature) Equals (ty Type) bool {
// Member is a syntactical construct that is used to list members in struct
// literals.
type Member struct {
Pos lexer.Position
Name string `parser:" @Ident "`
Value Expression `parser:" ':' @@ "`
Position errors.Position
Name string `parser:" @Ident "`
Value Expression `parser:" ':' @@ "`
}
func (this *Member) String () string {
return fmt.Sprint(this.Name, ":", this.Value)

View File

@ -1,7 +1,7 @@
package entity
import "fmt"
import "github.com/alecthomas/participle/v2/lexer"
import "git.tebibyte.media/sashakoshka/fspl/errors"
// TopLevel is any construct that is placed at the root of a file.
type TopLevel interface {
@ -36,7 +36,7 @@ func (this *Access) Capture (values []string) error {
// Typedef binds a type to a global identifier.
type Typedef struct {
// Syntax
Pos lexer.Position
Position errors.Position
Acc *Access `parser:" @('-' | '~' | '+')? "`
Name string `parser:" @TypeIdent "`
Type Type `parser:" ':' @@ "`
@ -66,7 +66,7 @@ func (this *Typedef) String () string {
// these are typed.
type Function struct {
// Syntax
Pos lexer.Position
Position errors.Position
Acc *Access `parser:" @('-' | '~' | '+')? "`
Signature *Signature `parser:" @@ "`
LinkName string `parser:" @String? "`
@ -97,7 +97,7 @@ func (this *Function) String () string {
// unique, but are unique within the type they are defined on.
type Method struct {
// Syntax
Pos lexer.Position
Position errors.Position
Acc *Access `parser:" @('-' | '~' | '+')? "`
TypeName string `parser:" @TypeIdent "`
Signature *Signature `parser:" '.' @@ "`

View File

@ -1,7 +1,7 @@
package entity
import "fmt"
import "github.com/alecthomas/participle/v2/lexer"
import "git.tebibyte.media/sashakoshka/fspl/errors"
// Type is any type notation.
type Type interface {
@ -15,10 +15,10 @@ type Type interface {
// TypeNamed refers to a user-defined or built in named type.
type TypeNamed struct {
Pos lexer.Position
Module string `parser:" (@Ident '::')? "`
Name string `parser:" @TypeIdent "`
Type Type
Position errors.Position
Module string `parser:" (@Ident '::')? "`
Name string `parser:" @TypeIdent "`
Type Type
}
func (*TypeNamed) ty(){}
func (this *TypeNamed) String () string {
@ -35,7 +35,7 @@ func (this *TypeNamed) Equals (ty Type) bool {
// TypePointer is a pointer to another type.
type TypePointer struct {
Pos lexer.Position
Position errors.Position
Referenced Type `parser:" '*' @@ "`
}
func (*TypePointer) ty(){}
@ -51,8 +51,8 @@ func (this *TypePointer) Equals (ty Type) bool {
// eachother. Its length is not built into its type and can be changed at
// runtime.
type TypeSlice struct {
Pos lexer.Position
Element Type `parser:" '*' ':' @@ "`
Position errors.Position
Element Type `parser:" '*' ':' @@ "`
}
func (*TypeSlice) ty(){}
func (this *TypeSlice) String () string {
@ -67,9 +67,9 @@ func (this *TypeSlice) Equals (ty Type) bool {
// length of an array is fixed and is part of its type. Arrays are passed by
// value unless a pointer is used.
type TypeArray struct {
Pos lexer.Position
Length int `parser:" @Int "`
Element Type `parser:" ':' @@ "`
Position errors.Position
Length int `parser:" @Int "`
Element Type `parser:" ':' @@ "`
}
func (*TypeArray) ty(){}
func (this *TypeArray) String () string {
@ -87,8 +87,8 @@ func (this *TypeArray) Equals (ty Type) bool {
// are specified in. Structs are passed by value unless a pointer is used.
type TypeStruct struct {
// Syntax
Pos lexer.Position
Members []*Declaration `parser:" '(' @@+ ')' "`
Position errors.Position
Members []*Declaration `parser:" '(' @@+ ')' "`
// Semantics
MemberOrder []string
@ -122,7 +122,7 @@ func (this *TypeStruct) Equals (ty Type) bool {
// pointer to an interface, the pointer's reference will be used instead.
type TypeInterface struct {
// Syntax
Pos lexer.Position
Position errors.Position
Behaviors []*Signature `parser:" '(' @@+ ')' "`
// Semantics
@ -152,9 +152,9 @@ func (this *TypeInterface) Equals (ty Type) bool {
// TypeInt represents any signed or unsigned integer type.
type TypeInt struct {
Pos lexer.Position
Width int
Signed bool
Position errors.Position
Width int
Signed bool
}
func (*TypeInt) ty(){}
func (this *TypeInt) String () string {
@ -171,8 +171,8 @@ func (this *TypeInt) Equals (ty Type) bool {
// TypeFloat represents any floating point type.
type TypeFloat struct {
Pos lexer.Position
Width int
Position errors.Position
Width int
}
func (*TypeFloat) ty(){}
func (this *TypeFloat) String () string {
@ -187,8 +187,8 @@ func (this *TypeFloat) Equals (ty Type) bool {
// is chosen based on the machine word size (32 on 32 bit systems, 64 on 64 bit
// systems, etc)
type TypeWord struct {
Pos lexer.Position
Signed bool
Position errors.Position
Signed bool
}
func (*TypeWord) ty(){}
func (this *TypeWord) String () string {