Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
17 changes: 17 additions & 0 deletions AGENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ScoreLang Agent Guidelines

## Commands
- Run tests: `bun test`
- Run specific test: `bun test src/lexer.test.ts`
- Build project: `bun build ./src/index.ts --compile --outfile scorelang`

## Code Style Guidelines
- **Imports**: Use named imports for specific components, default exports for main classes
- **Types**: Use TypeScript with explicit type annotations, const assertions when appropriate
- **Error handling**: Use console.log for errors, return null/ILLEGAL tokens for invalid inputs
- **Naming conventions**:
- Classes: PascalCase (e.g., Lexer)
- Methods/variables: camelCase
- Constants: UPPER_SNAKE_CASE for token types
- **Formatting**: 2-space indentation, semicolons at end of statements
- **Class structure**: Private methods prefixed with 'private', constructor parameters prefixed with 'private' when appropriate
34 changes: 34 additions & 0 deletions src/lexer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,38 @@ describe("Lexer", () => {
expect(token).toEqual(expectedToken);
});
});

it("should tokenize a string with team names with spaces", () => {
const input = `Manchester United 2-0 Arsenal;`;
const lexer = new Lexer(input);
[
{ type: "TEAM_NAME" as const, value: "Manchester United" },
{ type: "TEAM_SCORE" as const, value: "2" },
{ type: "SCORE_SEPARATOR" as const, value: "-" },
{ type: "TEAM_SCORE" as const, value: "0" },
{ type: "TEAM_NAME" as const, value: "Arsenal" },
{ type: "GAME_SEPARATOR" as const, value: ";" },
{ type: "EOF" as const, value: "" },
].forEach((expectedToken) => {
const token = lexer.nextToken();
expect(token).toEqual(expectedToken);
});
})

it("should tokenize a string with team names with multiple spaces", () => {
const input = `Manchester United 2-0 Arsenal;`;
const lexer = new Lexer(input);
[
{ type: "TEAM_NAME" as const, value: "Manchester United" },
{ type: "TEAM_SCORE" as const, value: "2" },
{ type: "SCORE_SEPARATOR" as const, value: "-" },
{ type: "TEAM_SCORE" as const, value: "0" },
{ type: "TEAM_NAME" as const, value: "Arsenal" },
{ type: "GAME_SEPARATOR" as const, value: ";" },
{ type: "EOF" as const, value: "" },
].forEach((expectedToken) => {
const token = lexer.nextToken();
expect(token).toEqual(expectedToken);
});
})
});
12 changes: 10 additions & 2 deletions src/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ export class Lexer {

private readIdentifier(): string {
const startPosition = this.position;
while (this.isLetter(this.ch)) {
while (this.isLetter(this.ch) || this.ch === " ") {
this.readChar();
}
return this.program.slice(startPosition, this.position);
return this.program.slice(startPosition, this.position).trim()
}

private peekChar(): string {
if (this.readPosition >= this.program.length) {
return "";
} else {
return this.program[this.readPosition]!;
}
}

private readNumber(): string {
Expand Down