Skip to content

Commit

Permalink
Lexer: remove passthrough options (#2209)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Oct 1, 2019
1 parent 5eb7c4d commit f36ca25
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
15 changes: 5 additions & 10 deletions src/language/lexer.js
Expand Up @@ -17,14 +17,10 @@ import { type TokenKindEnum, TokenKind } from './tokenKind';
* EOF, after which the lexer will repeatedly return the same EOF token
* whenever called.
*/
export function createLexer<TOptions>(
source: Source,
options: TOptions,
): Lexer<TOptions> {
export function createLexer(source: Source): Lexer {
const startOfFileToken = new Tok(TokenKind.SOF, 0, 0, 0, 0, null);
const lexer: Lexer<TOptions> = {
const lexer: Lexer = {
source,
options,
lastToken: startOfFileToken,
token: startOfFileToken,
line: 1,
Expand Down Expand Up @@ -55,9 +51,8 @@ function lookahead() {
/**
* The return type of createLexer.
*/
export type Lexer<TOptions> = {
export type Lexer = {
source: Source,
options: TOptions,

/**
* The previously focused non-ignored token.
Expand Down Expand Up @@ -167,7 +162,7 @@ function printCharCode(code) {
* punctuators immediately or calls the appropriate helper function for more
* complicated tokens.
*/
function readToken(lexer: Lexer<mixed>, prev: Token): Token {
function readToken(lexer: Lexer, prev: Token): Token {
const source = lexer.source;
const body = source.body;
const bodyLength = body.length;
Expand Down Expand Up @@ -334,7 +329,7 @@ function unexpectedCharacterMessage(code) {
function positionAfterWhitespace(
body: string,
startPosition: number,
lexer: Lexer<mixed>,
lexer: Lexer,
): number {
const bodyLength = body.length;
let position = startPosition;
Expand Down
2 changes: 1 addition & 1 deletion src/language/parser.js
Expand Up @@ -168,7 +168,7 @@ export function parseType(

class Parser {
_options: ParseOptions;
_lexer: Lexer<void>;
_lexer: Lexer;

constructor(source: string | Source, options?: ParseOptions) {
const sourceObj = typeof source === 'string' ? new Source(source) : source;
Expand Down
8 changes: 2 additions & 6 deletions tstypes/language/lexer.d.ts
Expand Up @@ -10,17 +10,13 @@ import { Source } from './source';
* EOF, after which the lexer will repeatedly return the same EOF token
* whenever called.
*/
export function createLexer<TOptions>(
source: Source,
options: TOptions,
): Lexer<TOptions>;
export function createLexer(source: Source): Lexer;

/**
* The return type of createLexer.
*/
export interface Lexer<TOptions> {
export interface Lexer {
source: Source;
options: TOptions;

/**
* The previously focused non-ignored token.
Expand Down

0 comments on commit f36ca25

Please sign in to comment.