diff --git a/entity/expression.go b/entity/expression.go index 92cff0b..0cd37dd 100644 --- a/entity/expression.go +++ b/entity/expression.go @@ -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) } diff --git a/entity/type.go b/entity/type.go index 1d330f8..4b5ea91 100644 --- a/entity/type.go +++ b/entity/type.go @@ -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. diff --git a/parser/parser_test.go b/parser/parser_test.go index 0f05f51..4bfef18 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -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'] +`) +} diff --git a/parser/tree.go b/parser/tree.go index 67ae1c4..08cb808 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -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()))