Skip to content

Commit

Permalink
fix Issue 9503 - [grammar] template declaration/instance must take on…
Browse files Browse the repository at this point in the history
…e or more arguments?

- Define TemplateParameters and TemplateArguments, and use them as like Parameters
- Function template and template constructor also couldn't take zero template parameters.
  Moreover, DeclarationSuffix had been wrong, because TemplateParameterList does not have both side parenthesis.
  • Loading branch information
9rnsr committed Feb 13, 2013
1 parent 0f2f7d9 commit 2c34db6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion declaration.dd
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ $(GNAME DeclaratorSuffix):
$(D [ ])
$(D [) $(VEXPRESSION) $(D ])
$(D [) $(GLINK Type) $(D ])
$(GLINK2 template, TemplateParameterList)$(OPT) $(GLINK Parameters) $(GLINK MemberFunctionAttributes)$(OPT) $(GLINK2 template, Constraint)$(OPT)
$(GLINK2 template, TemplateParameters)$(OPT) $(GLINK Parameters) $(GLINK MemberFunctionAttributes)$(OPT) $(GLINK2 template, Constraint)$(OPT)

$(GNAME IdentifierList):
$(I Identifier)
Expand Down
10 changes: 5 additions & 5 deletions template-mixin.dd
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ $(SPEC_S Template Mixins,

$(GRAMMAR
$(GNAME TemplateMixinDeclaration):
$(B mixin) $(B template) $(TEMPLATEIDENTIFIER) $(B $(LPAREN)) $(TEMPLATEPARAMETERLIST) $(B $(RPAREN)) $(V2 $(GLINK2 template, Constraint)$(OPT))
$(B mixin) $(B template) $(TEMPLATEIDENTIFIER) $(TEMPLATEPARAMETERS) $(V2 $(GLINK2 template, Constraint)$(OPT))
$(B {) $(GLINK2 module, DeclDefs) $(B })

$(GNAME TemplateMixin):
$(B mixin) $(TEMPLATEIDENTIFIER) $(B ;)
$(B mixin) $(TEMPLATEIDENTIFIER) $(GLINK MixinIdentifier) $(B ;)
$(B mixin) $(TEMPLATEIDENTIFIER) $(B !$(LPAREN)) $(TEMPLATEARGUMENTLIST) $(B $(RPAREN)) $(B ;)
$(B mixin) $(TEMPLATEIDENTIFIER) $(B !$(LPAREN)) $(TEMPLATEARGUMENTLIST) $(B $(RPAREN)) $(GLINK MixinIdentifier) $(B ;)
$(B mixin) $(TEMPLATEIDENTIFIER) $(TEMPLATEARGUMENTS) $(B ;)
$(B mixin) $(TEMPLATEIDENTIFIER) $(TEMPLATEARGUMENTS) $(GLINK MixinIdentifier) $(B ;)

$(GNAME MixinIdentifier):
$(I Identifier)
Expand Down Expand Up @@ -306,6 +306,6 @@ Macros:
WIKI=Mixin
CATEGORY_SPEC=$0
TEMPLATEIDENTIFIER=$(GLINK2 template, TemplateIdentifier)
TEMPLATEPARAMETERLIST=$(GLINK2 template, TemplateParameterList)
TEMPLATEARGUMENTLIST=$(GLINK2 template, TemplateArgumentList)
TEMPLATEPARAMETERS=$(GLINK2 template, TemplateParameters)
TEMPLATEARGUMENTS=$(GLINK2 template, TemplateArguments)
FOO=
16 changes: 12 additions & 4 deletions template.dd
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ $(P Templates are D's approach to generic programming.

$(GRAMMAR
$(GNAME TemplateDeclaration):
$(B template) $(GLINK TemplateIdentifier) $(B $(LPAREN)) $(GLINK TemplateParameterList) $(B $(RPAREN)) $(GLINK Constraint)$(OPT)
$(B template) $(GLINK TemplateIdentifier) $(GLINK TemplateParameters) $(GLINK Constraint)$(OPT)
$(B {) $(GLINK2 module, DeclDefs) $(B })

$(GNAME TemplateIdentifier):
$(I Identifier)

$(GNAME TemplateParameters):
$(B $(LPAREN) $(RPAREN))
$(B $(LPAREN)) $(GLINK TemplateParameterList) $(B $(RPAREN))

$(GNAME TemplateParameterList):
$(GLINK TemplateParameter)
$(GLINK TemplateParameter) ,
Expand Down Expand Up @@ -65,8 +69,12 @@ $(P

$(GRAMMAR
$(GNAME TemplateInstance):
$(GLINK TemplateIdentifier) $(B !$(LPAREN)) $(GLINK TemplateArgumentList) $(B $(RPAREN))
$(GLINK TemplateIdentifier) $(B !) $(GLINK TemplateSingleArgument)
$(GLINK TemplateIdentifier) $(GLINK TemplateArguments)

$(GNAME TemplateArguments):
$(B !$(LPAREN) $(RPAREN))
$(B !$(LPAREN)) $(GLINK TemplateArgumentList) $(B $(RPAREN))
$(B !) $(GLINK TemplateSingleArgument)

$(GNAME TemplateArgumentList):
$(GLINK TemplateArgument)
Expand Down Expand Up @@ -747,7 +755,7 @@ $(H2 Template Constructors)

$(GRAMMAR
$(GNAME TemplatedConstructor):
$(B this) $(B $(LPAREN)) $(GLINK2 template, TemplateParameterList) $(B $(RPAREN)) $(GLINK2 declaration, Parameters) $(GLINK Constraint)$(OPT) $(GLINK2 function, FunctionBody)
$(B this) $(GLINK2 template, TemplateParameters) $(GLINK2 declaration, Parameters) $(GLINK Constraint)$(OPT) $(GLINK2 function, FunctionBody)
)

$(P Templates can be used to form constructors for classes and structs.
Expand Down

0 comments on commit 2c34db6

Please sign in to comment.