public override void Validate(RuleSpec rule, LexerSpec lexer)
 {
     if (!lexer.Modes.Contains(Mode))
     {
         throw new Exception($"Rule '{rule.Name}' references mode not in lexer spec: '{Mode}'");
     }
 }
Exemplo n.º 2
0
 public override void Validate(RuleSpec rule, LexerSpec lexer)
 {
     if (!lexer.Channels.Contains(Channel))
     {
         throw new Exception($"Rule '{rule.Name}' references channel not in lexer spec: '{Channel}'");
     }
 }
Exemplo n.º 3
0
		protected override IEnumerable<TData> ApplyImpl(TData input, TOffset start)
		{
			var results = new List<TData>();
			foreach (Match<TData, TOffset> match in Matcher.AllMatches(input, start))
				results.Add(RuleSpec.ApplyRhs(this, match));
			return results;
		}
        public override IEnumerable <Word> Apply(Word input)
        {
            bool applied = false;
            Match <Word, ShapeNode> targetMatch = Matcher.Match(input);

            while (targetMatch.Success)
            {
                ShapeNode start;
                PhonologicalSubruleMatch srMatch;
                if (RuleSpec.MatchSubrule(this, targetMatch, out srMatch))
                {
                    srMatch.SubruleSpec.ApplyRhs(targetMatch, srMatch.Range, srMatch.VariableBindings);
                    applied = true;
                    start   = targetMatch.Range.GetEnd(Matcher.Direction).GetNext(Matcher.Direction);
                }
                else
                {
                    start = targetMatch.Range.GetStart(Matcher.Direction).GetNext(Matcher.Direction);
                }

                if (start == null)
                {
                    break;
                }

                targetMatch = Matcher.Match(input, start);
            }

            if (applied)
            {
                input.ResetDirty();
                return(input.ToEnumerable());
            }
            return(Enumerable.Empty <Word>());
        }
        public override void Validate(RuleSpec rule, LexerSpec lexer)
        {
            if(!lexer.Rules.Contains(TokenType))
                throw new Exception($"Rule '{rule.Name}' references type not in lexer spec: '{TokenType}'");

            if(lexer.Rules[TokenType].IsFragment)
                throw new Exception($"Rule '{rule.Name}' references fragment for token type: '{TokenType}'");
        }
Exemplo n.º 6
0
        protected override IEnumerable <TData> ApplyImpl(TData input, TOffset start)
        {
            TData data = input;

            foreach (Match <TData, TOffset> match in Matcher.AllMatches(input, start).ToArray())
            {
                RuleSpec.ApplyRhs(this, match, out data);
            }
            return(data.ToEnumerable());
        }
Exemplo n.º 7
0
        public RuleGroupSpec AddRule(Action <IStartRuleSpec> configAction)
        {
            Guard.NotNull(() => configAction, configAction);

            var spec = new RuleSpec(this.Name());

            configAction(spec);

            this.commands.Add(new AddRuleCommand(spec));

            return(this);
        }
Exemplo n.º 8
0
        protected override IEnumerable <TData> ApplyImpl(TData input, TOffset start)
        {
            var results = new List <TData>();

            foreach (Match <TData, TOffset> match in Matcher.AllMatches(input, start))
            {
                TData outputData;
                RuleSpec.ApplyRhs(this, match, out outputData);
                results.Add(outputData);
            }
            return(results);
        }
Exemplo n.º 9
0
        public override void Validate(RuleSpec rule, LexerSpec lexer)
        {
            if (!lexer.Rules.Contains(TokenType))
            {
                throw new Exception($"Rule '{rule.Name}' references type not in lexer spec: '{TokenType}'");
            }

            if (lexer.Rules[TokenType].IsFragment)
            {
                throw new Exception($"Rule '{rule.Name}' references fragment for token type: '{TokenType}'");
            }
        }
Exemplo n.º 10
0
            public static RuleSpec recognizeDaySpec(string p)
            {
                RuleSpec rs = null;

                string[] sp = p.Split('-');
                if (sp.Length == 4)
                {
                    rs = new RuleSpec();
                    int.TryParse(sp[0], out rs.Month);
                    int.TryParse(sp[1], out rs.WeekOfMonth);
                    int.TryParse(sp[2], out rs.DayOfWeek);
                    int.TryParse(sp[3], out rs.Hour);
                }
                return(rs);
            }
Exemplo n.º 11
0
        protected override IEnumerable <TData> ApplyImpl(TData input, TOffset start)
        {
            bool  applied = false;
            TData data    = input;
            Match <TData, TOffset> match = Matcher.Match(input, start);

            while (match.Success)
            {
                TOffset nextOffset = RuleSpec.ApplyRhs(this, match, out data);
                applied = true;
                match   = Matcher.Match(data, nextOffset);
            }

            if (applied)
            {
                return(data.ToEnumerable());
            }
            return(Enumerable.Empty <TData>());
        }
 public override void Validate(RuleSpec rule, LexerSpec lexer)
 {
     if(!lexer.Modes.Contains(Mode))
         throw new Exception($"Rule '{rule.Name}' references mode not in lexer spec: '{Mode}'");
 }
 public override void Validate(RuleSpec rule, LexerSpec lexer)
 {
     if(!lexer.Channels.Contains(Channel))
         throw new Exception($"Rule '{rule.Name}' references channel not in lexer spec: '{Channel}'");
 }
Exemplo n.º 14
0
        public AddRuleCommand(RuleSpec ruleSpec)
        {
            Guard.NotNull(() => ruleSpec, ruleSpec);

            this.ruleSpec = ruleSpec;
        }