Ejemplo n.º 1
0
 public static BnfiTermConversion <T> Intro <T>(Terminal terminal, ValueIntroducer <T> valueIntroducer, ValueConverter <T, object> inverseValueConverterForUnparse, bool astForChild = true)
 {
     return(new BnfiTermConversion <T>(
                terminal,
                (context, parseNode) => valueIntroducer(context, parseNode),
                inverseValueConverterForUnparse,
                defaultValue: default(T),
                isOptionalValue: false,
                name: terminal.Name + "_introAs_" + typeof(T).Name.ToLower(),
                astForChild: astForChild
                )
            .MakeUncontractible());
 }
Ejemplo n.º 2
0
 public static BnfiTermConversionTL Intro(Type domainType, Terminal terminal, ValueIntroducer <object> valueIntroducer, ValueConverter <object, object> inverseValueConverterForUnparse, bool astForChild = true)
 {
     return(new BnfiTermConversionTL(
                domainType,
                terminal,
                (context, parseNode) => valueIntroducer(context, parseNode),
                inverseValueConverterForUnparse,
                defaultValue: null,
                isOptionalValue: false,
                name: terminal.Name + "_intro",
                astForChild: astForChild
                )
            .MakeUncontractible());
 }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
 protected BnfiTermConversion(Type domainType, BnfTerm bnfTerm, ValueIntroducer <object> valueIntroducer, object defaultValue, bool isOptionalValue, string name, bool astForChild)
     : this(domainType, bnfTerm, valueIntroducer, NoUnparseByInverse(), defaultValue, isOptionalValue, name, astForChild)
 {
 }
Ejemplo n.º 5
0
 internal BnfiTermConversionTL(Type domainType, BnfTerm bnfTerm, ValueIntroducer <object> valueIntroducer, ValueConverter <object, object> inverseValueConverterForUnparse, object defaultValue, bool isOptionalValue, string name, bool astForChild)
     : base(domainType, bnfTerm, valueIntroducer, inverseValueConverterForUnparse, defaultValue, isOptionalValue, name, astForChild)
 {
 }
Ejemplo n.º 6
0
 public static BnfiTermConversion <T> Intro <T>(Terminal terminal, ValueIntroducer <T> valueIntroducer, bool astForChild = true)
 {
     return(Intro(terminal, valueIntroducer, NoUnparseByInverse <T>(), astForChild));
 }
Ejemplo n.º 7
0
 public static BnfiTermConversionTL Intro(Type domainType, Terminal terminal, ValueIntroducer <object> valueIntroducer, bool astForChild = true)
 {
     return(Intro(domainType, terminal, valueIntroducer, NoUnparseByInverse(), astForChild));
 }
Ejemplo n.º 8
0
 public static BnfiTermConversionTL Intro(Terminal terminal, ValueIntroducer <object> valueIntroducer, ValueConverter <object, object> inverseValueConverterForUnparse, bool astForChild = true)
 {
     return(Intro(typeof(object), terminal, valueIntroducer, inverseValueConverterForUnparse, astForChild));
 }
Ejemplo n.º 9
0
 public static BnfiTermConversion <TDOut> IntroValue <TDOut>(this Terminal terminal, ValueIntroducer <TDOut> valueIntroducer,
                                                             ValueConverter <TDOut, object> inverseValueConverterForUnparse, bool astForChild = true)
 {
     return(BnfiTermConversion.Intro(terminal, valueIntroducer, inverseValueConverterForUnparse, astForChild));
 }
Ejemplo n.º 10
0
 public static BnfiTermConversion <TDOut> IntroValue <TDOut>(this Terminal terminal, ValueIntroducer <TDOut> valueIntroducer, bool astForChild = true)
 {
     return(BnfiTermConversion.Intro(terminal, valueIntroducer, astForChild));
 }