Added module referencing to parser
This commit is contained in:
parent
308efbbd5e
commit
af73d8e251
@ -61,6 +61,7 @@ func (this *Declaration) String () string {
|
|||||||
type Call struct {
|
type Call struct {
|
||||||
// Syntax
|
// Syntax
|
||||||
Pos lexer.Position
|
Pos lexer.Position
|
||||||
|
Module string `parser:" (@Ident '::')? "`
|
||||||
Name string `parser:" '[' @Ident "`
|
Name string `parser:" '[' @Ident "`
|
||||||
Arguments []Expression `parser:" @@* ']' "`
|
Arguments []Expression `parser:" @@* ']' "`
|
||||||
|
|
||||||
@ -71,7 +72,11 @@ func (*Call) expression(){}
|
|||||||
func (*Call) statement(){}
|
func (*Call) statement(){}
|
||||||
func (this *Call) Type () Type { return this.Function.Signature.Return }
|
func (this *Call) Type () Type { return this.Function.Signature.Return }
|
||||||
func (this *Call) String () string {
|
func (this *Call) String () string {
|
||||||
out := fmt.Sprint("[", this.Name)
|
out := ""
|
||||||
|
if this.Module != "" {
|
||||||
|
out += fmt.Sprint(this.Module, "::")
|
||||||
|
}
|
||||||
|
out += fmt.Sprint("[", this.Name)
|
||||||
for _, argument := range this.Arguments {
|
for _, argument := range this.Arguments {
|
||||||
out += fmt.Sprint(" ", argument)
|
out += fmt.Sprint(" ", argument)
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,21 @@ type Type interface {
|
|||||||
// TypeNamed refers to a user-defined or built in named type.
|
// TypeNamed refers to a user-defined or built in named type.
|
||||||
type TypeNamed struct {
|
type TypeNamed struct {
|
||||||
Pos lexer.Position
|
Pos lexer.Position
|
||||||
|
Module string `parser:" (@Ident '::')? "`
|
||||||
Name string `parser:" @TypeIdent "`
|
Name string `parser:" @TypeIdent "`
|
||||||
Type Type
|
Type Type
|
||||||
}
|
}
|
||||||
func (*TypeNamed) ty(){}
|
func (*TypeNamed) ty(){}
|
||||||
func (this *TypeNamed) String () string { return this.Name }
|
func (this *TypeNamed) String () string {
|
||||||
|
if this.Module == "" {
|
||||||
|
return this.Name
|
||||||
|
} else {
|
||||||
|
return fmt.Sprint(this.Module, "::", this.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
func (this *TypeNamed) Equals (ty Type) bool {
|
func (this *TypeNamed) Equals (ty Type) bool {
|
||||||
real, ok := ty.(*TypeNamed)
|
real, ok := ty.(*TypeNamed)
|
||||||
return ok && real.Name == this.Name
|
return ok && real.Name == this.Name && real.Module == this.Module
|
||||||
}
|
}
|
||||||
|
|
||||||
// TypePointer is a pointer to another type.
|
// TypePointer is a pointer to another type.
|
||||||
|
@ -191,3 +191,13 @@ File.[write size:Index nmemb:Index]: Index 'fwrite'
|
|||||||
[main]: Int 'main' = 0
|
[main]: Int 'main' = 0
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestModuleNamespace (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
// correct
|
||||||
|
`[hello out:io::Writer] = ioutil::[writeString out 'hello']`,
|
||||||
|
// input
|
||||||
|
`
|
||||||
|
[hello out:io::Writer] = ioutil::[writeString out 'hello']
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
@ -33,7 +33,6 @@ var parser = participle.MustBuild[Tree] (
|
|||||||
new(entity.MethodCall),
|
new(entity.MethodCall),
|
||||||
new(entity.MemberAccess),
|
new(entity.MemberAccess),
|
||||||
new(entity.Declaration),
|
new(entity.Declaration),
|
||||||
new(entity.Variable),
|
|
||||||
new(entity.Subscript),
|
new(entity.Subscript),
|
||||||
new(entity.Slice),
|
new(entity.Slice),
|
||||||
new(entity.Length),
|
new(entity.Length),
|
||||||
@ -43,6 +42,7 @@ var parser = participle.MustBuild[Tree] (
|
|||||||
new(entity.BitCast),
|
new(entity.BitCast),
|
||||||
new(entity.Operation),
|
new(entity.Operation),
|
||||||
new(entity.Call),
|
new(entity.Call),
|
||||||
|
new(entity.Variable),
|
||||||
new(entity.Block)),
|
new(entity.Block)),
|
||||||
participle.Union[entity.Statement] (
|
participle.Union[entity.Statement] (
|
||||||
new(entity.LiteralInt),
|
new(entity.LiteralInt),
|
||||||
@ -58,7 +58,6 @@ var parser = participle.MustBuild[Tree] (
|
|||||||
new(entity.MethodCall),
|
new(entity.MethodCall),
|
||||||
new(entity.MemberAccess),
|
new(entity.MemberAccess),
|
||||||
new(entity.Declaration),
|
new(entity.Declaration),
|
||||||
new(entity.Variable),
|
|
||||||
new(entity.Subscript),
|
new(entity.Subscript),
|
||||||
new(entity.Slice),
|
new(entity.Slice),
|
||||||
new(entity.Length),
|
new(entity.Length),
|
||||||
@ -68,6 +67,7 @@ var parser = participle.MustBuild[Tree] (
|
|||||||
new(entity.BitCast),
|
new(entity.BitCast),
|
||||||
new(entity.Operation),
|
new(entity.Operation),
|
||||||
new(entity.Call),
|
new(entity.Call),
|
||||||
|
new(entity.Variable),
|
||||||
new(entity.Block)),
|
new(entity.Block)),
|
||||||
participle.UseLookahead(participle.MaxLookahead),
|
participle.UseLookahead(participle.MaxLookahead),
|
||||||
participle.Lexer(flexer.NewDefinition()))
|
participle.Lexer(flexer.NewDefinition()))
|
||||||
|
Loading…
Reference in New Issue
Block a user