Skip to content

Commit

Permalink
Remove explicit EOF token from token builder (#1276)
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew authored Nov 8, 2023
1 parent 02d1fe8 commit 2b20f94
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions packages/langium/src/parser/token-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import type { CustomPatternMatcherFunc, TokenPattern, TokenType, TokenVocabulary } from 'chevrotain';
import type { AbstractRule, Grammar, Keyword, TerminalRule } from '../grammar/generated/ast.js';
import type { Stream } from '../utils/stream.js';
import { Lexer, EOF } from 'chevrotain';
import { isKeyword, isParserRule, isTerminalRule, isEndOfFile } from '../grammar/generated/ast.js';
import { Lexer } from 'chevrotain';
import { isKeyword, isParserRule, isTerminalRule } from '../grammar/generated/ast.js';
import { terminalRegex } from '../grammar/internal-grammar-util.js';
import { streamAllContents, streamAst } from '../utils/ast-util.js';
import { streamAllContents } from '../utils/ast-util.js';
import { getAllReachableRules } from '../utils/grammar-util.js';
import { getCaseInsensitivePattern, isWhitespaceRegExp, partialMatches } from '../utils/regex-util.js';
import { stream } from '../utils/stream.js';
Expand Down Expand Up @@ -38,11 +38,8 @@ export class DefaultTokenBuilder implements TokenBuilder {
tokens.push(terminalToken);
}
});

//reminder: EOF should always be the last token, because it is very unlikely that it will be matched within the input
if (reachableRules.some(r => streamAst(r.definition).some(isEndOfFile))) {
tokens.push(EOF);
}
// We don't need to add the EOF token explicitly.
// It is automatically available at the end of the token stream.
return tokens;
}

Expand Down

0 comments on commit 2b20f94

Please sign in to comment.