(block, blockId, offset = 0, spans = [], extraInfo = {})
| 1369 | let eveParser = new Parser([]); |
| 1370 | |
| 1371 | export function parseBlock(block, blockId, offset = 0, spans = [], extraInfo = {}) { |
| 1372 | let start = time(); |
| 1373 | let lex: any = EveBlockLexer.tokenize(block); |
| 1374 | let token: any; |
| 1375 | let tokenIx = 0; |
| 1376 | for(token of lex.tokens) { |
| 1377 | let tokenId = `${blockId}|token|${tokenIx++}`; |
| 1378 | token.id = tokenId; |
| 1379 | token.startOffset += offset; |
| 1380 | spans.push(token.startOffset, token.startOffset + token.image.length, token.label, tokenId); |
| 1381 | } |
| 1382 | for(token of lex.groups.comments) { |
| 1383 | let tokenId = `${blockId}|token|${tokenIx++}`; |
| 1384 | token.id = tokenId; |
| 1385 | token.startOffset += offset; |
| 1386 | spans.push(token.startOffset, token.startOffset + token.image.length, token.label, tokenId); |
| 1387 | } |
| 1388 | eveParser.input = lex.tokens; |
| 1389 | let results; |
| 1390 | try { |
| 1391 | // The parameters here are a strange quirk of how Chevrotain works, I believe the |
| 1392 | // 1 tells chevrotain what level the rule is starting at, we then pass our params |
| 1393 | // to the codeBlock parser function as an array |
| 1394 | results = eveParser.codeBlock(1, [blockId]); |
| 1395 | } catch(e) { |
| 1396 | console.error("The parser threw an error: " + e); |
| 1397 | } |
| 1398 | if(results) { |
| 1399 | results.start = offset; |
| 1400 | results.startOffset = offset; |
| 1401 | results.tokens = lex.tokens; |
| 1402 | for(let scan of results.scanLike) { |
| 1403 | let type = "scan-boundary"; |
| 1404 | if(scan.type === "record") { |
| 1405 | type = "record-boundary"; |
| 1406 | } |
| 1407 | spans.push(scan.startOffset, scan.endOffset, type, scan.id); |
| 1408 | } |
| 1409 | for(let action of results.binds) { |
| 1410 | let type = "action-boundary"; |
| 1411 | if(action.type === "record") { |
| 1412 | type = "action-record-boundary"; |
| 1413 | } |
| 1414 | spans.push(action.startOffset, action.endOffset, type, action.id); |
| 1415 | extraInfo[action.id] = {kind: "bind"}; |
| 1416 | } |
| 1417 | for(let action of results.commits) { |
| 1418 | let type = "action-boundary"; |
| 1419 | if(action.type === "record") { |
| 1420 | type = "action-record-boundary"; |
| 1421 | } |
| 1422 | spans.push(action.startOffset, action.endOffset, type, action.id); |
| 1423 | extraInfo[action.id] = {kind: "commits"}; |
| 1424 | } |
| 1425 | } |
| 1426 | let errors = parserErrors(eveParser.errors, {blockId, blockStart: offset, spans, extraInfo, tokens: lex.tokens}); |
| 1427 | lex.groups.comments.length = 0; |
| 1428 | return { |
no test coverage detected