@@ -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,24 @@ 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+ /**
130+ * Configuration options to control schema coordinate parser behavior
131+ */
132+ export interface ParseSchemaCoordinateOptions {
133+ /**
134+ * By default, the parser creates AST nodes that know the location
135+ * in the source that they correspond to. This configuration flag
136+ * disables that behavior for performance or testing.
137+ */
138+ noLocation ?: boolean | undefined ;
126139}
127140
128141/**
@@ -208,11 +221,10 @@ export function parseType(
208221 */
209222export function parseSchemaCoordinate (
210223 source : string | Source ,
211- options : ParseOptions & { noIgnoredTokens ?: true } = { } ,
224+ options ?: ParseSchemaCoordinateOptions ,
212225) : SchemaCoordinateNode {
213226 // Ignored tokens are excluded syntax for the schema coordinates.
214- const _options = { ...options , noIgnoredTokens : true } ;
215-
227+ const _options = { ...options , Lexer : SchemaCoordinateLexer } ;
216228 const parser = new Parser ( source , _options ) ;
217229 parser . expectToken ( TokenKind . SOF ) ;
218230 const coordinate = parser . parseSchemaCoordinate ( ) ;
@@ -239,11 +251,8 @@ export class Parser {
239251 constructor ( source : string | Source , options : ParseOptions = { } ) {
240252 const sourceObj = isSource ( source ) ? source : new Source ( source ) ;
241253
242- const lexerOptions : LexerOptions = {
243- noIgnoredTokens : options . noIgnoredTokens ?? false ,
244- } ;
245-
246- this . _lexer = new Lexer ( sourceObj , lexerOptions ) ;
254+ const LexerClass = options . Lexer ?? Lexer ;
255+ this . _lexer = new LexerClass ( sourceObj ) ;
247256 this . _options = options ;
248257 this . _tokenCounter = 0 ;
249258 }
0 commit comments