Ejemplo n.º 1
0
        private void initializeRules()
        {
            var thisType = this.GetType();

            var fields = thisType.GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).Where(x => x.IsDefined(typeof(RuleAttribute), false));


            // init lexer:
            var lexrules      = new List <Lexrule>();
            var lexrulesProps = fields.Where(x => x.FieldType == typeof(Lexrule));

            foreach (var item in lexrulesProps)
            {
                var at     = item.GetCustomAttributes(typeof(RuleAttribute), false)[0] as RuleAttribute;
                var skipat = item.GetCustomAttributes(typeof(SkipAttribute), false).FirstOrDefault();
                var lr     = new Lexrule(item.Name, skipat != null, at.pattern);
                lr.createNode = at.createNode;
                lexrules.Add(lr);
                item.SetValue(this, lr);
            }
            lexer = new Lexer(lexrules);


            // init parserules:
            var parserulesProps = fields.Where(x => x.FieldType == typeof(Parserule));

            foreach (var item in parserulesProps)
            {
                var at   = item.GetCustomAttributes(typeof(RuleAttribute), false)[0] as RuleAttribute;
                var rule = new Parserule(item.Name, at.pattern);
                rule.createNode = at.createNode;
                parserules.Add(rule);
                item.SetValue(this, rule);
            }

            foreach (var item in parserules)
            {
                item.Initialize(this);
            }
        }
Ejemplo n.º 2
0
 public Pattern(Parserule rule, IRule[] rules)
 {
     this.rule  = rule;
     this.rules = rules;
 }