refactor: try to fix last issues

上级 f0d9a11f
...@@ -155,7 +155,6 @@ impl Grammar { ...@@ -155,7 +155,6 @@ impl Grammar {
let stack = &mut next_state.clone().unwrap(); let stack = &mut next_state.clone().unwrap();
let vec = line_tokens.get_result(stack, line_length as i32); let vec = line_tokens.get_result(stack, line_length as i32);
TokenizeResult { TokenizeResult {
// line_length,
tokens: vec, tokens: vec,
rule_stack: Box::new(next_state.clone()), rule_stack: Box::new(next_state.clone()),
} }
...@@ -764,11 +763,11 @@ hellomake: $(OBJ) ...@@ -764,11 +763,11 @@ hellomake: $(OBJ)
for token in result.tokens { for token in result.tokens {
let start = token.start_index.clone() as usize; let start = token.start_index.clone() as usize;
let end = token.end_index.clone() as usize; let end = token.end_index.clone() as usize;
// let new_line: String = String::from(line) let new_line: String = String::from(line)
// .chars() .chars()
// .skip(start) .skip(start)
// .take(end - start) .take(end - start)
// .collect(); .collect();
let token_str: String = token.scopes.join(", "); let token_str: String = token.scopes.join(", ");
println!( println!(
" - token from {:?} to {:?} ({:?}) with scopes {:?}", " - token from {:?} to {:?} ({:?}) with scopes {:?}",
......
...@@ -64,11 +64,12 @@ impl LineTokens { ...@@ -64,11 +64,12 @@ impl LineTokens {
self._tokens.pop(); self._tokens.pop();
} }
let tokens_len = self._tokens.len(); if self._tokens.len() == 0 {
if tokens_len == 0 {
self._last_token_end_index = -1; self._last_token_end_index = -1;
self.produce(stack, line_length); self.produce(stack, line_length);
self._tokens[tokens_len - 1].start_index = 0;
let new_tokens_len = self._tokens.len();
self._tokens[new_tokens_len - 1].start_index = 0;
} }
self._tokens.clone() self._tokens.clone()
......
...@@ -167,7 +167,7 @@ impl RuleFactory { ...@@ -167,7 +167,7 @@ impl RuleFactory {
if rule.has_missing_pattern() && rule.patterns_length() == 0 { if rule.has_missing_pattern() && rule.patterns_length() == 0 {
match rule.get_rule_instance() { match rule.get_rule_instance() {
RuleEnum::BeginEndRule(r) => { RuleEnum::BeginEndRule(r) => {
println!("{:?}", r); println!("missing patterns -> {:?}", r);
} }
_ => {} _ => {}
} }
......
...@@ -21,12 +21,13 @@ const registry = new vsctm.Registry({ ...@@ -21,12 +21,13 @@ const registry = new vsctm.Registry({
createOnigString: (str) => new oniguruma.OnigString(str) createOnigString: (str) => new oniguruma.OnigString(str)
}), }),
loadGrammar: (scopeName) => { loadGrammar: (scopeName) => {
return readFile('./syntaxes/json/c.json').then(data => vsctm.parseRawGrammar(data.toString(), "c.json")) return readFile('./syntaxes/json/makefile.json').then(data => vsctm.parseRawGrammar(data.toString(), "c.json"))
} }
}); });
registry.loadGrammar('source.c').then(grammar => { registry.loadGrammar('source.makefile').then(grammar => {
const text = `#include <stdio.h>`.split("\n"); const text = `hellomake: $(OBJ)
\t$(CC) -o $@ $^ $(CFLAGS)`.split("\n");
let ruleStack = vsctm.INITIAL; let ruleStack = vsctm.INITIAL;
for (let i = 0; i < text.length; i++) { for (let i = 0; i < text.length; i++) {
const line = text[i]; const line = text[i];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册