summaryrefslogtreecommitdiff
path: root/school/node_modules/graphql/language/experimentalOnlineParser/onlineParser.d.ts
blob: 9570b9e5893d866c4dc22c617594cf82b22b4acb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { Lexer } from '../lexer';

import {
  GraphQLGrammarTokenConstraint,
  GraphQLGrammarOfTypeConstraint,
  GraphQLGrammarListOfTypeConstraint,
  GraphQLGrammarPeekConstraint,
  GraphQLGrammarConstraintsSet,
} from './grammar';

interface BaseOnlineParserRule {
  kind: string;
  name?: string;
  depth: number;
  step: number;
  expanded: boolean;
  state: string;
  optional?: boolean;
  eatNextOnFail?: boolean;
}
interface TokenOnlineParserRule
  extends BaseOnlineParserRule,
    GraphQLGrammarTokenConstraint {}
interface OfTypeOnlineParserRule
  extends BaseOnlineParserRule,
    GraphQLGrammarOfTypeConstraint {}
interface ListOfTypeOnlineParserRule
  extends BaseOnlineParserRule,
    GraphQLGrammarListOfTypeConstraint {}
interface PeekOnlineParserRule
  extends BaseOnlineParserRule,
    GraphQLGrammarPeekConstraint {
  index: number;
  matched: boolean;
}
interface ConstraintsSetOnlineParserRule extends BaseOnlineParserRule {
  constraintsSet: boolean;
  constraints: GraphQLGrammarConstraintsSet;
}

type OnlineParserRule =
  | TokenOnlineParserRule
  | OfTypeOnlineParserRule
  | ListOfTypeOnlineParserRule
  | PeekOnlineParserRule
  | ConstraintsSetOnlineParserRule;

export interface OnlineParserState {
  rules: Array<OnlineParserRule>;
  kind: () => string;
  step: () => number;
  levels: Array<number>;
  indentLevel: number | undefined;
  name: string | null;
  type: string | null;
}

interface Token {
  kind: string;
  value?: string;
  tokenName?: string | undefined;
  ruleName?: string | undefined;
}

type OnlineParserConfig = {
  tabSize: number;
};

type OnlineParserConfigOption = {
  tabSize?: number;
};

export class OnlineParser {
  state: OnlineParserState;
  _lexer: Lexer;
  _config: OnlineParserConfig;
  constructor(
    source: string,
    state?: OnlineParserState,
    config?: OnlineParserConfigOption,
  );
  static startState(): OnlineParserState;
  static copyState(state: OnlineParserState): OnlineParserState;
  sol(): boolean;
  parseToken(): Token;
  indentation(): number;
  private readonly _parseTokenConstraint;
  private readonly _parseListOfTypeConstraint;
  private readonly _parseOfTypeConstraint;
  private readonly _parsePeekConstraint;
  private readonly _parseConstraintsSetRule;
  private readonly _matchToken;
  private readonly _butNot;
  private readonly _transformLexerToken;
  private readonly _getNextRule;
  private readonly _popMatchedRule;
  private readonly _rollbackRule;
  private readonly _pushRule;
  private readonly _getRuleKind;
  private readonly _advanceToken;
  private readonly _lookAhead;
}

export const TokenKind: {
  NAME: string;
  INT: string;
  FLOAT: string;
  STRING: string;
  BLOCK_STRING: string;
  COMMENT: string;
  PUNCTUATION: string;
  EOF: string;
  INVALID: string;
};

export const RuleKind: {
  TOKEN_CONSTRAINT: string;
  OF_TYPE_CONSTRAINT: string;
  LIST_OF_TYPE_CONSTRAINT: string;
  PEEK_CONSTRAINT: string;
  CONSTRAINTS_SET: string;
  CONSTRAINTS_SET_ROOT: string;
  RULE_NAME: string;
  INVALID: string;
};