Skip to content

Commit bfd3211

Browse files
committed
Add shape offsets page
1 parent 2db500e commit bfd3211

File tree

7 files changed

+95
-7
lines changed

7 files changed

+95
-7
lines changed

Diff for: Writerside/cfg/static/custom.css

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
:root {
2+
--wh-color-accent-substrate-bg: #222330 !important;
3+
}
4+
15
.article > .prompt {
26
max-width: auto !important;
37
}
@@ -29,4 +33,4 @@ p + .code-collapse__wrapper,
2933

3034
#mermaid .flowchart-link {
3135
stroke: #59595c6b !important;
32-
}
36+
}

Diff for: Writerside/tl.tree

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020
toc-title="Shapes"/>
2121
<toc-element topic="callable-types.md"
2222
toc-title="Callables"/>
23-
<!-- TODO -->
24-
<toc-element topic="conditional-types.md" toc-title="Conditions" hidden="true"/>
23+
<toc-element topic="offset-access.md"
24+
toc-title="Offsets"/>
25+
<!-- TODO -->
26+
<toc-element topic="conditional-types.md"
27+
toc-title="Conditions"
28+
hidden="true" />
2529
<toc-element topic="comparison.md"
2630
toc-title="Comparison of syntax between different tools" />
2731

Diff for: Writerside/topics/language/basic-types.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Basic Types
2+
23
<show-structure for="chapter" depth="2"/>
34

45
The parser does not impose restrictions on type naming. The type name must begin

Diff for: Writerside/topics/language/callable-types.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Callable Types
2+
23
<show-structure for="chapter" depth="2"/>
34

45
Callable types describe an arbitrary type that describes a function.

Diff for: Writerside/topics/language/generic-types.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Generic Types
2+
23
<show-structure for="chapter" depth="2"/>
34

45
Each type can take arguments containing other type declarations. Validation of

Diff for: Writerside/topics/language/offset-access.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Type Offsets
2+
3+
<show-structure for="chapter" depth="2"/>
4+
<secondary-label ref="tl1.4"/>
5+
6+
To specify a reference to a specific <a href="shape-types.md">shape or array element</a>,
7+
the offset access syntax is used.
8+
9+
A description of this type consists of two parts: Arbitrary type description;
10+
The type of specific element, enclosed in square `[]` brackets.
11+
12+
<tabs>
13+
<tab title="Examples">
14+
15+
> Type with string key "offset".
16+
> ```typescript
17+
> T['offset']
18+
> ```
19+
20+
> Type with dependent key.
21+
> ```typescript
22+
> T[U]
23+
> ```
24+
25+
> <a href="shape-types.md">Shape type</a> with numeric key.
26+
> ```typescript
27+
> array{int, string}[0]
28+
> ```
29+
30+
> Complex example using <a href="shape-types.md">shape types</a>
31+
> and <a href="generic-types.md">generics</a>.
32+
> ```typescript
33+
> T<U>[object{key: int, ...}]
34+
> ```
35+
36+
</tab>
37+
<tab title="Counterexamples">
38+
39+
> The offset is enclosed in single brackets.
40+
> ```typescript
41+
> Collection[[Some]]
42+
> ```
43+
> ```
44+
> Syntax error, unexpected "["
45+
> ```
46+
> {collapsible="true" collapsed-title="TypeLang\Parser\Exception\ParseException"}
47+
> {style="warning"}
48+
49+
> There must be a type description first, followed
50+
> by a reference to an element of that type.
51+
> ```typescript
52+
> Collection['key']{key: string}
53+
> ```
54+
> ```
55+
> Syntax error, unexpected "{"
56+
> ```
57+
> {collapsible="true" collapsed-title="TypeLang\Parser\Exception\ParseException"}
58+
> {style="warning"}
59+
60+
</tab>
61+
</tabs>
62+
63+
<note>
64+
Note that since this is a type description language, any key type is allowed,
65+
including objects, <a href="conditional-types.md">conditions</a> or
66+
<a href="shape-types.md">shapes</a>.
67+
</note>

Diff for: Writerside/topics/language/shape-types.md

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# Shape Types
2+
23
<show-structure for="chapter" depth="2"/>
34

45
Each **composite** type can be rigidly described by a structural type called a
56
"shape". A shape within the PHP language can be applied to any array or object
67
and contain either implicit or explicit keys.
78

8-
> Support for other types of **keys**, such as const mask (`Class::CONST_*)`
9-
> is not currently available.
10-
{style="warning"}
11-
129
<tabs>
1310
<tab title="named explicit keys">
1411

@@ -62,6 +59,19 @@ array{
6259
> {collapsible="true" collapsed-title="TypeLang\Parser\Exception\ParseException"}
6360
{style="warning"}
6461
62+
> Support for other types of **keys**, such as const mask (`Class::CONST_*`)
63+
> is not currently available.
64+
> ```php
65+
> array{
66+
> Class::CONST_*: string,
67+
> ...
68+
> }
69+
> ```
70+
> ```
71+
> Syntax error, unexpected ":"
72+
> ```
73+
> {collapsible="true" collapsed-title="TypeLang\Parser\Exception\ParseException"}
74+
{style="warning"}
6575
6676
### Unsealed Shapes
6777

0 commit comments

Comments
 (0)