Skip to content

Commit

Permalink
bugfix: Fix SimaiException line count issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xhayper committed Feb 23, 2024
1 parent 1d9fe83 commit c5037cc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 36 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
},
"homepage": "https://github.com/reflektone-games/simai.js#readme",
"devDependencies": {
"@types/mocha": "^10.0.4",
"@types/node": "^20.9.0",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.20",
"del-cli": "^5.1.0",
"mocha": "^10.2.0",
"ts-node": "^10.9.1",
"tsup": "^7.2.0"
"mocha": "^10.3.0",
"ts-node": "^10.9.2",
"tsup": "^8.0.2"
},
"volta": {
"node": "18.12.0",
Expand Down
56 changes: 27 additions & 29 deletions src/internal/lexicalAnalysis/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ export class Tokenizer {

const c = this.advance();

if (this.decoratorChars.has(c)) return this.compileToken(TokenType.Decorator);
else if (this.eachDividerChars.has(c)) return this.compileToken(TokenType.EachDivider);
else if (this.separatorChars.has(c)) return undefined;

switch (c) {
case ",":
return this.compileToken(TokenType.TimeStep);
Expand All @@ -75,47 +71,49 @@ export class Tokenizer {
return this.compileSectionToken(TokenType.Subdivision, "{", "}");
case "[":
return this.compileSectionToken(TokenType.Duration, "[", "]");
}

const [isLocationToken, locationLength] = this.tryScanLocationToken();
if (isLocationToken) {
this._current += locationLength - 1;
return this.compileToken(TokenType.Location);
}

if (this.decoratorChars.has(c)) return this.compileToken(TokenType.Decorator);

const [isSlideDeclaration, slideLength] = this.isReadingSlideDeclaration();
if (isSlideDeclaration) {
this._current += slideLength - 1;
return this.compileToken(TokenType.Slide);
}

case "*":
return this.compileToken(TokenType.SlideJoiner);
if (c === "*") return this.compileToken(TokenType.SlideJoiner);

if (this.eachDividerChars.has(c)) return this.compileToken(TokenType.EachDivider);

if (this.separatorChars.has(c)) {
// Ignore whitespace.
return undefined;
}

switch (c) {
case "\n":
this._line++;
this._charIndex = 0;
return undefined;

case this.endOfFileChar:
try {
const [isLocationToken, locationLength] = this.tryScanLocationToken();
if (isLocationToken) {
this._current += locationLength - 1;
return this.compileToken(TokenType.Location);
}
} catch (ignored) {}

case "E":
return this.compileToken(TokenType.EndOfFile);

case "|": {
if (this.peek() !== "|") throw new UnexpectedCharacterException(this._line, this._charIndex, "|");
if (this.peek() != "|") throw new UnexpectedCharacterException(this._line, this._charIndex, "|");

while (this.peek() !== "\n" && !this.isAtEnd) this.advance();
while (this.peek() != "\n" && !this.isAtEnd) this.advance();

return undefined;
}
}

const [isLocationToken, locationLength] = this.tryScanLocationToken();
if (isLocationToken) {
this._current += locationLength - 1;
return this.compileToken(TokenType.Location);
}

const [isSlideDeclaration, slideLength] = this.isReadingSlideDeclaration();
if (isSlideDeclaration) {
this._current += slideLength - 1;
return this.compileToken(TokenType.Slide);
}

throw new UnsupportedSyntaxException(this._line, this._charIndex);
}

Expand Down
4 changes: 2 additions & 2 deletions src/simaiFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class SimaiFile {
for (let line of lines) {
if (line.startsWith("&")) {
if (currentKey !== "") {
result.set(currentKey, currentValue.trim());
result.set(currentKey, currentValue.trimEnd());
currentValue = "";
}

Expand All @@ -29,7 +29,7 @@ export class SimaiFile {
}

// Incase there is no trailing newline
if (currentKey) result.set(currentKey, currentValue.trim());
if (currentKey) result.set(currentKey, currentValue.trimEnd());

return result;
}
Expand Down

0 comments on commit c5037cc

Please sign in to comment.