refactor: update demo code && fxied issue

上级 338dca8c
......@@ -354,8 +354,8 @@ impl Grammar {
grammar: &mut Grammar,
line_text: String,
is_first_line: bool,
mut stack: &mut StackElement,
mut line_tokens: &mut LineTokens,
stack: &mut StackElement,
line_tokens: &mut LineTokens,
captures: Vec<Box<dyn AbstractRule>>,
capture_indices: Vec<IOnigCaptureIndex>,
) -> Option<LineTokens> {
......@@ -412,7 +412,7 @@ impl Grammar {
.get_content_name(Some(line_text.clone()), Some(capture_indices.clone()));
let content_name_scopes_list = name_scopes_list.push(grammar, content_name);
let mut stack_clone = stack.clone().push(
let stack_clone = stack.clone().push(
capture.retokenize_captured_with_rule_id,
capture_index.start.clone() as i32,
-1,
......
......@@ -103,7 +103,7 @@ impl RuleFactory {
if let Some(include_s) = pattern.clone().include {
if include_s.starts_with("#") {
let first = remove_first(include_s.as_str());
let mut local_included_rule = repository.map.name_map.get_mut(first);
let local_included_rule = repository.map.name_map.get_mut(first);
if let Some(rule) = local_included_rule.cloned() {
pattern_id = RuleFactory::get_compiled_rule_id(
*rule,
......
......@@ -20,13 +20,21 @@ const registry = new vsctm.Registry({
});
registry.loadGrammar('source.makefile').then(grammar => {
const text = `%.o: %.c $(DEPS)
const text = `CC=gcc
CFLAGS=-I.
DEPS = hellomake.h
OBJ = hellomake.o hellofunc.o
%.o: %.c $(DEPS)
\t$(CC) -c -o $@ $< $(CFLAGS)
hellomake: $(OBJ)
\t$(CC) -o $@ $^ $(CFLAGS)
`.split("\n");
let ruleStack = vsctm.INITIAL;
for (let i = 0; i < text.length; i++) {
const line = text[i];
const lineTokens = grammar.tokenizeLine(line, ruleStack);
console.log(grammar._ruleId2desc.length);
for (let j = 0; j < lineTokens.tokens.length; j++) {
const token = lineTokens.tokens[j];
console.log(` - token from ${token.startIndex} to ${token.endIndex} ` +
......
......@@ -924,7 +924,6 @@ function matchRule(grammar, lineText, isFirstLine, linePos, stack, anchorPositio
captureIndices: r.captureIndices,
matchedRuleId: ruleScanner.rules[r.index]
};
console.log(result);
return result;
}
return null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册