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,7 +41,7 @@ func (this *Variable) String () string {
// assigned to an interface. A declaration is always a valid location
// expression.
type Declaration struct {
Pos lexer.Position
Position errors.Position
Name string `parser:" @Ident "`
Ty Type `parser:" ':' @@ "`
}
@ -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,7 +125,7 @@ func (this *MethodCall) String () string {
// valid location expression only if the array being subscripted is.
type Subscript struct {
// Syntax
Pos lexer.Position
Position errors.Position
Slice Expression `parser:" '[' '.' @@ "`
Offset Expression `parser:" @@ ']' "`
@ -145,7 +145,7 @@ func (this *Subscript) String () string {
// is operating on. A slice is never a valid location expression.
type Slice struct {
// Syntax
Pos lexer.Position
Position errors.Position
Slice Expression `parser:" '[' '\\\\' @@ "`
Start Expression `parser:" @@? "`
End Expression `parser:" ':' @@? ']' "`
@ -188,7 +188,7 @@ func (this *Length) String () string {
// if the pointer being dereferenced is.
type Dereference struct {
// Syntax
Pos lexer.Position
Position errors.Position
Pointer Expression `parser:" '[' '.' @@ ']' "`
// Semantics
@ -210,7 +210,7 @@ func (this *Dereference) String () string {
// expression.
type Reference struct {
// Syntax
Pos lexer.Position
Position errors.Position
Value Expression `parser:" '[' '@' @@ ']' "`
// Semantics
@ -227,7 +227,7 @@ 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
Position errors.Position
Ty Type `parser:" '[' '~' @@ "`
Value Expression `parser:" @@ ']' "`
}
@ -243,7 +243,7 @@ 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
Position errors.Position
Ty Type `parser:" '[' '~~' @@ "`
Value Expression `parser:" @@ ']' "`
}
@ -260,7 +260,7 @@ func (this *BitCast) String () string {
// be assigned to interfaces. An operation is never a valid location expression.
type Operation struct {
// Syntax
Pos lexer.Position
Position errors.Position
Operator Operator `parser:" '[' @('++' | '+' | '--' | '-' | '*' | '/' | '%' | '!!' | '||' | '&&' | '^^' | '!' | '|' | '&' | '^' | '<<' | '>>' | '<' | '>' | '<=' | '>=' | '=') "`
Arguments []Expression `parser:" @@+ ']' "`
@ -285,7 +285,7 @@ func (this *Operation) String () string {
// expression.
type Block struct {
// Syntax
Pos lexer.Position
Position errors.Position
Steps []Statement `parser:" '{' @@* '}' "`
// Semantics
@ -312,7 +312,7 @@ func (this *Block) String () string {
// struct being accessed is.
type MemberAccess struct {
// Syntax
Pos lexer.Position
Position errors.Position
Source *Variable `parser:" @@ "`
Member string `parser:" '.' @Ident "`
@ -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,7 +361,7 @@ 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
Position errors.Position
Body Expression `parser:" 'loop' @@ "`
// Semantics
@ -378,7 +378,7 @@ func (this *Loop) String () string {
// to anything. It is never a valid location expression.
type Break struct {
// Syntax
Pos lexer.Position
Position errors.Position
Value Expression `parser:" '[' 'break' @@? ']' "`
// Semantics
@ -401,7 +401,7 @@ func (this *Break) String () string {
// to anything. A return statement is never a valid location expression.
type Return struct {
// Syntax
Pos lexer.Position
Position errors.Position
Value Expression `parser:" '[' 'return' @@? ']' "`
// Semantics
@ -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,7 +120,7 @@ func (this *LiteralArray) String () string {
// inherent type information. A value cast may be used for this purpose.
type LiteralStruct struct {
// Syntax
Pos lexer.Position
Position errors.Position
Members []*Member `parser:" '(' @@* ')' "`
// Semantics
@ -146,7 +146,7 @@ func (this *LiteralStruct) String () string {
// value cast may be used for this purpose.
type LiteralBoolean struct {
// Syntax
Pos lexer.Position
Position errors.Position
Value *Boolean `parser:" @('true' | 'false') "`
// Semantics
@ -172,7 +172,7 @@ func (this *Boolean) Capture (values []string) error {
type LiteralNil struct {
// Syntax
Pos lexer.Position
Position errors.Position
Value string `parser:" @'nil' "`
// Semantics

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,7 +48,7 @@ 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
Position errors.Position
Name string `parser:" @Ident "`
Value Expression `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"
// 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,7 +15,7 @@ type Type interface {
// TypeNamed refers to a user-defined or built in named type.
type TypeNamed struct {
Pos lexer.Position
Position errors.Position
Module string `parser:" (@Ident '::')? "`
Name string `parser:" @TypeIdent "`
Type Type
@ -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,7 +51,7 @@ 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
Position errors.Position
Element Type `parser:" '*' ':' @@ "`
}
func (*TypeSlice) ty(){}
@ -67,7 +67,7 @@ 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
Position errors.Position
Length int `parser:" @Int "`
Element Type `parser:" ':' @@ "`
}
@ -87,7 +87,7 @@ 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
Position errors.Position
Members []*Declaration `parser:" '(' @@+ ')' "`
// Semantics
@ -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,7 +152,7 @@ func (this *TypeInterface) Equals (ty Type) bool {
// TypeInt represents any signed or unsigned integer type.
type TypeInt struct {
Pos lexer.Position
Position errors.Position
Width int
Signed bool
}
@ -171,7 +171,7 @@ func (this *TypeInt) Equals (ty Type) bool {
// TypeFloat represents any floating point type.
type TypeFloat struct {
Pos lexer.Position
Position errors.Position
Width int
}
func (*TypeFloat) ty(){}
@ -187,7 +187,7 @@ 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
Position errors.Position
Signed bool
}
func (*TypeWord) ty(){}