test: add simplify code for index

上级 f51ce3f1
...@@ -8,30 +8,36 @@ function readFile(path) { ...@@ -8,30 +8,36 @@ function readFile(path) {
}) })
} }
// Create a registry that can create a grammar from a scope name. let promise = readFile('./syntaxes/json/c.json').then(data => vsctm.parseRawGrammar(data.toString(), "c.json"));
const registry = new vsctm.Registry({ promise.then((grammar) => {
onigLib: Promise.resolve({ console.log(grammar.patterns.length);
createOnigScanner: (sources) => new oniguruma.OnigScanner(sources), })
createOnigString: (str) => new oniguruma.OnigString(str)
}),
loadGrammar: (scopeName) => {
return readFile('./syntaxes/json/c.json').then(data => vsctm.parseRawGrammar(data.toString(), "c.json"))
}
});
registry.loadGrammar('source.c').then(grammar => { //
const text = `#include <stdio.h>`.split("\n"); // // Create a registry that can create a grammar from a scope name.
let ruleStack = vsctm.INITIAL; // const registry = new vsctm.Registry({
for (let i = 0; i < text.length; i++) { // onigLib: Promise.resolve({
const line = text[i]; // createOnigScanner: (sources) => new oniguruma.OnigScanner(sources),
const lineTokens = grammar.tokenizeLine(line, ruleStack); // createOnigString: (str) => new oniguruma.OnigString(str)
for (let j = 0; j < lineTokens.tokens.length; j++) { // }),
const token = lineTokens.tokens[j]; // loadGrammar: (scopeName) => {
console.log(` - token from ${token.startIndex} to ${token.endIndex} ` + // return readFile('./syntaxes/json/c.json').then(data => vsctm.parseRawGrammar(data.toString(), "c.json"))
`(${line.substring(token.startIndex, token.endIndex)}) ` + // }
`with scopes ${token.scopes.join(', ')}` // });
); //
} // registry.loadGrammar('source.c').then(grammar => {
ruleStack = lineTokens.ruleStack; // const text = `#include <stdio.h>`.split("\n");
} // let ruleStack = vsctm.INITIAL;
}); // for (let i = 0; i < text.length; i++) {
// const line = text[i];
// const lineTokens = grammar.tokenizeLine(line, ruleStack);
// for (let j = 0; j < lineTokens.tokens.length; j++) {
// const token = lineTokens.tokens[j];
// console.log(` - token from ${token.startIndex} to ${token.endIndex} ` +
// `(${line.substring(token.startIndex, token.endIndex)}) ` +
// `with scopes ${token.scopes.join(', ')}`
// );
// }
// ruleStack = lineTokens.ruleStack;
// }
// });
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册