Skip to content

Commit

Permalink
fix: add support for paths in msgbox.obj (#276)
Browse files Browse the repository at this point in the history
Add support for paths in msgbox.obj
  • Loading branch information
vetlek authored Sep 1, 2023
1 parent 9edabb2 commit f15b4f1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
20 changes: 19 additions & 1 deletion server/src/septic/septicParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ let validAttributeTokens = [
SepticTokenType.numeric,
SepticTokenType.string,
SepticTokenType.identifier,
SepticTokenType.path,
];

export class SepticParser extends Parser<SepticTokenType, SepticCnfg> {
Expand Down Expand Up @@ -220,7 +221,7 @@ export class SepticScanner {
} else if (this.peek() === "*") {
this.blockComment();
} else {
this.error(`Unexpected token: ${this.peek()}`);
this.path();
}
break;
case "-":
Expand All @@ -231,6 +232,9 @@ export class SepticScanner {
this.error(`Unexpected token: ${c}`);
}
break;
case "~":
this.path();
break;
default:
if (this.isDigit(c)) {
this.numeric();
Expand Down Expand Up @@ -427,6 +431,20 @@ export class SepticScanner {
}
}

private path(): void {
while (
!this.isAtEnd() &&
!(
this.peek() === " " ||
this.peek() === "\n" ||
this.peek() === "\r"
)
) {
this.advance();
}
this.addToken(SepticTokenType.path);
}

private isDigit(char: string): boolean {
return char >= "0" && char <= "9";
}
Expand Down
1 change: 1 addition & 0 deletions server/src/septic/septicTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum SepticTokenType {
skip,
unknown,
identifier,
path,
eof = "eof",
}

Expand Down
40 changes: 39 additions & 1 deletion server/src/test/septicParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,37 @@ describe("Test tokenization of comments", () => {
});
});

describe("Test tokenization of paths", () => {
it("Expect correct tokenization of path", () => {
const input = "Obj= /test/path ";
const scanner = new SepticScanner(input);
let tokens = scanner.scanTokens();
expect(tokens.tokens.length).to.equal(3);
expect(tokens.tokens[0].type).to.equal(SepticTokenType.attribute);
expect(tokens.tokens[1].type).to.equal(SepticTokenType.path);
expect(tokens.tokens[1].content).to.equal("/test/path");
});

it("Expect correct tokenization of wildcard path", () => {
const input = "Obj= ~ ";
const scanner = new SepticScanner(input);
let tokens = scanner.scanTokens();
expect(tokens.tokens.length).to.equal(3);
expect(tokens.tokens[0].type).to.equal(SepticTokenType.attribute);
expect(tokens.tokens[1].type).to.equal(SepticTokenType.path);
expect(tokens.tokens[1].content).to.equal("~");
});

it("Expect no path tokens for invalid paths", () => {
const input = "Obj= \bspath ";
const scanner = new SepticScanner(input);
let tokens = scanner.scanTokens();
expect(tokens.tokens.length).to.equal(4);
expect(tokens.tokens[0].type).to.equal(SepticTokenType.attribute);
expect(tokens.tokens[1].type).to.not.equal(SepticTokenType.path);
});
});

describe("Test tokenization of blocks", () => {
it("Expect correct tokenization of attribute with list of values", () => {
const input = `Grps= 7
Expand Down Expand Up @@ -637,6 +668,12 @@ describe("Test basic functionality of parser", () => {
end: 63,
content: "OFF",
},
{
type: SepticTokenType.path,
start: 65,
end: 70,
content: "/test/path",
},
{
type: SepticTokenType.eof,
start: 100,
Expand All @@ -648,12 +685,13 @@ describe("Test basic functionality of parser", () => {
parser.advance();
let attr = parser.attribute();
expect(attr.key).to.equal("Test");
expect(attr.values.length).to.equal(5);
expect(attr.values.length).to.equal(6);
expect(attr.values[0].value).to.equal("Test");
expect(attr.values[1].value).to.equal("77");
expect(attr.values[2].value).to.equal("00000000000000000000001");
expect(attr.values[3].value).to.equal("1000");
expect(attr.values[4].value).to.equal("OFF");
expect(attr.values[5].value).to.equal("/test/path");
});

it("Test parsing of variables with one part", () => {
Expand Down

0 comments on commit f15b4f1

Please sign in to comment.