Skip to content

Commit 1e51614

Browse files
committed
fix attributes
1 parent 8afc51c commit 1e51614

11 files changed

Lines changed: 914 additions & 453 deletions

build/parser.js

Lines changed: 465 additions & 407 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/parser.jison

Lines changed: 100 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ ClassDeclaration // {{{
964964
$$ = location({
965965
kind: Kind.ClassDeclaration,
966966
modifiers: $1,
967-
name: $2,
967+
name: $3,
968968
extends: $6,
969969
members: $8
970970
}, @1, @9);
@@ -1002,7 +1002,7 @@ ClassDeclaration // {{{
10021002
$$ = location({
10031003
kind: Kind.ClassDeclaration,
10041004
modifiers: [],
1005-
name: $1,
1005+
name: $2,
10061006
extends: $5,
10071007
members: $7
10081008
}, @1, @8);
@@ -1169,7 +1169,17 @@ ClassMemberModifier // {{{
11691169
// }}}
11701170

11711171
ClassMemberSX // {{{
1172-
: ClassField
1172+
: AttributeList ClassField
1173+
{
1174+
$$ = location($2, @1, @2);
1175+
$$.attributes = $1;
1176+
}
1177+
| AttributeList Method
1178+
{
1179+
$$ = location($2, @1, @2);
1180+
$$.attributes = $1;
1181+
}
1182+
| ClassField
11731183
| Method
11741184
;
11751185
// }}}
@@ -1185,7 +1195,7 @@ ClassModifier // {{{
11851195
{
11861196
$$ = [
11871197
location({
1188-
kind: ClassModifier.Sealed
1198+
kind: ClassModifier.Sealed
11891199
}, @1),
11901200
location({
11911201
kind: ClassModifier.Abstract
@@ -1705,74 +1715,120 @@ ExternDeclarator // {{{
17051715
// }}}
17061716

17071717
ExternClass // {{{
1708-
: 'SEALED' 'CLASS' Identifier TypeGeneric '{' ExternClassMember '}'
1718+
: 'SEALED' 'ABSTRACT' 'CLASS' ExternClassBody
17091719
{
1710-
$$ = location({
1711-
kind: Kind.ClassDeclaration,
1712-
name: $3,
1713-
members: $6,
1714-
sealed: true
1715-
}, @1, @7);
1720+
$4.modifiers = [
1721+
location({
1722+
kind: ClassModifier.Sealed
1723+
}, @1),
1724+
location({
1725+
kind: ClassModifier.Abstract
1726+
}, @2)
1727+
];
1728+
1729+
$$ = location($4, @1, @4);
1730+
}
1731+
| 'ABSTRACT' 'CLASS' ExternClassBody
1732+
{
1733+
$3.modifiers = [
1734+
location({
1735+
kind: ClassModifier.Abstract
1736+
}, @1)
1737+
];
1738+
1739+
$$ = location($3, @1, @3);
1740+
}
1741+
| 'SEALED' 'CLASS' ExternClassBody
1742+
{
1743+
$3.modifiers = [
1744+
location({
1745+
kind: ClassModifier.Sealed
1746+
}, @1)
1747+
];
1748+
1749+
$$ = location($3, @1, @3);
17161750
}
1717-
| 'SEALED' 'CLASS' Identifier '{' ExternClassMember '}'
1751+
| 'CLASS' ExternClassBody
1752+
{
1753+
$2.modifiers = [];
1754+
1755+
$$ = location($2, @1, @2);
1756+
}
1757+
;
1758+
// }}}
1759+
1760+
ExternClassBody // {{{
1761+
: Identifier TypeGeneric 'EXTENDS' Identifier '{' ExternClassMember '}'
17181762
{
17191763
$$ = location({
17201764
kind: Kind.ClassDeclaration,
1721-
name: $3,
1722-
members: $5,
1723-
sealed: true
1724-
}, @1, @6);
1765+
name: $1,
1766+
extends: $4,
1767+
members: $6
1768+
}, @1, @7);
17251769
}
1726-
| 'CLASS' Identifier TypeGeneric '{' ExternClassMember '}'
1770+
| Identifier 'EXTENDS' Identifier '{' ExternClassMember '}'
17271771
{
17281772
$$ = location({
17291773
kind: Kind.ClassDeclaration,
1730-
name: $2,
1774+
modifiers: [],
1775+
name: $1,
1776+
extends: $3,
17311777
members: $5
17321778
}, @1, @6);
17331779
}
1734-
| 'CLASS' Identifier '{' ExternClassMember '}'
1780+
| Identifier TypeGeneric '{' ExternClassMember '}'
17351781
{
17361782
$$ = location({
17371783
kind: Kind.ClassDeclaration,
1738-
name: $2,
1784+
modifiers: [],
1785+
name: $1,
17391786
members: $4
17401787
}, @1, @5);
17411788
}
1742-
| 'SEALED' 'CLASS' Identifier TypeGeneric
1789+
| Identifier '{' ExternClassMember '}'
17431790
{
17441791
$$ = location({
17451792
kind: Kind.ClassDeclaration,
1746-
name: $3,
1747-
members: [],
1748-
sealed: true
1793+
modifiers: [],
1794+
name: $1,
1795+
members: $3
17491796
}, @1, @4);
17501797
}
1751-
| 'SEALED' 'CLASS' Identifier
1798+
| Identifier TypeGeneric 'EXTENDS' Identifier
17521799
{
17531800
$$ = location({
17541801
kind: Kind.ClassDeclaration,
1755-
name: $3,
1756-
members: [],
1757-
sealed: true
1758-
}, @1, @3);
1802+
name: $1,
1803+
extends: $4,
1804+
members: []
1805+
}, @1, @7);
17591806
}
1760-
| 'CLASS' Identifier TypeGeneric
1807+
| Identifier 'EXTENDS' Identifier
17611808
{
17621809
$$ = location({
17631810
kind: Kind.ClassDeclaration,
1764-
name: $2,
1811+
name: $1,
1812+
extends: $3,
17651813
members: []
17661814
}, @1, @3);
17671815
}
1768-
| 'CLASS' Identifier
1816+
| Identifier TypeGeneric
17691817
{
17701818
$$ = location({
17711819
kind: Kind.ClassDeclaration,
1772-
name: $2,
1820+
name: $1,
17731821
members: []
17741822
}, @1, @2);
17751823
}
1824+
| Identifier
1825+
{
1826+
$$ = location({
1827+
kind: Kind.ClassDeclaration,
1828+
name: $1,
1829+
members: []
1830+
}, @1);
1831+
}
17761832
;
17771833
// }}}
17781834

@@ -3630,7 +3686,17 @@ ObjectListPN // {{{
36303686
// }}}
36313687

36323688
ObjectListPNI // {{{
3633-
: ObjectItem ',' NL_0M
3689+
: AttributeList ObjectItem ',' NL_0M
3690+
{
3691+
$$ = location($2, @1, @2);
3692+
$$.attributes = $1;
3693+
}
3694+
| AttributeList ObjectItem NL_1M
3695+
{
3696+
$$ = location($2, @1, @2);
3697+
$$.attributes = $1;
3698+
}
3699+
| ObjectItem ',' NL_0M
36343700
| ObjectItem NL_1M
36353701
;
36363702
// }}}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"kind": 59,
3+
"attributes": [],
4+
"body": [
5+
{
6+
"kind": 15,
7+
"modifiers": [],
8+
"name": {
9+
"kind": 41,
10+
"name": "Foo",
11+
"start": {
12+
"line": 1,
13+
"column": 7
14+
},
15+
"end": {
16+
"line": 1,
17+
"column": 10
18+
}
19+
},
20+
"members": [
21+
{
22+
"name": {
23+
"kind": 41,
24+
"name": "bar",
25+
"start": {
26+
"line": 3,
27+
"column": 2
28+
},
29+
"end": {
30+
"line": 3,
31+
"column": 5
32+
}
33+
},
34+
"parameters": [],
35+
"throws": [],
36+
"start": {
37+
"line": 2,
38+
"column": 2
39+
},
40+
"end": {
41+
"line": 4,
42+
"column": 3
43+
},
44+
"kind": 56,
45+
"modifiers": [],
46+
"body": {
47+
"kind": 11,
48+
"attributes": [],
49+
"statements": [],
50+
"start": {
51+
"line": 3,
52+
"column": 8
53+
},
54+
"end": {
55+
"line": 4,
56+
"column": 3
57+
}
58+
},
59+
"attributes": [
60+
{
61+
"kind": 5,
62+
"declaration": {
63+
"kind": 41,
64+
"name": "foo",
65+
"start": {
66+
"line": 2,
67+
"column": 4
68+
},
69+
"end": {
70+
"line": 2,
71+
"column": 7
72+
}
73+
},
74+
"start": {
75+
"line": 2,
76+
"column": 4
77+
},
78+
"end": {
79+
"line": 2,
80+
"column": 7
81+
}
82+
}
83+
]
84+
}
85+
],
86+
"start": {
87+
"line": 1,
88+
"column": 1
89+
},
90+
"end": {
91+
"line": 5,
92+
"column": 2
93+
},
94+
"attributes": []
95+
}
96+
],
97+
"start": {
98+
"line": 1,
99+
"column": 1
100+
},
101+
"end": {
102+
"line": 5,
103+
"column": 2
104+
}
105+
}

test/fixtures/attribute.method.ks

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Foo {
2+
#[foo]
3+
bar() {
4+
}
5+
}

0 commit comments

Comments
 (0)