GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — WIP · AssemblyScript/assemblyscript@696e6b7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • parser.ts
  • tests
    • compiler
      • asi.debug.wat
      • asi.release.wat
      • asi.ts
      • resolve-elementaccess.debug.wat
      • resolve-elementaccess.release.wat
      • resolve-elementaccess.ts
    • parser
      • asi.ts.fixture.ts
      • asi.ts
      • interface-errors.ts.fixture.ts
      • literals.ts.fixture.ts
      • literals.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/parser.ts‎

Copy file name to clipboardExpand all lines: src/parser.ts
+64-32Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ export class Parser extends DiagnosticEmitter {
649649
let parameters: TypeNode[] | null = null;
650650

651651
// Name<T>
652-
if (tn.skip(Token.LessThan)) {
652+
if (!tn.peekOnNewLine() && tn.skip(Token.LessThan)) {
653653
do {
654654
let parameter = this.parseType(tn, true, suppressErrors);
655655
if (!parameter) return null;
@@ -703,7 +703,7 @@ export class Parser extends DiagnosticEmitter {
703703
}
704704
}
705705
// ... [][]
706-
while (tn.skip(Token.OpenBracket)) {
706+
while (!tn.peekOnNewLine() && tn.skip(Token.OpenBracket)) {
707707
let bracketStart = tn.tokenPos;
708708
if (!tn.skip(Token.CloseBracket)) {
709709
if (!suppressErrors) {
@@ -991,7 +991,8 @@ export class Parser extends DiagnosticEmitter {
991991
} while (tn.skip(Token.Comma));
992992

993993
let ret = Node.createVariableStatement(decorators, declarations, tn.range(startPos, tn.pos));
994-
if (!tn.skip(Token.Semicolon) && !isFor) this.checkASI(tn);
994+
if (isFor) tn.skip(Token.Semicolon);
995+
else this.parseSemicolon(tn);
995996
return ret;
996997
}
997998

@@ -1019,7 +1020,8 @@ export class Parser extends DiagnosticEmitter {
10191020
);
10201021
}
10211022
let flags = parentFlags;
1022-
if (tn.skip(Token.Exclamation)) {
1023+
if (tn.peek() == Token.Exclamation && !tn.peekOnNewLine()) {
1024+
tn.next();
10231025
flags |= CommonFlags.DefinitelyAssigned;
10241026
}
10251027

@@ -1175,7 +1177,7 @@ export class Parser extends DiagnosticEmitter {
11751177
}
11761178

11771179
let ret = Node.createReturnStatement(expr, tn.range(startPos, tn.pos));
1178-
if (!tn.skip(Token.Semicolon)) this.checkASI(tn);
1180+
this.parseSemicolon(tn);
11791181
return ret;
11801182
}
11811183

@@ -1601,7 +1603,8 @@ export class Parser extends DiagnosticEmitter {
16011603
tn.range(startPos, tn.pos)
16021604
);
16031605
ret.overriddenModuleName = this.currentModuleName;
1604-
tn.skip(Token.Semicolon);
1606+
if (body) tn.skip(Token.Semicolon);
1607+
else this.parseSemicolon(tn);
16051608
return ret;
16061609
}
16071610

@@ -1669,6 +1672,13 @@ export class Parser extends DiagnosticEmitter {
16691672
}
16701673

16711674
if (arrowKind) {
1675+
if (tn.peek() == Token.Equals_GreaterThan && tn.peekOnNewLine()) {
1676+
this.error(
1677+
DiagnosticCode.Unexpected_token,
1678+
tn.range(tn.nextTokenPos)
1679+
);
1680+
return null;
1681+
}
16721682
if (!tn.skip(Token.Equals_GreaterThan)) {
16731683
this.error(
16741684
DiagnosticCode._0_expected,
@@ -2203,7 +2213,7 @@ export class Parser extends DiagnosticEmitter {
22032213
}
22042214
return null;
22052215
}
2206-
tn.skip(Token.Semicolon);
2216+
this.parseSemicolon(tn);
22072217
return retIndex;
22082218
}
22092219
if (!tn.skipIdentifier(IdentifierHandling.Always)) {
@@ -2367,8 +2377,10 @@ export class Parser extends DiagnosticEmitter {
23672377
body,
23682378
tn.range(startPos, tn.pos)
23692379
);
2370-
if (!(isInterface && tn.skip(Token.Comma))) {
2371-
tn.skip(Token.Semicolon);
2380+
let hasComma = isInterface && tn.skip(Token.Comma);
2381+
if (!hasComma) {
2382+
if (body) tn.skip(Token.Semicolon);
2383+
else this.parseSemicolon(tn);
23722384
}
23732385
return retMethod;
23742386

@@ -2421,7 +2433,8 @@ export class Parser extends DiagnosticEmitter {
24212433
tn.range(startPos, tn.pos)
24222434
);
24232435
}
2424-
if (tn.skip(Token.Exclamation)) {
2436+
if (tn.peek() == Token.Exclamation && !tn.peekOnNewLine()) {
2437+
tn.next();
24252438
flags |= CommonFlags.DefinitelyAssigned;
24262439
}
24272440
if (tn.skip(Token.Colon)) {
@@ -2465,9 +2478,7 @@ export class Parser extends DiagnosticEmitter {
24652478
initializer,
24662479
range
24672480
);
2468-
if (!(isInterface && tn.skip(Token.Comma))) {
2469-
tn.skip(Token.Semicolon);
2470-
}
2481+
if (!(isInterface && tn.skip(Token.Comma))) this.parseSemicolon(tn);
24712482
return retField;
24722483
}
24732484
return null;
@@ -2656,7 +2667,7 @@ export class Parser extends DiagnosticEmitter {
26562667
this.seenlog.add(internalPath);
26572668
}
26582669
}
2659-
tn.skip(Token.Semicolon);
2670+
this.parseSemicolon(tn);
26602671
return ret;
26612672
} else if (tn.skip(Token.Asterisk)) {
26622673
if (tn.skip(Token.From)) {
@@ -2672,7 +2683,7 @@ export class Parser extends DiagnosticEmitter {
26722683
this.dependees.set(internalPath, new Dependee(currentSource, path));
26732684
this.backlog.push(internalPath);
26742685
}
2675-
tn.skip(Token.Semicolon);
2686+
this.parseSemicolon(tn);
26762687
return ret;
26772688
} else {
26782689
this.error(
@@ -2754,7 +2765,7 @@ export class Parser extends DiagnosticEmitter {
27542765
range
27552766
)
27562767
], null, false, tn.range(startPos, tn.pos));
2757-
tn.skip(Token.Semicolon);
2768+
this.parseSemicolon(tn);
27582769
return ret;
27592770
}
27602771

@@ -2844,7 +2855,7 @@ export class Parser extends DiagnosticEmitter {
28442855
this.dependees.set(internalPath, new Dependee(assert(this.currentSource), path));
28452856
this.backlog.push(internalPath);
28462857
}
2847-
tn.skip(Token.Semicolon);
2858+
this.parseSemicolon(tn);
28482859
return ret;
28492860
} else {
28502861
this.error(
@@ -2915,7 +2926,7 @@ export class Parser extends DiagnosticEmitter {
29152926
if (tn.skipIdentifier()) {
29162927
let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
29172928
let ret = Node.createExportImportStatement(identifier, asIdentifier, tn.range(startPos, tn.pos));
2918-
tn.skip(Token.Semicolon);
2929+
this.parseSemicolon(tn);
29192930
return ret;
29202931
} else {
29212932
this.error(
@@ -3078,7 +3089,7 @@ export class Parser extends DiagnosticEmitter {
30783089
identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
30793090
}
30803091
let ret = Node.createBreakStatement(identifier, tn.range());
3081-
tn.skip(Token.Semicolon);
3092+
this.parseSemicolon(tn);
30823093
return ret;
30833094
}
30843095

@@ -3094,7 +3105,7 @@ export class Parser extends DiagnosticEmitter {
30943105
identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
30953106
}
30963107
let ret = Node.createContinueStatement(identifier, tn.range());
3097-
tn.skip(Token.Semicolon);
3108+
this.parseSemicolon(tn);
30983109
return ret;
30993110
}
31003111

@@ -3140,7 +3151,8 @@ export class Parser extends DiagnosticEmitter {
31403151
}
31413152

31423153
parseExpressionStatement(
3143-
tn: Tokenizer
3154+
tn: Tokenizer,
3155+
isFor: bool = false
31443156
): ExpressionStatement | null {
31453157

31463158
// at previous token
@@ -3149,7 +3161,8 @@ export class Parser extends DiagnosticEmitter {
31493161
if (!expr) return null;
31503162

31513163
let ret = Node.createExpressionStatement(expr);
3152-
tn.skip(Token.Semicolon);
3164+
if (isFor) tn.skip(Token.Semicolon);
3165+
else this.parseSemicolon(tn);
31533166
return ret;
31543167
}
31553168

@@ -3172,7 +3185,7 @@ export class Parser extends DiagnosticEmitter {
31723185
initializer = this.parseVariable(tn, CommonFlags.None, null, tn.tokenPos, true);
31733186

31743187
} else if (!tn.skip(Token.Semicolon)) {
3175-
initializer = this.parseExpressionStatement(tn);
3188+
initializer = this.parseExpressionStatement(tn, true);
31763189
if (!initializer) return null;
31773190
}
31783191

@@ -3234,7 +3247,7 @@ export class Parser extends DiagnosticEmitter {
32343247
if (tn.token == Token.Semicolon) {
32353248
let condition: ExpressionStatement | null = null;
32363249
if (!tn.skip(Token.Semicolon)) {
3237-
condition = this.parseExpressionStatement(tn);
3250+
condition = this.parseExpressionStatement(tn, true);
32383251
if (!condition) return null;
32393252
}
32403253

@@ -3375,7 +3388,6 @@ export class Parser extends DiagnosticEmitter {
33753388
switchCases.push(switchCase);
33763389
}
33773390
let ret = Node.createSwitchStatement(condition, switchCases, tn.range(startPos, tn.pos));
3378-
tn.skip(Token.Semicolon);
33793391
return ret;
33803392
} else {
33813393
this.error(
@@ -3467,10 +3479,17 @@ export class Parser extends DiagnosticEmitter {
34673479
// at 'throw': Expression ';'?
34683480

34693481
let startPos = tn.tokenPos;
3482+
if (tn.peekOnNewLine()) {
3483+
this.error(
3484+
DiagnosticCode.Unexpected_token,
3485+
tn.range(tn.nextTokenPos)
3486+
);
3487+
return null;
3488+
}
34703489
let expression = this.parseExpression(tn);
34713490
if (!expression) return null;
34723491
let ret = Node.createThrowStatement(expression, tn.range(startPos, tn.pos));
3473-
if (!tn.skip(Token.Semicolon)) this.checkASI(tn);
3492+
this.parseSemicolon(tn);
34743493
return ret;
34753494
}
34763495

@@ -3561,7 +3580,6 @@ export class Parser extends DiagnosticEmitter {
35613580
finallyStatements,
35623581
tn.range(startPos, tn.pos)
35633582
);
3564-
tn.skip(Token.Semicolon);
35653583
return ret;
35663584
} else {
35673585
this.error(
@@ -3608,7 +3626,7 @@ export class Parser extends DiagnosticEmitter {
36083626
type,
36093627
tn.range(startPos, tn.pos)
36103628
);
3611-
tn.skip(Token.Semicolon);
3629+
this.parseSemicolon(tn);
36123630
ret.overriddenModuleName = this.currentModuleName;
36133631
return ret;
36143632
} else {
@@ -3638,7 +3656,7 @@ export class Parser extends DiagnosticEmitter {
36383656
let moduleName = tn.readString();
36393657
let ret = Node.createModuleDeclaration(moduleName, flags, tn.range(startPos, tn.pos));
36403658
this.currentModuleName = moduleName;
3641-
tn.skip(Token.Semicolon);
3659+
this.parseSemicolon(tn);
36423660
return ret;
36433661
}
36443662

@@ -3649,10 +3667,10 @@ export class Parser extends DiagnosticEmitter {
36493667
// at 'void': Expression ';'?
36503668

36513669
let startPos = tn.tokenPos;
3652-
let expression = this.parseExpression(tn, Precedence.Grouping);
3670+
let expression = this.parseExpression(tn, Precedence.UnaryPrefix);
36533671
if (!expression) return null;
36543672
let ret = Node.createVoidStatement(expression, tn.range(startPos, tn.pos));
3655-
tn.skip(Token.Semicolon);
3673+
this.parseSemicolon(tn);
36563674
return ret;
36573675
}
36583676

@@ -3670,7 +3688,6 @@ export class Parser extends DiagnosticEmitter {
36703688
let statement = this.parseStatement(tn);
36713689
if (!statement) return null;
36723690
let ret = Node.createWhileStatement(expression, statement, tn.range(startPos, tn.pos));
3673-
tn.skip(Token.Semicolon);
36743691
return ret;
36753692
} else {
36763693
this.error(
@@ -4131,6 +4148,15 @@ export class Parser extends DiagnosticEmitter {
41314148
while (
41324149
(nextPrecedence = determinePrecedence(tn.peek())) >= precedence
41334150
) {
4151+
let nextToken = tn.peek();
4152+
if (
4153+
(
4154+
nextToken == Token.Plus_Plus ||
4155+
nextToken == Token.Minus_Minus ||
4156+
nextToken == Token.As ||
4157+
nextToken == Token.Exclamation
4158+
) && tn.peekOnNewLine()
4159+
) break;
41344160
let token = tn.next();
41354161
switch (token) {
41364162

@@ -4430,6 +4456,12 @@ export class Parser extends DiagnosticEmitter {
44304456
);
44314457
}
44324458

4459+
private parseSemicolon(
4460+
tn: Tokenizer
4461+
): void {
4462+
if (!tn.skip(Token.Semicolon)) this.checkASI(tn);
4463+
}
4464+
44334465
/** Skips over a statement on errors in an attempt to reduce unnecessary diagnostic noise. */
44344466
skipStatement(tn: Tokenizer): void {
44354467
if (tn.peekOnNewLine()) tn.next(); // if reset() to the previous line
Collapse file

‎tests/compiler/asi.debug.wat‎

Copy file name to clipboard
+52Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
(module
2+
(type $0 (func))
3+
(type $1 (func (param i32 i32 i32 i32)))
4+
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
5+
(global $asi/i (mut i32) (i32.const 0))
6+
(global $asi/j (mut i32) (i32.const 7))
7+
(global $asi/k (mut i32) (i32.const 1))
8+
(global $~lib/memory/__data_end i32 (i32.const 44))
9+
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 32812))
10+
(global $~lib/memory/__heap_base i32 (i32.const 32812))
11+
(memory $0 1)
12+
(data $0 (i32.const 12) "\1c\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\0c\00\00\00a\00s\00i\00.\00t\00s\00")
13+
(table $0 1 1 funcref)
14+
(elem $0 (i32.const 1))
15+
(export "memory" (memory $0))
16+
(start $~start)
17+
(func $start:asi
18+
global.get $asi/j
19+
global.set $asi/i
20+
global.get $asi/k
21+
i32.const 1
22+
i32.add
23+
global.set $asi/k
24+
global.get $asi/i
25+
i32.const 7
26+
i32.eq
27+
i32.eqz
28+
if
29+
i32.const 0
30+
i32.const 32
31+
i32.const 8
32+
i32.const 1
33+
call $~lib/builtins/abort
34+
unreachable
35+
end
36+
global.get $asi/k
37+
i32.const 2
38+
i32.eq
39+
i32.eqz
40+
if
41+
i32.const 0
42+
i32.const 32
43+
i32.const 9
44+
i32.const 1
45+
call $~lib/builtins/abort
46+
unreachable
47+
end
48+
)
49+
(func $~start
50+
call $start:asi
51+
)
52+
)
Collapse file

‎tests/compiler/asi.release.wat‎

Copy file name to clipboard
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
(module
2+
(type $0 (func))
3+
(type $1 (func (param i32 i32 i32 i32)))
4+
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
5+
(global $asi/k (mut i32) (i32.const 1))
6+
(memory $0 1)
7+
(data $0 (i32.const 1036) "\1c")
8+
(data $0.1 (i32.const 1048) "\02\00\00\00\0c\00\00\00a\00s\00i\00.\00t\00s")
9+
(export "memory" (memory $0))
10+
(start $~start)
11+
(func $~start
12+
global.get $asi/k
13+
i32.const 1
14+
i32.add
15+
global.set $asi/k
16+
global.get $asi/k
17+
i32.const 2
18+
i32.ne
19+
if
20+
i32.const 0
21+
i32.const 1056
22+
i32.const 9
23+
i32.const 1
24+
call $~lib/builtins/abort
25+
unreachable
26+
end
27+
)
28+
)

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.