Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next: 改行できる箇所の追加実装 #590

Merged
merged 4 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/parser/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Scanner implements ITokenStream {
/**
* カーソル位置にあるトークンの種類を取得します。
*/
public get kind(): TokenKind {
public getKind(): TokenKind {
return this.token.kind;
}

Expand Down Expand Up @@ -74,8 +74,8 @@ export class Scanner implements ITokenStream {
* 一致しなかった場合には文法エラーを発生させます。
*/
public expect(kind: TokenKind): void {
if (this.kind !== kind) {
throw new AiScriptSyntaxError(`unexpected token: ${TokenKind[this.kind]}`, this.token.loc);
if (this.getKind() !== kind) {
throw new AiScriptSyntaxError(`unexpected token: ${TokenKind[this.getKind()]}`, this.token.loc);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/parser/streams/token-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface ITokenStream {
/**
* カーソル位置にあるトークンの種類を取得します。
*/
get kind(): TokenKind;
getKind(): TokenKind;

/**
* カーソル位置を次のトークンへ進めます。
Expand Down Expand Up @@ -70,7 +70,7 @@ export class TokenStream implements ITokenStream {
/**
* カーソル位置にあるトークンの種類を取得します。
*/
public get kind(): TokenKind {
public getKind(): TokenKind {
return this.token.kind;
}

Expand Down Expand Up @@ -100,8 +100,8 @@ export class TokenStream implements ITokenStream {
* 一致しなかった場合には文法エラーを発生させます。
*/
public expect(kind: TokenKind): void {
if (this.kind !== kind) {
throw new AiScriptSyntaxError(`unexpected token: ${TokenKind[this.kind]}`, this.token.loc);
if (this.getKind() !== kind) {
throw new AiScriptSyntaxError(`unexpected token: ${TokenKind[this.getKind()]}`, this.token.loc);
}
}

Expand Down
26 changes: 13 additions & 13 deletions src/parser/syntaxes/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ export function parseParams(s: ITokenStream): { name: string, argType?: Ast.Node

s.nextWith(TokenKind.OpenParen);

if (s.kind === TokenKind.NewLine) {
if (s.getKind() === TokenKind.NewLine) {
s.next();
}

while (s.kind !== TokenKind.CloseParen) {
while (s.getKind() !== TokenKind.CloseParen) {
s.expect(TokenKind.Identifier);
const name = s.token.value!;
s.next();

let type;
if ((s.kind as TokenKind) === TokenKind.Colon) {
if (s.getKind() === TokenKind.Colon) {
s.next();
type = parseType(s);
}

items.push({ name, argType: type });

// separator
switch (s.kind as TokenKind) {
switch (s.getKind()) {
case TokenKind.NewLine: {
s.next();
break;
}
case TokenKind.Comma: {
s.next();
if (s.kind === TokenKind.NewLine) {
if (s.getKind() === TokenKind.NewLine) {
s.next();
}
break;
Expand All @@ -68,19 +68,19 @@ export function parseParams(s: ITokenStream): { name: string, argType?: Ast.Node
export function parseBlock(s: ITokenStream): Ast.Node[] {
s.nextWith(TokenKind.OpenBrace);

while (s.kind === TokenKind.NewLine) {
while (s.getKind() === TokenKind.NewLine) {
s.next();
}

const steps: Ast.Node[] = [];
while (s.kind !== TokenKind.CloseBrace) {
while (s.getKind() !== TokenKind.CloseBrace) {
steps.push(parseStatement(s));

// terminator
switch (s.kind as TokenKind) {
switch (s.getKind()) {
case TokenKind.NewLine:
case TokenKind.SemiColon: {
while ([TokenKind.NewLine, TokenKind.SemiColon].includes(s.kind)) {
while ([TokenKind.NewLine, TokenKind.SemiColon].includes(s.getKind())) {
s.next();
}
break;
Expand All @@ -102,7 +102,7 @@ export function parseBlock(s: ITokenStream): Ast.Node[] {
//#region Type

export function parseType(s: ITokenStream): Ast.Node {
if (s.kind === TokenKind.At) {
if (s.getKind() === TokenKind.At) {
return parseFnType(s);
} else {
return parseNamedType(s);
Expand All @@ -122,9 +122,9 @@ function parseFnType(s: ITokenStream): Ast.Node {
s.nextWith(TokenKind.OpenParen);

const params: Ast.Node[] = [];
while (s.kind !== TokenKind.CloseParen) {
while (s.getKind() !== TokenKind.CloseParen) {
if (params.length > 0) {
switch (s.kind as TokenKind) {
switch (s.getKind()) {
case TokenKind.Comma: {
s.next();
break;
Expand Down Expand Up @@ -160,7 +160,7 @@ function parseNamedType(s: ITokenStream): Ast.Node {

// inner type
let inner = null;
if (s.kind === TokenKind.Lt) {
if (s.getKind() === TokenKind.Lt) {
s.next();
inner = parseType(s);
s.nextWith(TokenKind.Gt);
Expand Down
Loading
Loading