Exemplo n.º 1
0
 /// <summary>
 /// Decorates given parser rule with all necessary global parser rules.
 /// </summary>
 /// <param name="rule">Parser rule to decorate</param>
 /// <returns>Given parser rule decorated with all necessary global rules.</returns>
 private IParserRule <TToken> DecorateWithGlobalRules(IParserRule <TToken> rule)
 {
     return
         (ExcludedGlobalRules == AllGlobalRules
             ? rule
             : new GlobalRulesDecoratorRule <TToken>(rule, ExcludedGlobalRules));
 }
 public SidesOrNoSidesRule(
     IParserRule <IBuildConflict> sidesDefinedFollowUpRule,
     IParserRule <IBuildConflict> noSidesDefinedFollowUpRule)
 {
     this.sidesDefinedFollowUpRule   = sidesDefinedFollowUpRule;
     this.noSidesDefinedFollowUpRule = noSidesDefinedFollowUpRule;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Extracts underlying parser rule from the given decorator.
        /// </summary>
        /// <param name="rule">Potential decorator rule</param>
        /// <returns>Underlying parser rule or original rule, if given rule is not decorated.</returns>
        public static IParserRule <TToken> Unwrap(IParserRule <TToken> rule)
        {
            var decoratedRule = rule as GlobalRulesDecoratorRule <TToken>;

            return
                (decoratedRule == null
                    ? rule
                    : decoratedRule.rule);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Intializes a new instance of the <see cref="GlobalRulesDecoratorRule{TToken}"/> class
        /// with the provided underlying rule and collection of excluded global rules.
        /// </summary>
        /// <param name="rule">Underlying parser rule</param>
        /// <param name="excludedGlobalRules">Set of excluded global rules</param>
        public GlobalRulesDecoratorRule(
            IParserRule <TToken> rule,
            ISet <string> excludedGlobalRules)
        {
            this.rule =
                rule ?? throw new ArgumentNullException(nameof(rule));

            this.excludedGlobalRules = excludedGlobalRules;
        }
Exemplo n.º 5
0
 public ParserNode(TagType tagType, int startPosition, int endPosition, IParserRule rule)
 {
     childs                 = new List <ParserNode>();
     TypeTag                = tagType;
     StartPosition          = startPosition;
     EndPosition            = endPosition;
     StartInnerPartPosition = startPosition + rule.OpenTag.Length;
     EndInnerPartPosition   = endPosition - rule.CloseTag.Length;
     attributes             = new Dictionary <string, string>();
 }
Exemplo n.º 6
0
 /// <summary>
 /// Adds a parser rule to the grammar.
 /// </summary>
 /// <param name="rule">Instance of the parser rule implementation</param>
 /// <param name="isGlobal">Flag that indicates whether parser rule is global</param>
 public void AddRule(IParserRule <TToken> rule, bool isGlobal = false)
 {
     if (isGlobal)
     {
         globalRules[rule.RuleName] = rule;
         globalRulesCache           = null;
     }
     else
     {
         rules[rule.RuleName] = rule;
     }
 }
        public SplitByDashIntoSeparateSides(IParserRule <IBuildSide> followUpRule)
        {
            Argument.AssertIsNotNull(followUpRule, nameof(followUpRule));

            this.followUpRule = followUpRule;
        }
        public RemoveNumericBlocksAtTheEndRule(IParserRule <IBuildConflict> followUpRule)
        {
            Argument.AssertIsNotNull(followUpRule, nameof(followUpRule));

            this.followUpRule = followUpRule;
        }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OneOrMoreTimesRule{TToken}"/> class
 /// with the provided parser rule.
 /// </summary>
 /// <param name="rule">Parser rule to match</param>
 public OneOrMoreTimesRule(IParserRule <TToken> rule)
     : base(rule)
 {
 }
Exemplo n.º 10
0
 public TemplateParser(Dictionary <char, IParserRule> parseRules, IParserRule fallbackRule, IMessageHandler messageHandler)
 {
     this.ParseRules     = parseRules;
     this.FallbackRule   = fallbackRule;
     this.MessageHandler = messageHandler;
 }
 public TemplateParser(Dictionary<char, IParserRule> parseRules, IParserRule fallbackRule, IMessageHandler messageHandler)
 {
     this.parseRules = parseRules;
     this.fallbackRule = fallbackRule;
     this.messageHandler = messageHandler;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OptionalRule{TToken}"/> class
 /// with the provided parser rule.
 /// </summary>
 /// <param name="rule">Parser rule to match</param>
 public OptionalRule(IParserRule <TToken> rule)
 {
     this.rule = rule ?? throw new ArgumentNullException(nameof(rule));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Creates logical parser rule that matches one or more occurences of the given rule.
 /// </summary>
 /// <param name="rule">Parser rule to match</param>
 /// <returns>New parser rule that implements one-or-more-times logic.</returns>
 protected IParserRule <TToken> OneOrMoreTimes(IParserRule <TToken> rule)
 {
     return(new OneOrMoreTimesRule <TToken>(rule));
 }
Exemplo n.º 14
0
 /// <summary>
 /// Creates logical parser rule that matches given rule zero or one time, making it optional.
 /// </summary>
 /// <param name="rule">Parser rule to match</param>
 /// <returns>New parser rule that implements optional match logic.</returns>
 protected IParserRule <TToken> Optional(IParserRule <TToken> rule)
 {
     return(new OptionalRule <TToken>(rule));
 }
Exemplo n.º 15
0
 /// <summary>
 /// Checks, if specified global <paramref name="rule"/> should be included in matching.
 /// </summary>
 /// <param name="rule">Global rule to check</param>
 /// <returns>true if rule should be included, otherwise false.</returns>
 private bool IsIncludedGlobalRule(IParserRule <TToken> rule)
 {
     return(!excludedGlobalRules.Contains(rule.RuleName));
 }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RepetitiveRuleBase{TToken}"/> class
 /// with the provided parser rule.
 /// </summary>
 /// <param name="rule">Parser rule to match</param>
 public RepetitiveRuleBase(IParserRule <TToken> rule)
 {
     Rule = rule ?? throw new ArgumentNullException(nameof(rule));
 }