Add Navigable interface

This commit is contained in:
aNNiMON 2024-03-06 00:18:13 +02:00
parent 3eac6863d6
commit 1367acb05f
2 changed files with 18 additions and 3 deletions

View File

@ -3,6 +3,7 @@ import { Variables } from "../runtime/Variables";
import { FadeInfo } from "../view/model/FadeInfo"; import { FadeInfo } from "../view/model/FadeInfo";
import { Menu } from "../view/model/Menu"; import { Menu } from "../view/model/Menu";
import { ViewModel } from "../view/model/ViewModel"; import { ViewModel } from "../view/model/ViewModel";
import { Navigable } from "../view/model/Navigable";
import { Token } from "./Token"; import { Token } from "./Token";
import { TokenType } from "./TokenType"; import { TokenType } from "./TokenType";
import { import {
@ -13,7 +14,7 @@ import {
Operator Operator
} from "./ast"; } from "./ast";
export class Parser { export class Parser implements Navigable {
private readonly EOF = new Token("", TokenType.EOF); private readonly EOF = new Token("", TokenType.EOF);
private tokensCount: number private tokensCount: number
@ -43,17 +44,21 @@ export class Parser {
this.vm = view this.vm = view
} }
public setPosition(position): void { public setPosition(position: number): void {
this.position = position; this.position = position;
this.next(); this.next();
} }
public jumpLabel(label): void { public jumpLabel(label: string): void {
if (label in this.labels) { if (label in this.labels) {
this.position = this.labels[label]; this.position = this.labels[label];
} }
} }
public getLastPosition(): number {
return this.lastPosition;
}
public next(): void { public next(): void {
this.lastPosition = this.position; this.lastPosition = this.position;

View File

@ -0,0 +1,10 @@
export interface Navigable {
setPosition(position: number): void
getLastPosition(): number
next(): void
jumpLabel(label: string): void
prevScene(): void
nextScene(): void
}