Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function runOnlineParser(
queryText: string,
callback: callbackFnType,
): ContextToken {
const lines = queryText.split('\n');
const parser = onlineParser();
let state = parser.startState();
let style = '';
let stream: CharacterStream = new CharacterStream('');
for (let i = 0; i < lines.length; i++) {
stream = new CharacterStream(lines[i]);
// Stop the parsing when the stream arrives at the current cursor position
while (!stream.eol()) {
style = parser.token(stream, state);
const code = callback(stream, state, style, i);
if (code === 'BREAK') {
break;
}
}
function runOnlineParser(
queryText: string,
callback: callbackFnType,
): ContextToken {
const lines = queryText.split('\n');
const parser = onlineParser();
let state = parser.startState();
let style = '';
let stream: CharacterStream = new CharacterStream('');
for (let i = 0; i < lines.length; i++) {
stream = new CharacterStream(lines[i]);
while (!stream.eol()) {
style = parser.token(stream, state);
const code = callback(stream, state, style, i);
if (code === 'BREAK') {
break;
}
}
// Above while loop won't run if there is an empty line.
export default function runParser(sourceText, parserOptions, callbackFn) {
const parser = onlineParser(parserOptions);
const state = parser.startState();
const lines = sourceText.split('\n');
lines.forEach(line => {
const stream = new CharacterStream(line);
while (!stream.eol()) {
const style = parser.token(stream, state);
callbackFn(stream, state, style);
}
});
}
CodeMirror.defineMode('graphql', config => {
const parser = onlineParser({
eatWhitespace: stream => stream.eatWhile(isIgnored),
lexRules: LexRules,
parseRules: ParseRules,
editorConfig: { tabSize: config.tabSize },
});
return {
config,
startState: parser.startState,
token: parser.token,
indent,
electricInput: /^\s*[})\]]/,
fold: 'brace',
lineComment: '#',
closeBrackets: {
pairs: '()[]{}""',
CodeMirror.defineMode('graphql-variables', config => {
const parser = onlineParser({
eatWhitespace: stream => stream.eatSpace(),
lexRules: LexRules,
parseRules: ParseRules,
editorConfig: { tabSize: config.tabSize },
});
return {
config,
startState: parser.startState,
token: parser.token,
indent,
electricInput: /^\s*[}\]]/,
fold: 'brace',
closeBrackets: {
pairs: '[]{}""',
explode: '[]{}',
constructor() {
this._parser = onlineParser({
eatWhitespace: (stream) => stream.eatWhile(isIgnored),
lexRules: LexRules,
parseRules: ParseRules,
});
}