public override FGGrammar.IScanner MoveAfterLeaf(ParseTree.Leaf leaf) { var scanner = new CsGrammar.Scanner(CsGrammar.Instance, textBuffer.formatedLines, assetPath); return(leaf == null ? scanner : scanner.MoveAfterLeaf(leaf) ? scanner : null); }
public override bool ParseLines(int fromLine, int toLineInclusive) { var formatedLines = textBuffer.formatedLines; for (var line = Math.Max(0, fromLine); line <= toLineInclusive; ++line) { var tokens = formatedLines[line].tokens; for (var i = tokens.Count; i-- > 0;) { var t = tokens[i]; //if (t.parent != null) //{ // //t.parent.line = line; // t.parent.tokenIndex = i; //} /*if (t.tokenKind == SyntaxToken.Kind.ContextualKeyword) * { * t.tokenKind = SyntaxToken.Kind.Identifier; * t.style = textBuffer.styles.normalStyle; * } * else*/if (t.tokenKind == SyntaxToken.Kind.Missing) { if (t.parent != null && t.parent.parent != null) { t.parent.parent.syntaxError = null; } tokens.RemoveAt(i); } } } var scanner = new CsGrammar.Scanner(CsGrammar.Instance, formatedLines, assetPath); //CsGrammar.Instance.ParseAll(scanner); scanner.MoveToLine(fromLine, parseTree); // if (scanner.CurrentGrammarNode == null) // { // if (!scanner.MoveNext()) // return false; // FGGrammar.Rule startRule = CsGrammar.Instance.r_compilationUnit; //// if (parseTree == null) //// { //// parseTree = new ParseTree(); //// var rootId = new Id(startRule.GetNt()); //// ids[Start.GetNt()] = startRule; //// rootId.SetLookahead(this); //// Start.parent = rootId; // scanner.CurrentParseTreeNode = parseTree.root;// = new ParseTree.Node(rootId); // scanner.CurrentGrammarNode = startRule;//.Parse(scanner); // scanner.ErrorParseTreeNode = scanner.CurrentParseTreeNode; // scanner.ErrorGrammarNode = scanner.CurrentGrammarNode; // //} // } //Debug.Log("Parsing line " + (fromLine + 1) + " starting from " + scanner.CurrentLine() + ", token " + scanner.CurrentTokenIndex() + " currentToken " + scanner.Current); var grammar = CsGrammar.Instance; var canContinue = true; for (var line = Math.Max(0, scanner.CurrentLine() - 1); canContinue && line <= toLineInclusive; line = scanner.CurrentLine() - 1) { canContinue = grammar.ParseLine(scanner, line); } //if (!(canContinue = grammar.ParseLine(scanner, line))) // if (scanner.Current.tokenKind != SyntaxToken.Kind.EOF) // Debug.Log("can't continue at line " + (line + 1) + " token " + scanner.Current); if (canContinue && toLineInclusive == formatedLines.Length - 1) { canContinue = grammar.GetParser.ParseStep(scanner); } //Debug.Log("canContinue == " + canContinue); for (var line = fromLine; line <= toLineInclusive; ++line) { foreach (var t in formatedLines[line].tokens) { if (t.tokenKind == SyntaxToken.Kind.ContextualKeyword) { t.style = t.text == "value" ? textBuffer.styles.parameterStyle : textBuffer.styles.keywordStyle; } } } return(canContinue); //return true; }
protected override void ParseAll(string bufferName) { var scanner = new CsGrammar.Scanner(CsGrammar.Instance, textBuffer.formatedLines, bufferName); parseTree = CsGrammar.Instance.ParseAll(scanner); }