void LinkSemanticFunctions(PegNode n) { Debug.Assert(n.id_ == (int)EPegGrammar.rule_ref); string semanticFunction = n.GetAsString(normalizeTree_.c_.src_); if (normalizeTree_.setRules_.Contains(semanticFunction)) return; //was a rule reference PegNode method; bool isLocal; PegNode semBlock = normalizeTree_.FindSemanticBlock(FindSemanticFunctionInTree, semanticFunction, n, out method, out isLocal); if (semBlock != null) { var semanticFuncWithContext = new NormalizeTree.SemanticVarOrFuncWithContext((int)EPegGeneratorNodes.SemanticFunctionWithContext, semBlock, method, n, isLocal); normalizeTree_.c_.semanticInfoNodes_.Add(method); PUtils.ReplaceNode(n, semanticFuncWithContext); } else { normalizeTree_.c_.errOut_.WriteLine(normalizeTree_.c_.sErrorPrefix + "ERROR: no rule found and no semantic function <" + semanticFunction + "> found in semantic block candidates"); normalizeTree_.bOk_ = false; } }
void LinkIntoVariables(PegNode n) { Debug.Assert(n.id_ == (int)EPegGrammar.into_variable); string intoVariable = n.GetAsString(c_.src_); PegNode variable; bool isLocal; PegNode semBlock = FindSemanticBlock(FindIntoVariableInTree, intoVariable, n, out variable, out isLocal); if (semBlock != null) { var intoVarWithContext = new NormalizeTree.SemanticVarOrFuncWithContext((int)EPegGeneratorNodes.IntoVarWithContext, semBlock, variable, n, isLocal); c_.semanticInfoNodes_.Add(variable); PUtils.ReplaceNode(n, intoVarWithContext); Debug.Assert(intoVarWithContext.parent_ != null); if (intoVarWithContext.parent_.id_ == (int)EPegGrammar.lower_limit && intoVarWithContext.parent_.parent_.id_ == (int)EPegGrammar.repetition_range) { var r = intoVarWithContext.parent_.parent_ as PegGrammarParser.TRange; Debug.Assert(r != null); r.lowerIntoVar = intoVarWithContext; } else if (intoVarWithContext.parent_.id_ == (int)EPegGrammar.upper_limit && intoVarWithContext.parent_.parent_.id_ == (int)EPegGrammar.repetition_range) { var r = intoVarWithContext.parent_.parent_ as PegGrammarParser.TRange; Debug.Assert(r != null); r.upperIntoVar = intoVarWithContext; } } else { c_.errOut_.WriteLine(c_.sErrorPrefix + "ERROR: into variable <" + intoVariable + "> not found in semantic block candidates"); bOk_ = false; } }