Trass3r wrote:
Original discussion forked in the D grammar thread, so I'm opening a new one
for this specific issue.
The D grammar is in dire need of an overhaul.
I suggest we discuss changes here and then put everything into github to issue
a pull request once everything's done.
I already forked the d-programming-language.org repo to get started by fixing
some mistakes. Hereafter I list some issues that come to my mind.
I'm not yet friend with git, but this might be a chance to get used to
it. How can I contribute patches? I guess this would be with pull
requests, so I'll need a github repository, too? The discussion page for
pull requests looks like a nice feature...
I'm not sure though it is a good place to keep an overview of the
grammar in a readable style. The grammar in the ddoc source is sometimes
rather polluted with formatting information and links.
As a starter, here are some syntactic problems in the ddoc sources that
cause the generation of grammar.txt to fail:
- in template.dd, $(GNAME Constraint) is not enclosed by $(GRAMMAR)
- in attribute.dd, $(GRAMMAR $(B const)), $(GRAMMAR $(B override)), etc
are used for formatting without having to do with the grammar. The boxes
they generate don't make much sense anyway, so they can just be removed.
- MulExpression is only in $(V1), so it does not show for D2
I've attached the patch for these.
Also there are 3 different instances of mixin: MixinExpression, MixinStatement
and MixinDeclaration. Even though they all come down to the same thing.
I think, the different mixin variants are ok, because you might want to
generate different AST for these.
Well I can imagine that MixinStatement is necessary because if you have an
ExpStatement with a MixinExpression the result is probably discarded (just like
'a' is discarded in a = 5;).
But why do you need another MixinDeclaration?
MixinDeclaration expands to declarations, while MixinStatement expands
to statements, so the difference is not interesting during parsing, but
might be important in the semantic pass (which restarts parsing for the
string).
From 7326cf6c2cb08069ef29b281244ae57f90171ce1 Mon Sep 17 00:00:00 2001
From: Rainer <r.sagita...@gmx.de>
Date: Thu, 31 Mar 2011 09:03:25 +0200
Subject: [PATCH] grammar formatting corrections
---
attribute.dd | 22 +---------------------
expression.dd | 4 +---
template.dd | 4 ++--
3 files changed, 4 insertions(+), 26 deletions(-)
diff --git a/attribute.dd b/attribute.dd
index 050a385..5db0dc8 100644
--- a/attribute.dd
+++ b/attribute.dd
@@ -277,10 +277,6 @@ $(GNAME ProtectionAttribute):
<h2>$(LNAME2 const, Const Attribute)</h2>
-$(GRAMMAR
-$(B const)
-)
-
$(P The $(B const) attribute declares constants that can be
evaluated at compile time. For example:
)
@@ -392,10 +388,6 @@ void main()
<h2>$(LNAME2 override, Override Attribute)</h2>
-$(GRAMMAR
-$(B override)
-)
-
$(P The $(B override) attribute applies to virtual functions.
It means that the function must override a function with the
same name and parameters in a base class. The override attribute
@@ -423,10 +415,6 @@ class Foo2 : Foo
<h2>Static Attribute</h2>
-$(GRAMMAR
-$(B static)
-)
-
$(P The $(B static) attribute applies to functions and data.
It means that the declaration does not apply to a particular
instance of an object, but to the type of the object. In
@@ -472,10 +460,6 @@ private int y = 4; // y is local to module foo
<h2>$(LNAME2 auto, Auto Attribute)</h2>
-$(GRAMMAR
-$(B auto)
-)
-
$(P The $(B auto) attribute is used when there are no other attributes
and type inference is desired.
)
@@ -486,10 +470,6 @@ auto i = 6.8; // declare i as a double
<h2>$(LNAME2 scope, Scope Attribute)</h2>
-$(GRAMMAR
-$(B scope)
-)
-
$(P
The $(B scope) attribute is used for local variables and for class
declarations. For class declarations, the $(B scope) attribute creates
@@ -541,5 +521,5 @@ $(P
Macros:
TITLE=Attributes
WIKI=Attribute
- CATEGORY_SPEC=$0
+ CATEGORY_SPEC=$0
diff --git a/expression.dd b/expression.dd
index cfee8d2..615441e 100644
--- a/expression.dd
+++ b/expression.dd
@@ -656,7 +656,6 @@ $(GNAME CatExpression):
<h2>Mul Expressions</h2>
-$(V1
$(GRAMMAR
$(GNAME MulExpression):
$(GLINK UnaryExpression)
@@ -664,7 +663,6 @@ $(GNAME MulExpression):
$(I MulExpression) $(B /) $(GLINK UnaryExpression)
$(I MulExpression) $(B %) $(GLINK UnaryExpression)
)
-)
$(P The operands must be arithmetic types. They undergo integral
promotions, and then are brought to a common type using the
@@ -1931,7 +1929,7 @@ void main()
Macros:
TITLE=Expressions
WIKI=Expression
- CATEGORY_SPEC=$0
+ CATEGORY_SPEC=$0
GLINK=$(LINK2 #$0, $(I $0))
GNAME=<a name=$0>$(I $0)</a>
DOLLAR=$
diff --git a/template.dd b/template.dd
index e46fe4d..8bbd9db 100644
--- a/template.dd
+++ b/template.dd
@@ -1000,13 +1000,13 @@ void test()
$(V2
<h2>Template Constraints</h2>
----
+$(GRAMMAR
$(GNAME Constraint):
$(B if) $(B $(LPAREN)) $(I ConstraintExpression) $(B $(RPAREN))
$(I ConstraintExpression):
$(I $(GLINK2 expression, Expression))
----
+)
$(P $(I Constraint)s are used to impose additional constraints
on matching arguments to a template beyond what is possible
--
1.7.3.1.msysgit.0