Skip to content

Commit 6bda784

Browse files
committed
handle semicolons after import statement
1 parent ad51f4f commit 6bda784

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/ast.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export namespace syxparser {
8888

8989
const ex = parseExpression(false, false);
9090
if (ex.type !== NodeType.String) throw new CompilerError(ex.range, 'Expected file path after import statement.');
91+
if (at().type !== TokenType.Semicolon) throw new CompilerError(at().range, `Expected ';' after import statement, found '${at().value}'.`);
92+
tokens.shift();
9193
return node({ type: NodeType.Import, path: (ex as Expression).value, range: combineTwo(token, ex.range) }, put);
9294

9395
} else if (token.type === TokenType.OperatorKeyword) {
@@ -118,13 +120,13 @@ export namespace syxparser {
118120

119121
if (t.type === TokenType.Comma && at().type !== TokenType.Identifier) throw new CompilerError(t.range, 'Expected identifier after comma.');
120122
else if (t.type === TokenType.Comma && statement.formats.length === 0) throw new CompilerError(t.range, 'Can\'t start with comma.');
121-
else if (t.type === TokenType.Comma) {}
123+
else if (t.type === TokenType.Comma) { }
122124
else if (t.type === TokenType.Identifier) statement.formats.push(t.value);
123125
else throw new CompilerError(t.range, `Expected comma or identifier, found '${t.value}'.`);
124126
}
125127
tokens.shift(); // skip CloseParen
126128

127-
if(statement.formats.length===0) throw new CompilerError(token.range,'At least one file type is required.');
129+
if (statement.formats.length === 0) throw new CompilerError(token.range, 'At least one file type is required.');
128130

129131
while (at().type !== TokenType.Semicolon) {
130132
const expr = parseExpression(false, false);
@@ -148,13 +150,13 @@ export namespace syxparser {
148150

149151
if (t.type === TokenType.Comma && at().type !== TokenType.Identifier) throw new CompilerError(t.range, 'Expected identifier after comma.');
150152
else if (t.type === TokenType.Comma && statement.formats.length === 0) throw new CompilerError(t.range, 'Can\'t start with comma.');
151-
else if (t.type === TokenType.Comma) {}
153+
else if (t.type === TokenType.Comma) { }
152154
else if (t.type === TokenType.Identifier) statement.formats.push(t.value);
153155
else throw new CompilerError(t.range, `Expected comma or identifier, found '${t.value}'.`);
154156
}
155157
tokens.shift(); // skip CloseParen
156158

157-
if(statement.formats.length===0) throw new CompilerError(token.range,'At least one file type is required.');
159+
if (statement.formats.length === 0) throw new CompilerError(token.range, 'At least one file type is required.');
158160

159161

160162
const moduleExpr = parseExpression(false, false) as Expression;
@@ -200,8 +202,8 @@ export namespace syxparser {
200202
if (ruleExpr.type !== NodeType.String) { throw new CompilerError(ruleExpr.range, `Expected rule name as string after 'rule', found ${ruleExpr.value}.`); }
201203
if (at().value !== ':') throw new CompilerError(at().range, `Expected \':\' after rule name, found ${at().value}.`);
202204
tokens.shift();
203-
if (!dictionary.Rules.find(r=>r.name===ruleExpr.value)) throw new CompilerError(ruleExpr.range, `Unknown rule '${ruleExpr.value}'.`);
204-
const rule = dictionary.Rules.find(r=>r.name===ruleExpr.value);
205+
if (!dictionary.Rules.find(r => r.name === ruleExpr.value)) throw new CompilerError(ruleExpr.range, `Unknown rule '${ruleExpr.value}'.`);
206+
const rule = dictionary.Rules.find(r => r.name === ruleExpr.value);
205207

206208
if (rule.type === 'boolean') {
207209
const boolEx = parseExpression(false, false, true) as Expression;
@@ -263,7 +265,7 @@ export namespace syxparser {
263265
tokens.shift();
264266
while (at().type !== TokenType.SingleQuote) {
265267
const _t = tokens.shift();
266-
if(_t.type===TokenType.EndOfFile) throw new CompilerError(combineTwo(range,{start:{line:0,character:0},end:{character:range.end.character+s.length,line:range.end.line}}),'Strings must be closed.');
268+
if (_t.type === TokenType.EndOfFile) throw new CompilerError(combineTwo(range, { start: { line: 0, character: 0 }, end: { character: range.end.character + s.length, line: range.end.line } }), 'Strings must be closed.');
267269

268270
s += _t.value;
269271
}
@@ -277,8 +279,8 @@ export namespace syxparser {
277279
tokens.shift();
278280
while (at().type !== TokenType.DoubleQuote) {
279281
const _t = tokens.shift();
280-
if(_t.type===TokenType.EndOfFile) throw new CompilerError(combineTwo(range,{start:{line:0,character:0},end:{character:range.end.character+s.length,line:range.end.line}}),'Strings must be closed.');
281-
282+
if (_t.type === TokenType.EndOfFile) throw new CompilerError(combineTwo(range, { start: { line: 0, character: 0 }, end: { character: range.end.character + s.length, line: range.end.line } }), 'Strings must be closed.');
283+
282284
s += _t.value;
283285
}
284286

@@ -447,6 +449,8 @@ export namespace sysparser {
447449

448450
const ex = parseExpression(false, false) as Expression;
449451
if (ex.type !== NodeType.String) throw new CompilerError(ex.range, `Expected string after import statement, found ${ex.value}.`);
452+
if (at().type !== TokenType.Semicolon) throw new CompilerError(at().range, `Expected ';' after import statement, found '${at().value}'.`);
453+
tokens.shift();
450454
return node({ type: NodeType.Import, path: (ex as Expression).value, range: combineTwo(token, ex.range) }, put);
451455

452456
}
@@ -489,7 +493,7 @@ export namespace sysparser {
489493
tokens.shift();
490494
while (at().type !== TokenType.SingleQuote) {
491495
const _t = tokens.shift();
492-
if(_t.type===TokenType.EndOfFile) throw new CompilerError(combineTwo(range,{start:{line:0,character:0},end:{character:range.end.character+s.length,line:range.end.line}}),'Strings must be closed.');
496+
if (_t.type === TokenType.EndOfFile) throw new CompilerError(combineTwo(range, { start: { line: 0, character: 0 }, end: { character: range.end.character + s.length, line: range.end.line } }), 'Strings must be closed.');
493497

494498
s += _t.value;
495499
}
@@ -503,8 +507,8 @@ export namespace sysparser {
503507
tokens.shift();
504508
while (at().type !== TokenType.DoubleQuote) {
505509
const _t = tokens.shift();
506-
if(_t.type===TokenType.EndOfFile) throw new CompilerError(combineTwo(range,{start:{line:0,character:0},end:{character:range.end.character+s.length,line:range.end.line}}),'Strings must be closed.');
507-
510+
if (_t.type === TokenType.EndOfFile) throw new CompilerError(combineTwo(range, { start: { line: 0, character: 0 }, end: { character: range.end.character + s.length, line: range.end.line } }), 'Strings must be closed.');
511+
508512
s += _t.value;
509513
}
510514

0 commit comments

Comments
 (0)