-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from msftrncs/LineEndRuleCnt
Fix line end rule count and debug
- Loading branch information
Showing
5 changed files
with
98 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1 @@ | ||
if (process.argv.length < 4) { | ||
console.log('usage: node index.js <mainGrammarPath> [<additionalGrammarPath1> ...] <filePath>'); | ||
process.exit(0); | ||
} | ||
|
||
var GRAMMAR_PATHS = process.argv.slice(2, process.argv.length - 1); | ||
var FILE_PATH = process.argv[process.argv.length - 1]; | ||
|
||
process.env['VSCODE_TEXTMATE_DEBUG'] = true; | ||
|
||
var fs = require('fs'); | ||
var main = require('../out/main'); | ||
|
||
var Registry = main.Registry; | ||
var registry = new Registry(); | ||
var grammarPromise = null; | ||
for (let path of GRAMMAR_PATHS) { | ||
console.log('LOADING GRAMMAR: ' + path); | ||
var content = fs.readFileSync(path).toString(); | ||
var rawGrammar = main.parseRawGrammar(content, path); | ||
var g = registry.addGrammar(rawGrammar); | ||
grammarPromise = grammarPromise || g; | ||
} | ||
grammarPromise.then(grammar => { | ||
var fileContents = fs.readFileSync(FILE_PATH).toString(); | ||
var lines = fileContents.split(/\r\n|\r|\n/); | ||
var ruleStack = null; | ||
var lastElementId = 0; | ||
for (var i = 0; i < lines.length; i++) { | ||
var line = lines[i]; | ||
|
||
console.log(''); | ||
console.log(''); | ||
console.log('==========================================='); | ||
console.log('TOKENIZING LINE ' + (i + 1) + ': |' + line + '|'); | ||
|
||
var r = grammar.tokenizeLine(line, ruleStack); | ||
|
||
console.log(''); | ||
|
||
var stackElement = r.ruleStack; | ||
var cnt = 0; | ||
while (stackElement) { | ||
cnt++; | ||
stackElement = stackElement._parent; | ||
} | ||
|
||
console.log('@@LINE END RULE STACK CONTAINS ' + cnt + ' RULES:'); | ||
stackElement = r.ruleStack; | ||
var list = []; | ||
while (stackElement) { | ||
if (!stackElement._instanceId) { | ||
stackElement._instanceId = (++lastElementId); | ||
} | ||
var ruleDesc = grammar._ruleId2desc[stackElement._ruleId] | ||
if (!ruleDesc) { | ||
list.push(' * no rule description found for rule id: ' + stackElement._ruleId); | ||
} else { | ||
list.push(' * ' + ruleDesc.debugName + ' -- [' + ruleDesc.id + ',' + stackElement._instanceId + '] "' + stackElement._scopeName + '"'); | ||
} | ||
stackElement = stackElement._parent; | ||
} | ||
list.reverse(); | ||
console.log(list.join('\n')); | ||
|
||
ruleStack = r.ruleStack; | ||
} | ||
}); | ||
require('../out/inspect'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
*--------------------------------------------------------*/ | ||
|
||
import * as fs from 'fs'; | ||
import { Registry, IGrammar, parseRawGrammar, Thenable } from './main'; | ||
import { StackElement as StackElementImpl, Grammar as GrammarImpl } from './grammar'; | ||
import * as debug from './debug'; | ||
|
||
class ExtendedStackElement extends StackElementImpl { | ||
_instanceId?: number; | ||
} | ||
|
||
debug.DebugFlags.InDebugMode = true; | ||
|
||
if (process.argv.length < 4) { | ||
console.log('usage: node index.js <mainGrammarPath> [<additionalGrammarPath1> ...] <filePath>'); | ||
process.exit(0); | ||
} | ||
|
||
const GRAMMAR_PATHS = process.argv.slice(2, process.argv.length - 1); | ||
const FILE_PATH = process.argv[process.argv.length - 1]; | ||
|
||
const registry = new Registry(); | ||
let grammarPromises: Thenable<IGrammar>[] = []; | ||
for (let path of GRAMMAR_PATHS) { | ||
console.log('LOADING GRAMMAR: ' + path); | ||
const content = fs.readFileSync(path).toString(); | ||
const rawGrammar = parseRawGrammar(content, path); | ||
grammarPromises.push(registry.addGrammar(rawGrammar)); | ||
} | ||
|
||
Promise.all(grammarPromises).then(_grammars => { | ||
const grammar = _grammars[0]; | ||
const fileContents = fs.readFileSync(FILE_PATH).toString(); | ||
const lines = fileContents.split(/\r\n|\r|\n/); | ||
let ruleStack = null; | ||
let lastElementId = 0; | ||
for (let i = 0; i < lines.length; i++) { | ||
const line = lines[i]; | ||
|
||
console.log(''); | ||
console.log(''); | ||
console.log('==========================================='); | ||
console.log('TOKENIZING LINE ' + (i + 1) + ': |' + line + '|'); | ||
|
||
const r = grammar.tokenizeLine(line, ruleStack); | ||
|
||
console.log(''); | ||
|
||
let stackElement = <ExtendedStackElement>r.ruleStack; | ||
let cnt = 0; | ||
while (stackElement) { | ||
cnt++; | ||
stackElement = stackElement.parent; | ||
} | ||
|
||
console.log('@@LINE END RULE STACK CONTAINS ' + cnt + ' RULES:'); | ||
stackElement = <ExtendedStackElement>r.ruleStack; | ||
let list: string[] = []; | ||
while (stackElement) { | ||
if (!stackElement._instanceId) { | ||
stackElement._instanceId = (++lastElementId); | ||
} | ||
let ruleDesc = (<GrammarImpl>grammar).getRule(stackElement.ruleId); | ||
if (!ruleDesc) { | ||
list.push(' * no rule description found for rule id: ' + stackElement.ruleId); | ||
} else { | ||
list.push(' * ' + ruleDesc.debugName + ' -- [' + ruleDesc.id + ',' + stackElement._instanceId + '] "' + stackElement.nameScopesList.generateScopes() + '", "' + stackElement.contentNameScopesList.generateScopes() + '"'); | ||
} | ||
stackElement = stackElement.parent; | ||
} | ||
list.reverse(); | ||
console.log(list.join('\n')); | ||
|
||
ruleStack = r.ruleStack; | ||
} | ||
}); |