Adds the necessary rules to the digester to parse our classes.
335356
@Override
    public void addRuleInstances (Digester digester)
    {
        // this creates the appropriate instance when we encounter a
        // <class> tag
        digester.addObjectCreate(_prefix + CLASS_PATH,
                                 ComponentClass.class.getName());

        // grab the attributes from the <class> tag
        SetPropertyFieldsRule rule = new SetPropertyFieldsRule();
        rule.addFieldParser("shadowColor", new FieldParser() {
            public Object parse (String text) {
                int[] values = StringUtil.parseIntArray(text);
                return new Color(values[0], values[1], values[2], values[3]);
            }
        });
        digester.addRule(_prefix + CLASS_PATH, rule);

        // parse render priority overrides
        String opath = _prefix + CLASS_PATH + "/override";
        digester.addObjectCreate(opath, PriorityOverride.class.getName());
        rule = new SetPropertyFieldsRule();
        rule.addFieldParser("orients", new FieldParser() {
            public Object parse (String text) {
                String[] orients = StringUtil.parseStringArray(text);
                ArrayIntSet oset = new ArrayIntSet();
                for (String orient : orients) {
                    oset.add(DirectionUtil.fromShortString(orient));
                }
                return oset;
            }
        });
        digester.addRule(opath, rule);

        digester.addSetNext(opath, "addPriorityOverride",
                            PriorityOverride.class.getName());
    }
990020
def addRule( self, rule ):
        
        self._rules[rule.term()] = rule
        self.updateRules()
1253548
public function setupRules()
    {
        // we need to allow all the tokens in json
        $this->rules->validator = new Validator(['*none', '*meta.json', '!comment']);

        $this->rules->addMany([
            'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], [
                'context' => ['!operator.escape', '!comment', '!string'],
            ]),

            'symbol.function' => new Rule(new RegexMatcher('/function\s+([a-z_]\w+)\s*\(/i')),

            'operator.escape' => new Rule(new RegexMatcher('/(\\\(?:x[0-9a-fA-F]{1,2}|u\{[0-9a-fA-F]{1,6}\}|[0-7]{1,3}|.))/i'), [
                'context' => ['string']
            ]),

            'comment' => new Rule(new CommentMatcher(['//'], [['/*', '*/']]), ['priority' => 3]),

            'call' => new Rule(new RegexMatcher('/(' . self::IDENTIFIER . ')\s*\(/iu'), ['priority' => -1]),

            'keyword' => new Rule(new WordMatcher([
                'do', 'if', 'in', 'for', 'let', 'new', 'try', 'var', 'case', 'else', 'enum', 'eval',
                'void', 'with', 'break', 'catch', 'class', 'const', 'super', 'throw',
                'while', 'yield', 'delete', 'export', 'import', 'public', 'return', 'static', 'switch',
                'typeof', 'default', 'extends', 'finally', 'package', 'private', 'continue', 'debugger',
                'function', 'arguments', 'interface', 'protected', 'implements', 'instanceof', 'get', 'set', 'from'
            ]), ['context' => ['!string', '!comment', '!symbol', '!call']]),

            'constant.special' => new Rule(new WordMatcher(['null', 'true', 'false'])),
            'variable.special' => new Rule(new SubStringMatcher('this')),

            'number' => new Rule(new RegexMatcher('/\b(-?(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\d+))\b/')),

            'operator.punctuation' => new Rule(new WordMatcher([',', ';'], ['separated' => false]), ['priority' => 0]),
            'operator'             => new Rule(new RegexMatcher('/(=>|\+{1,2}|-{1,2}|={1,3}|\|{1,2}|&{1,2})/'), ['priority' => 0]),

            'string.regex' => [
                new OpenRule(new RegexMatcher('#(?>[\[=(?:+,!]|^|return|=>|&&|\|\|)\s*(/).*?/#m'), [
                    'context' => ['!comment', '!string']
                ]),
                new Rule(new RegexMatcher('#\/.*(/[gimuy]{0,5})#m'), [
                    'priority' => 1,
                    'factory'  => new TokenFactory(ContextualToken::class),
                    'context'  => ['!operator.escape', 'string.regex']
                ])
            ],

            'variable' => new Rule(new RegexMatcher('/\b(?<!\.)(' . self::IDENTIFIER . ':?)/iu'), [
                'priority' => -1,
                'enabled'  => $this->variables
            ]),

            'variable.property' => [
                new Rule(new RegexMatcher('/(?=[\w)\]]\s*\.([a-z_]\w*))/i'), [
                    'priority' => -2
                ]),
                new Rule(new RegexMatcher('/(\w+)\s*:/si'), [
                    'context' => ['meta.json', '!comment', '!string']
                ]),
            ],

            'meta.json' => new Rule(new RegexMatcher('/(?<=[=(,])\s*(\{(?>[^{}]|(?1))+\})/m'), [
                'factory' => new TokenFactory(MetaToken::class)
            ])
        ]);
    }
896352
protected void addProjectRules(Digester digester, String xpath) {

        digester.addCallMethod(xpath + N_NAME, "setProjectName", 0);
        digester.addCallMethod(xpath + N_DESCRIPTION, "setProjectDescription", 0);
        digester.addCallMethod(xpath + N_MANAGERSGROUP, "setProjectManagers", 0);
        digester.addCallMethod(xpath + N_USERSGROUP, "setProjectUsers", 0);
        digester.addCallMethod(xpath + N_RESOURCES + "/" + N_RESOURCE, "addProjectResource", 0);
        digester.addCallMethod(xpath + N_RESOURCES, "importProject");
    }
1014662
def register_rules(self, rules):
    
    if not isinstance(rules, Iterable):
      raise TypeError('The rules must be an iterable, given {!r}'.format(rules))

    # "Index" the rules to normalize them and expand their dependencies.
    normalized_rules = RuleIndex.create(rules).normalized_rules()
    indexed_rules = normalized_rules.rules
    union_rules = normalized_rules.union_rules

    # Store the rules and record their dependency Optionables.
    self._rules.update(indexed_rules)
    self._union_rules.update(union_rules)
    dependency_optionables = {do
                              for rule in indexed_rules
                              for do in rule.dependency_optionables
                              if rule.dependency_optionables}
    self.register_optionables(dependency_optionables)
1079589
public function setupRules()
    {
        parent::setupRules();
        $this->rules->add('symbol', new Rule(new SubStringMatcher('`'), [
            'factory' => new TokenFactory(ContextualToken::class)
        ]));
    }
1039932
public void addRuleInstances (String prefix, Digester dig)
    {
        // this creates the appropriate instance when we encounter our
        // prefix tag
        dig.addRule(prefix, new Rule() {
            @Override
            public void begin (String namespace, String name,
                               Attributes attributes) throws Exception {
                digester.push(createMisoSceneModel());
            }
            @Override
            public void end (String namespace, String name) throws Exception {
                digester.pop();
            }
        });

        // set up rules to parse and set our fields
        dig.addRule(prefix + "/width", new SetFieldRule("width"));
        dig.addRule(prefix + "/height", new SetFieldRule("height"));
        dig.addRule(prefix + "/viewwidth", new SetFieldRule("vwidth"));
        dig.addRule(prefix + "/viewheight", new SetFieldRule("vheight"));
        dig.addRule(prefix + "/base", new SetFieldRule("baseTileIds"));

        dig.addObjectCreate(prefix + "/objects", ArrayList.class.getName());
        dig.addObjectCreate(prefix + "/objects/object",
                            ObjectInfo.class.getName());
        dig.addSetNext(prefix + "/objects/object", "add",
                       Object.class.getName());

        dig.addRule(prefix + "/objects/object", new SetPropertyFieldsRule());

        dig.addRule(prefix + "/objects", new CallMethodSpecialRule() {
            @Override
            public void parseAndSet (String bodyText, Object target)
                throws Exception
            {
                @SuppressWarnings("unchecked") ArrayList<ObjectInfo> ilist =
                    (ArrayList<ObjectInfo>)target;
                ArrayList<ObjectInfo> ulist = Lists.newArrayList();
                SimpleMisoSceneModel model = (SimpleMisoSceneModel)
                    digester.peek(1);

                // filter interesting and uninteresting into two lists
                for (int ii = 0; ii < ilist.size(); ii++) {
                    ObjectInfo info = ilist.get(ii);
                    if (!info.isInteresting()) {
                        ilist.remove(ii--);
                        ulist.add(info);
                    }
                }

                // now populate the model
                SimpleMisoSceneModel.populateObjects(model, ilist, ulist);
            }
        });
    }
383114
public function setupRules()
    {
        $function = '[a-z]\w*[!?]?';
        $this->rules->addMany([
            'comment' => [
                new Rule(new CommentMatcher(['#']), ['context' => ['!string.regex', '!string']]),
                'doc' => [
                    new OpenRule(new RegexMatcher('/^(=begin)/m')),
                    new CloseRule(new RegexMatcher('/^(=end)/m')),
                ]
            ],
            'keyword' => new Rule(new WordMatcher([
                'BEGIN', 'class', 'ensure', 'when', 'END', 'def', 'not', 'super', 'while',
                'alias', 'defined', 'for', 'or', 'then', 'yield', 'and', 'do', 'if', 'redo', 'begin', 'else',
                'in', 'rescue', 'undef', 'break', 'elsif', 'module', 'retry', 'unless', 'case', 'end', 'next', 'return',
                'until',
            ], ['case-sensitivity' => true])),
            'string' => [
                CommonFeatures::strings(
                    ['single' => '\'', 'double' => '"'],
                    ['context' => ['!operator.escape', '!comment', '!string', '!expression']]
                ),
                'generalized' => [
                    // TODO: Generalized strings
                ]
            ],
            'operator.escape' => new Rule(new RegexMatcher('/(\\\.)/'), [
                'context' => ['string']
            ]),
            'constant' => [
                new Rule(new RegexMatcher('/(?:[a-z_])?::([a-z_]\w*)/i')),
                'special' => new Rule(new WordMatcher(['self', 'nil', 'true', 'false', '__FILE__', '__LINE__']))
            ],
            'variable' => [
                'global'   => new Rule(new RegexMatcher('/(?:[^\\\]|^)(\$\w*)/i')),
                'property' => new Rule(new RegexMatcher('/(?:[^\\\]|^)(@{1,2}\w*)/i')),
            ],
            // JS + Perl = Ruby?
            'string.regex' => [
                new OpenRule(new RegexMatcher('#(?>[\[=(?:+,!~]|^|return|=>|&&|\|\|)\s*(/).*?/#sm'), [
                    'context' => ['!comment']
                ]),
                new Rule(new RegexMatcher('#(?=\/.*?(/[mixounse]*))#sm'), [
                    'priority' => 2,
                    'factory'  => new TokenFactory(ContextualToken::class),
                    'context'  => ['!operator.escape', 'string.regex']
                ])
            ],
            'call' => [
                new Rule(new RegexMatcher("/($function)\\s*\\(/i"), ['priority' => 2]),
                new Rule(new RegexMatcher(
                    // fixme: expression handling smth[blah].func
                    "/(?<![^\\\\]\\\\)(?<=\\n|\\{|\\(|\\}|\\|\\||or|&&|and|=|;)\\s*(?:\\w+(?:::|\\.))?($function)(?:[\\h\r]*\$|\\h+['\":\\w])/im"
                ), ['priority' => 0]),
            ],
            'symbol' => [
                'symbol'   => new Rule(new RegexMatcher('/[^\B:](:[a-z_]\w*)/i')),
                'class'    => new Rule(new RegexMatcher('/class\s+([a-z_]\w*)/i')),
                'function' => new Rule(new RegexMatcher('/def\s+(?:\[\]\s*|\*\s*|\w+\.){0,2}([a-z_]\w*)/i')),
            ],
            'expression.in-string' => new Rule(new RegexMatcher('/(?=(\#\{((?>[^\#{}]+|(?1))+)\}))/x'), [
                'context' => ['string.double'],
                'factory' => new TokenFactory(LanguageToken::class),
                'inject'  => $this
            ]),

            'number'    => new Rule(new RegexMatcher('/((?:-|\b)(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\d+))/')),
        ]);
    }
489251
public function setupRules()
    {
        $identifier = '-?[_a-zA-Z]+[_a-zA-Z0-9-]*';
        $at = [
            'charset', 'import', 'namespace',
            'media', 'supports', 'document', 'page', 'font-face', 'keyframes', 'viewport', 'counter-style',
            'font-feature-values', 'swash', 'ornaments', 'annotation', 'stylistic', 'styleset', 'character-variant'
        ];
        
        $this->rules->addMany([
            'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], [
                'context' => $this->everywhere()
            ]),

            'meta.declaration' => [
                new OpenRule(new SubStringMatcher('{'), [
                    'context' => ['!meta.declaration.media', '!comment'],
                    'factory' => new TokenFactory(MetaToken::class)
                ]),
                new CloseRule(new SubStringMatcher('}')),
            ],

            'meta.declaration.media' => [
                new Rule(new RegexMatcher('/@media(.*?\{)/'), [
                    'context' => Validator::everywhere(),
                    'factory' => new TokenFactory(MetaToken::class)
                ]),
            ],

            'meta.declaration.rule' => [
                new OpenRule(new RegexMatcher('/@media.*(\()/'), [
                    'context' => ['meta.declaration.media'],
                    'factory' => new TokenFactory(MetaToken::class)
                ]),
                new CloseRule(new SubStringMatcher(')')),
            ],

            'keyword.at-rule' => new Rule(new RegexMatcher('/(@(?:-[a-z]+-)?(?:'.implode('|', $at).'))/'), [
                'priority' => 2
            ]),

            'symbol.selector.id'    => new Rule(new RegexMatcher("/(#$identifier)/i")),
            'symbol.selector.tag'   => new Rule(new RegexMatcher('/(?>[\s}]|^)(?=(\w+)[^;]*\{)/ms')),
            'symbol.selector.class' => new Rule(new RegexMatcher("/(\\.$identifier)/i")),

            'symbol.selector.class.pseudo' => new Rule(new RegexMatcher("/(:{1,2}$identifier)/")),

            'number' => new Rule(new RegexMatcher("/([-+]?[0-9]*\\.?[0-9]+([\\w%]+)?)/"), [
                'context'  => ['meta.declaration', '!constant.color', '!comment', '!symbol', '!comment', '!string'],
                'priority' => 0
            ]),
            
            'symbol.property' => new Rule(new RegexMatcher("/($identifier:)/"), [
                'context' => ['meta.declaration', '!symbol', '!comment'],
                'priority' => 2
            ]),

            'call' => new Rule(new RegexMatcher("/($identifier)\\s*\\((?:(?P<string>[a-z].*?)|.*?)\\)/", [
                1 => Token::NAME,
                'string' => 'string.argument'
            ]), [
                'context' => ['meta.declaration', '!comment', '!string', '!keyword']
            ]),

            'constant.color' => [
                new Rule(new RegexMatcher("/(#[0-9a-f]{3,6})/i"), [
                    'priority' => 2,
                    'context'  => ['meta.declaration', '!comment']
                ]),
                new Rule(new WordMatcher([
                    'white', 'silver', 'gray', 'black', 'red', 'maroon', 'yellow', 'olive',
                    'lime', 'green', 'aqua', 'teal', 'blue', 'navy', 'fuchsia', 'purple'
                ]), [
                    'context'  => ['meta.declaration', '!comment', '!symbol', '!variable']
                ]),
            ],

            'operator' => new Rule(new WordMatcher(['>', '+', '*', '!important'], ['separated' => false]), [
                'context' => $this->everywhere()
            ]),

            'operator.punctuation' => new Rule(new SubStringMatcher(';'), [
                'context' => $this->everywhere()
            ]),

            'comment' => new Rule(new CommentMatcher([], [['/*', '*/']]), ['context' => $this->everywhere()])
        ]);
    }
700610
private void parse()
    {
        this.elements = new ArrayList<>();

        try {
            for (Tokenizer tokenizer = new Tokenizer(this.rawVersion); tokenizer.next();) {
                Element element = new Element(tokenizer);
                this.elements.add(element);
                if (element.getVersionType() != Type.STABLE) {
                    this.type = element.getVersionType();
                }
            }

            trimPadding(this.elements);
        } catch (Exception e) {
            // Make sure to never fail no matter what
            LOGGER.error("Failed to parse version [" + this.rawVersion + "]", e);
            this.elements.add(new Element(this.rawVersion));
        }
    }
276378
protected void addAccountsUserRules(Digester digester, String xpath) {

        String xp_user = xpath + N_USERS + "/" + N_USER + "/";
        digester.addCallMethod(xp_user + N_NAME, "setUserName", 0);
        digester.addCallMethod(xp_user + N_PASSWORD, "setUserPassword", 0);
        digester.addCallMethod(xp_user + N_FIRSTNAME, "setUserFirstname", 0);
        digester.addCallMethod(xp_user + N_LASTNAME, "setUserLastname", 0);
        digester.addCallMethod(xp_user + N_EMAIL, "setUserEmail", 0);
        digester.addCallMethod(xp_user + N_FLAGS, "setUserFlags", 0);
        digester.addCallMethod(xp_user + N_DATECREATED, "setUserDateCreated", 0);
        digester.addCallMethod(xp_user + N_USERINFO, "importUser");

        String xp_info = xp_user + N_USERINFO + "/" + N_USERINFO_ENTRY;
        digester.addCallMethod(xp_info, "importUserInfo", 3);
        digester.addCallParam(xp_info, 0, A_NAME);
        digester.addCallParam(xp_info, 1, A_TYPE);
        digester.addCallParam(xp_info, 2);

        digester.addCallMethod(xp_user + N_USERROLES + "/" + N_USERROLE, "importUserRole", 0);
        digester.addCallMethod(xp_user + N_USERGROUPS + "/" + N_USERGROUP, "importUserGroup", 0);
    }
598753
public static void addParsers(final List<AbstractWarningsParser> parsers) {
        parsers.add(new ViolationsAdapter(new CodenarcParser(),
                Messages._Warnings_Codenarc_ParserName(),
                Messages._Warnings_Codenarc_LinkName(),
                Messages._Warnings_Codenarc_TrendName()));
        parsers.add(new ViolationsAdapter(new CssLintParser(),
                Messages._Warnings_CssLint_ParserName(),
                Messages._Warnings_CssLint_LinkName(),
                Messages._Warnings_CssLint_TrendName()));
        parsers.add(new ViolationsAdapter(new GendarmeParser(),
                Messages._Warnings_Gendarme_ParserName(),
                Messages._Warnings_Gendarme_LinkName(),
                Messages._Warnings_Gendarme_TrendName()));
        parsers.add(new ViolationsAdapter(new JcReportParser(),
                Messages._Warnings_JCReport_ParserName(),
                Messages._Warnings_JCReport_LinkName(),
                Messages._Warnings_JCReport_TrendName()));
        parsers.add(new ViolationsAdapter(new Pep8Parser(),
                Messages._Warnings_Pep8_ParserName(),
                Messages._Warnings_Pep8_LinkName(),
                Messages._Warnings_Pep8_TrendName()));
    }
967872
def parse(scanner, rules, scope = ParserScope.empty)
      (rule = rules[rule_name]) && rule.parse(scanner, rules, scope)
    end
383849
public function setupRules()
    {
        $this->rules->addMany([
            'number.status'   => new Rule(new RegexMatcher('/^HTTP\/.+\s(\d+)/')),
            'constant.status' => new Rule(new RegexMatcher('/^HTTP\/.+\s+\d+\s+(.+?)\R/')),

            'call.method' => new Rule(new RegexMatcher('/^(\w+).*HTTP\//')),
            'string.path' => new Rule(new RegexMatcher('/^\w+\s(.*?)\sHTTP\//')),

            'symbol.version' => new Rule(new RegexMatcher('/^.*(HTTP\/\S+)/')),

            'symbol.header' => new Rule(new RegexMatcher('/^([\w-]+:)/m')),
        ]);
    }
476430
private function parseClass()
    {
        $parser = new Parser();
        $parsedApi = $parser->parseApi($this->class, $this->normalize);

        // in development we always write cache
        $writer = new Compiler($this->api, $this->normalize, $this->cacheInstance);
        $writer->writeCacheFiles($parsedApi);
    }
124031
def load_rules(self):
        
        self.col_maps = []
        #print("reading mapping table")
        with open(self.col_file, 'r') as f:
            for line in f:
                rule = MapColumn(line)
                #rule = line
                self.col_maps.append(rule)
1156366
public function setupRules()
    {
        $this->rules->addMany([
            'tag.open'  => [
                new OpenRule(new RegexMatcher('/(<[\w\.-]+)[:\/>:\s]/')),
                new CloseRule(new SubStringMatcher('>'), ['context' => ['!string', '!comment']])
            ],
            'tag.close' => new Rule(new RegexMatcher('/(<\/' . self::IDENTIFIER . '>)/')),

            'symbol.tag' => new Rule(new RegexMatcher('/<\\/?' . self::IDENTIFIER . '/', [
                'name'      => Token::NAME,
                'namespace' => '$.namespace'
            ]), ['context' => ['tag', '!string']]),

            'symbol.attribute' => new Rule(new RegexMatcher('/' . self::IDENTIFIER . '=/', [
                'name'      => Token::NAME,
                'namespace' => '$.namespace'
            ]), ['context' => ['tag', '!string']]),

            'constant.entity' => new Rule(new RegexMatcher('/(&(?:\#\d+|[a-z])+;)/si')),

            'comment' => new Rule(new CommentMatcher(null, [['<!--', '-->']])),
            'string'  => CommonFeatures::strings(['single' => '\'', 'double' => '"'], ['context' => ['tag']]),
        ]);
    }