@@ -70,23 +70,18 @@ import type {
7070import { Location , OperationTypeNode } from './ast.js' ;
7171import { DirectiveLocation } from './directiveLocation.js' ;
7272import { Kind } from './kinds.js' ;
73- import type { LexerOptions } from './lexer.js' ;
74- import { isPunctuatorTokenKind , Lexer } from './lexer.js' ;
73+ import {
74+ isPunctuatorTokenKind ,
75+ Lexer ,
76+ SchemaCoordinateLexer ,
77+ } from './lexer.js' ;
7578import { isSource , Source } from './source.js' ;
7679import { TokenKind } from './tokenKind.js' ;
7780
7881/**
7982 * Configuration options to control parser behavior
8083 */
8184export interface ParseOptions {
82- /**
83- * By default, ignored tokens are valid syntax and ignored when lexing.
84- * This may be disabled for certain grammars that specifically disallow
85- * ignored tokens (e.g. schema coordinates).
86- * This is passed down to the lexer to enforce.
87- */
88- noIgnoredTokens ?: boolean | undefined ;
89-
9085 /**
9186 * By default, the parser creates AST nodes that know the location
9287 * in the source that they correspond to. This configuration flag
@@ -123,6 +118,21 @@ export interface ParseOptions {
123118 * ```
124119 */
125120 experimentalFragmentArguments ?: boolean | undefined ;
121+
122+ /**
123+ * You may override the Lexer class used to lex the source; this is used by
124+ * schema coordinates to introduce a lexer that forbids ignored tokens.
125+ */
126+ Lexer ?: typeof Lexer | undefined ;
127+ }
128+
129+ export interface ParseSchemaCoordinateOptions {
130+ /**
131+ * By default, the parser creates AST nodes that know the location
132+ * in the source that they correspond to. This configuration flag
133+ * disables that behavior for performance or testing.
134+ */
135+ noLocation ?: boolean | undefined ;
126136}
127137
128138/**
@@ -208,12 +218,11 @@ export function parseType(
208218 */
209219export function parseSchemaCoordinate (
210220 source : string | Source ,
211- options : ParseOptions & { noIgnoredTokens ?: true } = { } ,
221+ options : ParseSchemaCoordinateOptions ,
212222) : SchemaCoordinateNode {
213223 // Ignored tokens are excluded syntax for the schema coordinates.
214- const _options = { ...options , noIgnoredTokens : true } ;
215-
216- const parser = new Parser ( source , _options ) ;
224+ const parserOptions = { ...options , Lexer : SchemaCoordinateLexer } ;
225+ const parser = new Parser ( source , parserOptions ) ;
217226 parser . expectToken ( TokenKind . SOF ) ;
218227 const coordinate = parser . parseSchemaCoordinate ( ) ;
219228 parser . expectToken ( TokenKind . EOF ) ;
@@ -239,11 +248,8 @@ export class Parser {
239248 constructor ( source : string | Source , options : ParseOptions = { } ) {
240249 const sourceObj = isSource ( source ) ? source : new Source ( source ) ;
241250
242- const lexerOptions : LexerOptions = {
243- noIgnoredTokens : options . noIgnoredTokens ?? false ,
244- } ;
245-
246- this . _lexer = new Lexer ( sourceObj , lexerOptions ) ;
251+ const LexerClass = options . Lexer ?? Lexer ;
252+ this . _lexer = new LexerClass ( sourceObj ) ;
247253 this . _options = options ;
248254 this . _tokenCounter = 0 ;
249255 }
0 commit comments