feat: fix begin rule error issues

上级 1e080798
# C issues
## Lost begin_captures
```bash
meta.preprocessor.c.include
```
### Correct
```json
"beginCaptures": [
null,
{
"id": 86,
"_name": "keyword.control.import.include.c",
"_nameIsCapturing": false,
"_contentName": null,
"_contentNameIsCapturing": false,
"retokenizeCapturedWithRuleId": 0,
"_type": "CaptureRule"
}
],
```
### Error
```json
"begin_captures": [],
```
\ No newline at end of file
......@@ -660,7 +660,13 @@ return 0;
}
";
let grammar = to_grammar_with_code("test-cases/first-mate/fixtures/c.json", code);
// assert_eq!(grammar.rule_id2desc.len(), 162);
debug_output(&grammar, String::from("program.json"));
}
#[test]
fn should_identify_c_include() {
let code = "#include <stdio.h>";
let grammar = to_grammar_with_code("test-cases/first-mate/fixtures/c.json", code);
debug_output(&grammar, String::from("program.json"));
}
......
......@@ -26,7 +26,6 @@ impl RuleFactory {
repository: &mut IRawRepository,
) -> Vec<Box<dyn AbstractRule>> {
let mut r: Vec<Box<dyn AbstractRule>> = vec![];
if let Some(capts) = captures.clone() {
let mut maximum_capture_id = 0;
for (id_str, _value) in capts.clone().map.capture_map {
......@@ -305,8 +304,8 @@ impl RuleFactory {
}
let begin_rule_factory =
RuleFactory::compile_captures(begin_captures, helper, repository);
let end_rule_factory = RuleFactory::compile_captures(end_captures, helper, repository);
RuleFactory::compile_captures(desc.begin_captures, helper, repository);
let end_rule_factory = RuleFactory::compile_captures(desc.end_captures, helper, repository);
let pattern_factory = RuleFactory::compile_patterns(desc.patterns, helper, repository);
let begin_end_rule = BeginEndRule::new(
......
......@@ -15,15 +15,12 @@ const registry = new vsctm.Registry({
createOnigString: (str) => new oniguruma.OnigString(str)
}),
loadGrammar: (scopeName) => {
return readFile('./syntaxes/json/makefile.json').then(data => vsctm.parseRawGrammar(data.toString(), "makefile.json"))
return readFile('./syntaxes/json/c.json').then(data => vsctm.parseRawGrammar(data.toString(), "c.json"))
}
});
registry.loadGrammar('source.makefile').then(grammar => {
const text = `
hellomake: $(OBJ)
\t$(CC) -o $@ $^ $(CFLAGS)
`.split("\n");
registry.loadGrammar('source.c').then(grammar => {
const text = `#include <stdio.h>`.split("\n");
let ruleStack = vsctm.INITIAL;
for (let i = 0; i < text.length; i++) {
const line = text[i];
......
此差异已折叠。
......@@ -734,11 +734,11 @@ var Grammar = /** @class */ (function () {
if (this._rootId === -1) {
this._rootId = rule_1.RuleFactory.getCompiledRuleId(this._grammar.repository.$self, this, this._grammar.repository);
}
//
// console.log(this._ruleId2desc.length);
// let fs = require('fs');
// let data = JSON.stringify(this._ruleId2desc, null, 2);
// fs.writeFileSync("testdata/makefile.out.json", data, 'utf8');
// fs.writeFileSync("testdata/c.out.json", data, 'utf8');
var isFirstLine;
if (!prevState || prevState === StackElement.NULL) {
......@@ -3628,6 +3628,8 @@ var RuleFactory = /** @class */ (function () {
var retokenizeCapturedWithRuleId = 0;
if (captures[captureId].patterns) {
retokenizeCapturedWithRuleId = RuleFactory.getCompiledRuleId(captures[captureId], helper, repository);
} else {
console.log(captures[captureId], numericCaptureId);
}
r[numericCaptureId] = RuleFactory.createCaptureRule(helper, captures[captureId].$vscodeTextmateLocation, captures[captureId].name, captures[captureId].contentName, retokenizeCapturedWithRuleId);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册