protected BnfiTermCopy(Type domainType, BnfTerm bnfTerm, string name) : base(domainType, name: name ?? GetName(domainType, bnfTerm)) { if (bnfTerm != null) { // "this" BnfiTermCopy is not an independent bnfTerm, just a syntax magic for BnfiTermRecord<TType> (we were called by the Copy method) this.IsContractible = true; this.RuleRaw = bnfTerm.ToBnfExpression() + GrammarHelper.ReduceHere(); } else { // "this" BnfiTermCopy is an independent bnfTerm this.IsContractible = false; } GrammarHelper.MarkTransientForced(this); // default "transient" behavior (the Rule of this BnfiTermCopyable will contain the BnfiTerm... which actually does something) }
protected BnfiTermConversion(Type domainType, BnfTerm bnfTerm, ValueIntroducer <object> valueIntroducer, ValueConverter <object, object> inverseValueConverterForUnparse, object defaultValue, bool isOptionalValue, string name, bool astForChild) : base(domainType, name) { this.IsContractible = true; this.bnfTerm = bnfTerm; this.isOptionalValue = isOptionalValue; this.defaultValue = defaultValue; if (!astForChild) { bnfTerm.SetFlag(TermFlags.NoAstNode); } this.RuleRawWithMove = isOptionalValue ? GrammarHelper.PreferShiftHere() + bnfTerm | Irony.Parsing.Grammar.CurrentGrammar.Empty : bnfTerm.ToBnfExpression(); this.AstConfig.NodeCreator = (context, parseTreeNode) => { try { parseTreeNode.AstNode = GrammarHelper.ValueToAstNode(valueIntroducer(context, new ParseTreeNodeWithoutAst(parseTreeNode)), context, parseTreeNode); } catch (AstException e) { context.AddMessage(AstException.ErrorLevel, parseTreeNode.Span.Location, e.Message); } catch (FatalAstException e) { context.AddMessage(FatalAstException.ErrorLevel, parseTreeNode.Span.Location, e.Message); // although it will be abandoned anyway e.Location = parseTreeNode.Span.Location; throw; // handle in MultiParser } }; this.inverseValueConverterForUnparse = inverseValueConverterForUnparse; }
protected BnfiExpression(BnfTerm bnfTerm) { this.bnfExpression = bnfTerm.ToBnfExpression(); }
protected BnfiTermNoAst(BnfTerm bnfTerm, ValueCreatorFromNoAst <object> valueCreatorFromNoAst) : this(string.Format("{0}->no_ast", bnfTerm.Name)) { base.Rule = bnfTerm.ToBnfExpression(); this.valueCreatorFromNoAst = valueCreatorFromNoAst; }