Skip to content

Commit 547ad46

Browse files
authored
Move the base of {Index,Slice}Expression into PostfixExpression (#3680)
* Move the base of {Index,Slice}Expression into PostfixExpression Them being independent expressions in the grammar made PostfixExpression non-trivially left recursive. A more direct representation of the parser would be to combine indexing and slicing, but I assume the separation was deliberate for reader clarity. * preserve legacy link names
1 parent 90b6ea2 commit 547ad46

File tree

4 files changed

+44
-44
lines changed

4 files changed

+44
-44
lines changed

spec/arrays.dd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ assert(b[1] == 2);
204204
---------
205205
)
206206

207-
$(P See also $(GLINK2 expression, IndexExpression).)
207+
$(P See also $(GLINK2 expression, IndexOperation).)
208208

209209
$(H3 $(LNAME2 pointer-arithmetic, Pointer Arithmetic))
210210

@@ -284,7 +284,7 @@ writeln(b[7]); // 10
284284
---------
285285
)
286286

287-
$(P See also $(GLINK2 expression, SliceExpression).)
287+
$(P See also $(GLINK2 expression, SliceOperation).)
288288

289289

290290
$(H2 $(LNAME2 array-length, Array Length))
@@ -502,7 +502,7 @@ a[] = b[] + 4;
502502
as the left-hand side of an assignment or an op-assignment expression.
503503
The right-hand side can be certain combinations of:)
504504

505-
* An array $(GLINK2 expression, SliceExpression) of the same length
505+
* An array $(GLINK2 expression, SliceOperation) of the same length
506506
and type as the left-hand side
507507
* A scalar expression of the same element type as the left-hand side
508508

spec/expression.dd

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ assert(a[2] == 4);
905905
---
906906
)
907907

908-
$(P $(GLINK IndexExpression) can also be used with a pointer and has
908+
$(P $(GLINK IndexOperation) can also be used with a pointer and has
909909
the same behaviour as adding an integer, then dereferencing the result.)
910910

911911
$(P If the second operand is a pointer, and the first is an integral type,
@@ -1531,8 +1531,8 @@ $(GNAME PostfixExpression):
15311531
$(GSELF PostfixExpression) $(D --)
15321532
$(GSELF PostfixExpression) $(D $(LPAREN)) $(GLINK NamedArgumentList)$(OPT) $(D $(RPAREN))
15331533
$(GLINK2 type, TypeCtors)$(OPT) $(GLINK2 type, BasicType) $(D $(LPAREN)) $(GLINK NamedArgumentList)$(OPT) $(D $(RPAREN))
1534-
$(GLINK IndexExpression)
1535-
$(GLINK SliceExpression)
1534+
$(GSELF PostfixExpression) $(GLINK IndexOperation)
1535+
$(GSELF PostfixExpression) $(GLINK SliceOperation)
15361536
)
15371537

15381538
$(TABLE
@@ -1546,8 +1546,8 @@ $(TABLE
15461546
)
15471547
$(TROW `++`, Increment after use - see $(RELATIVE_LINK2 order-of-evaluation, order of evaluation))
15481548
$(TROW `--`, Decrement after use)
1549-
$(TROW *IndexExpression*, Select a single element)
1550-
$(TROW *SliceExpression*, Select a series of elements)
1549+
$(TROW *IndexOperation*, Select a single element)
1550+
$(TROW *SliceOperation*, Select a series of elements)
15511551
)
15521552

15531553
$(H3 $(LNAME2 argument-list, Postfix Argument Lists))
@@ -1592,47 +1592,47 @@ S s = S(1, 2);
15921592
Uniform construction syntax for built-in scalar types))
15931593

15941594

1595-
$(H2 $(LNAME2 index_expressions, Index Expressions))
1595+
$(H3 $(LEGACY_LNAME2 index_operations, index_expressions, Index Operations))
15961596

15971597
$(GRAMMAR
1598-
$(GNAME IndexExpression):
1599-
$(GLINK PostfixExpression) $(D [) $(GLINK ArgumentList) $(D ])
1598+
$(GNAME IndexOperation):
1599+
$(D [) $(GLINK ArgumentList) $(D ])
16001600
)
16011601

1602-
$(P $(I PostfixExpression) is evaluated.
1603-
If $(I PostfixExpression) is an expression of static or
1602+
$(P The base $(I PostfixExpression) is evaluated.
1603+
The special variable `$` is declared and set to be the number
1604+
of elements in the base $(I PostfixExpression) (when available).
1605+
A new declaration scope is created for the evaluation of the
1606+
$(I ArgumentList) and `$` appears in that scope only.
1607+
)
1608+
1609+
$(P If the $(I PostfixExpression) is an expression of static or
16041610
dynamic array type, the result of the indexing is an lvalue
16051611
of the *i*th element in the array, where `i` is an integer
16061612
evaluated from $(I ArgumentList).
16071613
If $(I PostfixExpression) is a pointer `p`, the result is
16081614
`*(p + i)` (see $(RELATIVE_LINK2 pointer_arithmetic, Pointer Arithmetic)).
16091615
)
16101616

1611-
$(P If $(I PostfixExpression) is a $(DDSUBLINK spec/template, variadic-templates, $(I ValueSeq))
1617+
$(P If the base $(I PostfixExpression) is a $(DDSUBLINK spec/template, variadic-templates, $(I ValueSeq))
16121618
then the $(I ArgumentList) must consist of only one argument,
16131619
and that must be statically evaluatable to an integral constant.
16141620
That integral constant $(I n) then selects the $(I n)th
16151621
expression in the $(I ValueSeq), which is the result
1616-
of the $(I IndexExpression).
1622+
of the $(I IndexOperation).
16171623
It is an error if $(I n) is out of bounds of the $(I ValueSeq).
16181624
)
16191625

1620-
$(P The special variable `$` is declared and set to be the number
1621-
of elements in the $(I PostfixExpression) (when available).
1622-
A new declaration scope is created for the evaluation of the
1623-
$(I ArgumentList) and `$` appears in that scope only.
1624-
)
1625-
16261626
$(P The index operator can be $(DDSUBLINK spec/operatoroverloading, array, overloaded).
16271627
Using multiple indices in *ArgumentList* is only supported for operator
16281628
overloading.)
16291629

1630-
$(H2 $(LNAME2 slice_expressions, Slice Expressions))
1630+
$(H3 $(LEGACY_LNAME2 slice_operations, slice_expressions, Slice Operations))
16311631

16321632
$(GRAMMAR
1633-
$(GNAME SliceExpression):
1634-
$(GLINK PostfixExpression) $(D [ ])
1635-
$(GLINK PostfixExpression) $(D [) $(GLINK Slice) $(D ,)$(OPT) $(D ])
1633+
$(GNAME SliceOperation):
1634+
$(D [ ])
1635+
$(D [) $(GLINK Slice) $(D ,)$(OPT) $(D ])
16361636

16371637
$(GNAME Slice):
16381638
$(GLINK AssignExpression)
@@ -1641,21 +1641,28 @@ $(GNAME Slice):
16411641
$(GLINK AssignExpression) $(D ..) $(GLINK AssignExpression) $(D ,) $(GSELF Slice)
16421642
)
16431643

1644-
$(P $(I PostfixExpression) is evaluated.
1645-
If $(I PostfixExpression) is a static or dynamic
1644+
$(P The base $(I PostfixExpression) is evaluated.
1645+
The special variable `$` is declared and set to be the number
1646+
of elements in the $(I PostfixExpression) (when available).
1647+
A new declaration scope is created for the evaluation of the
1648+
$(I AssignExpression)`..`$(I AssignExpression) and `$` appears in
1649+
that scope only.
1650+
)
1651+
1652+
$(P If the base $(I PostfixExpression) is a static or dynamic
16461653
array `a`, the result of the slice is a dynamic array
16471654
referencing elements `a[i]` to `a[j-1]` inclusive, where `i`
16481655
and `j` are integers evaluated from the first and second $(I
16491656
AssignExpression) respectively.
16501657
)
16511658

1652-
$(P If $(I PostfixExpression) is a pointer `p`, the result
1659+
$(P If the base $(I PostfixExpression) is a pointer `p`, the result
16531660
will be a dynamic array referencing elements from `p[i]` to `p[j-1]`
16541661
inclusive, where `i` and `j` are integers evaluated from the
16551662
first and second $(I AssignExpression) respectively.
16561663
)
16571664

1658-
$(P If $(I PostfixExpression) is a $(DDSUBLINK spec/template, variadic-templates, $(I ValueSeq)), then
1665+
$(P If the base $(I PostfixExpression) is a $(DDSUBLINK spec/template, variadic-templates, $(I ValueSeq)), then
16591666
the result of the slice is a new $(I ValueSeq) formed
16601667
from the upper and lower bounds, which must statically evaluate
16611668
to integral constants.
@@ -1669,24 +1676,17 @@ $(GNAME Slice):
16691676
The result of the expression is a slice of the elements in $(I PostfixExpression).
16701677
)
16711678

1672-
$(P The special variable `$` is declared and set to be the number
1673-
of elements in the $(I PostfixExpression) (when available).
1674-
A new declaration scope is created for the evaluation of the
1675-
$(I AssignExpression)`..`$(I AssignExpression) and `$` appears in
1676-
that scope only.
1677-
)
1678-
1679-
$(P If the $(D [ ]) form is used, the slice is of all the elements in $(I PostfixExpression).
1680-
The expression cannot be a pointer.
1679+
$(P If the $(D [ ]) form is used, the slice is of all the elements in the base $(I PostfixExpression).
1680+
The base expression cannot be a pointer.
16811681
)
16821682

16831683
$(P The slice operator can be $(DDSUBLINK spec/operatoroverloading, slice, overloaded).
16841684
Using more than one *Slice* is only supported for operator
16851685
overloading.)
16861686

1687-
$(P A $(I SliceExpression) is not a modifiable lvalue.)
1687+
$(P A $(I SliceOperation) is not a modifiable lvalue.)
16881688

1689-
$(H3 $(LNAME2 slice_to_static_array, Slice Conversion to Static Array))
1689+
$(H4 $(LNAME2 slice_to_static_array, Slice Conversion to Static Array))
16901690

16911691
$(P If the slice bounds can be known at compile time, the slice expression
16921692
may be implicitly convertible to a static array lvalue. For example:)
@@ -1785,7 +1785,7 @@ $(GNAME PrimaryExpression):
17851785
$(RELATIVE_LINK2 null, $(D null))
17861786
$(LEGACY_LNAME2 true_false)$(DDSUBLINK spec/type, bool, `true`)
17871787
$(DDSUBLINK spec/type, bool, `false`)
1788-
$(RELATIVE_LINK2 IndexExpression, `$`)
1788+
$(RELATIVE_LINK2 IndexOperation, `$`)
17891789
$(GLINK_LEX IntegerLiteral)
17901790
$(GLINK_LEX FloatLiteral)
17911791
$(LEGACY_LNAME2 CharacterLiteral)$(LEGACY_LNAME2 character-literal)$(GLINK_LEX CharacterLiteral)

spec/function.dd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3679,7 +3679,7 @@ $(H2 $(LNAME2 nogc-functions, No-GC Functions))
36793679
$(LI $(DDSUBLINK spec/expression, CatExpression, array concatenation))
36803680
$(LI $(DDSUBLINK spec/expression, simple_assignment_expressions, array appending))
36813681
$(LI $(DDSUBLINK spec/expression, AssocArrayLiteral, constructing an associative array))
3682-
$(LI $(DDSUBLINK spec/expression, IndexExpression, indexing) an associative array
3682+
$(LI $(DDSUBLINK spec/expression, IndexOperation, indexing) an associative array
36833683
$(NOTE because it may throw $(D RangeError) if the specified key is not present))
36843684
$(LI $(DDSUBLINK spec/expression, NewExpression, allocating an object with `new`) on the heap
36853685
$(NOTE `new` declarations of $(D class types) in function scopes are compatible with

spec/template.dd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,10 +950,10 @@ $(H4 $(LNAME2 seq-ops, Sequence Operations))
950950
$(LI The number of elements in an $(I AliasSeq) can be retrieved with
951951
the $(D .length) property.)
952952
$(LI The $(I n)th element can be retrieved by
953-
$(DDSUBLINK spec/expression, index_expressions, indexing) an
953+
$(DDSUBLINK spec/expression, index_operations, indexing) an
954954
$(I AliasSeq) with `Seq[n]`. Indexes must be known at compile-time.
955955
The result is an lvalue when the element is a variable.)
956-
$(LI $(DDSUBLINK spec/expression, slice_expressions, Slicing)
956+
$(LI $(DDSUBLINK spec/expression, slice_operations, Slicing)
957957
produces a new sequence with a subset of the elements of the original sequence.)
958958
)
959959

0 commit comments

Comments
 (0)