Added module referencing to parser
This commit is contained in:
parent
308efbbd5e
commit
af73d8e251
@ -61,8 +61,9 @@ func (this *Declaration) String () string {
|
||||
type Call struct {
|
||||
// Syntax
|
||||
Pos lexer.Position
|
||||
Name string `parser:" '[' @Ident "`
|
||||
Arguments []Expression `parser:" @@* ']' "`
|
||||
Module string `parser:" (@Ident '::')? "`
|
||||
Name string `parser:" '[' @Ident "`
|
||||
Arguments []Expression `parser:" @@* ']' "`
|
||||
|
||||
// Semantics
|
||||
Function *Function
|
||||
@ -71,7 +72,11 @@ func (*Call) expression(){}
|
||||
func (*Call) statement(){}
|
||||
func (this *Call) Type () Type { return this.Function.Signature.Return }
|
||||
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 {
|
||||
out += fmt.Sprint(" ", argument)
|
||||
}
|
||||
|
@ -16,14 +16,21 @@ type Type interface {
|
||||
// TypeNamed refers to a user-defined or built in named type.
|
||||
type TypeNamed struct {
|
||||
Pos lexer.Position
|
||||
Name string `parser:" @TypeIdent "`
|
||||
Type Type
|
||||
Module string `parser:" (@Ident '::')? "`
|
||||
Name string `parser:" @TypeIdent "`
|
||||
Type Type
|
||||
}
|
||||
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 {
|
||||
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.
|
||||
|
@ -191,3 +191,13 @@ File.[write size:Index nmemb:Index]: Index 'fwrite'
|
||||
[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.MemberAccess),
|
||||
new(entity.Declaration),
|
||||
new(entity.Variable),
|
||||
new(entity.Subscript),
|
||||
new(entity.Slice),
|
||||
new(entity.Length),
|
||||
@ -43,6 +42,7 @@ var parser = participle.MustBuild[Tree] (
|
||||
new(entity.BitCast),
|
||||
new(entity.Operation),
|
||||
new(entity.Call),
|
||||
new(entity.Variable),
|
||||
new(entity.Block)),
|
||||
participle.Union[entity.Statement] (
|
||||
new(entity.LiteralInt),
|
||||
@ -58,7 +58,6 @@ var parser = participle.MustBuild[Tree] (
|
||||
new(entity.MethodCall),
|
||||
new(entity.MemberAccess),
|
||||
new(entity.Declaration),
|
||||
new(entity.Variable),
|
||||
new(entity.Subscript),
|
||||
new(entity.Slice),
|
||||
new(entity.Length),
|
||||
@ -68,6 +67,7 @@ var parser = participle.MustBuild[Tree] (
|
||||
new(entity.BitCast),
|
||||
new(entity.Operation),
|
||||
new(entity.Call),
|
||||
new(entity.Variable),
|
||||
new(entity.Block)),
|
||||
participle.UseLookahead(participle.MaxLookahead),
|
||||
participle.Lexer(flexer.NewDefinition()))
|
||||
|
Loading…
Reference in New Issue
Block a user