function addRules(state, newrules, rules) {
        for (var idx in rules) {
            if (rules.hasOwnProperty(idx)) {
                var rule = rules[idx];
                var include = rule.include;
                if (include) {
                    if (typeof (include) !== 'string') {
                        throw monarchCommon.createError(lexer, 'an \'include\' attribute must be a string at: ' + state);
                    }
                    if (include[0] === '@') {
                        include = include.substr(1); // peel off starting @
                    }
                    if (!json.tokenizer[include]) {
                        throw monarchCommon.createError(lexer, 'include target \'' + include + '\' is not defined at: ' + state);
                    }
                    addRules(state + '.' + include, newrules, json.tokenizer[include]);
                }
                else {
                    var newrule = new Rule(state);
                    // Set up new rule attributes
                    if (Array.isArray(rule) && rule.length >= 1 && rule.length <= 3) {
                        newrule.setRegex(lexerMin, rule[0]);
                        if (rule.length >= 3) {
                            if (typeof (rule[1]) === 'string') {
                                newrule.setAction(lexerMin, { token: rule[1], next: rule[2] });
                            }
                            else if (typeof (rule[1]) === 'object') {
                                var rule1 = rule[1];
                                rule1.next = rule[2];
                                newrule.setAction(lexerMin, rule1);
                            }
                            else {
                                throw monarchCommon.createError(lexer, 'a next state as the last element of a rule can only be given if the action is either an object or a string, at: ' + state);
                            }
                        }
                        else {
                            newrule.setAction(lexerMin, rule[1]);
                        }
                    }
                    else {
                        if (!rule.regex) {
                            throw monarchCommon.createError(lexer, 'a rule must either be an array, or an object with a \'regex\' or \'include\' field at: ' + state);
                        }
                        if (rule.name) {
                            if (typeof rule.name === 'string') {
                                newrule.name = rule.name;
                            }
                        }
                        if (rule.matchOnlyAtStart) {
                            newrule.matchOnlyAtLineStart = bool(rule.matchOnlyAtLineStart, false);
                        }
                        newrule.setRegex(lexerMin, rule.regex);
                        newrule.setAction(lexerMin, rule.action);
                    }
                    newrules.push(newrule);
                }
            }
        }
    }
// Compile an array of rules into newrules where RegExp objects are created.
Compile an array of rules into newrules where RegExp objects are created.
Compile an array of rules into newrules where RegExp objects are created .
function addRules(state, newrules, rules) {
        for (var idx in rules) {
            if (rules.hasOwnProperty(idx)) {
                var rule = rules[idx];
                var include = rule.include;
                if (include) {
                    if (typeof (include) !== 'string') {
                        throw monarchCommon.createError(lexer, 'an \'include\' attribute must be a string at: ' + state);
                    }
                    if (include[0] === '@') {
                        include = include.substr(1); 
                    }
                    if (!json.tokenizer[include]) {
                        throw monarchCommon.createError(lexer, 'include target \'' + include + '\' is not defined at: ' + state);
                    }
                    addRules(state + '.' + include, newrules, json.tokenizer[include]);
                }
                else {
                    var newrule = new Rule(state);
                    if (Array.isArray(rule) && rule.length >= 1 && rule.length <= 3) {
                        newrule.setRegex(lexerMin, rule[0]);
                        if (rule.length >= 3) {
                            if (typeof (rule[1]) === 'string') {
                                newrule.setAction(lexerMin, { token: rule[1], next: rule[2] });
                            }
                            else if (typeof (rule[1]) === 'object') {
                                var rule1 = rule[1];
                                rule1.next = rule[2];
                                newrule.setAction(lexerMin, rule1);
                            }
                            else {
                                throw monarchCommon.createError(lexer, 'a next state as the last element of a rule can only be given if the action is either an object or a string, at: ' + state);
                            }
                        }
                        else {
                            newrule.setAction(lexerMin, rule[1]);
                        }
                    }
                    else {
                        if (!rule.regex) {
                            throw monarchCommon.createError(lexer, 'a rule must either be an array, or an object with a \'regex\' or \'include\' field at: ' + state);
                        }
                        if (rule.name) {
                            if (typeof rule.name === 'string') {
                                newrule.name = rule.name;
                            }
                        }
                        if (rule.matchOnlyAtStart) {
                            newrule.matchOnlyAtLineStart = bool(rule.matchOnlyAtLineStart, false);
                        }
                        newrule.setRegex(lexerMin, rule.regex);
                        newrule.setAction(lexerMin, rule.action);
                    }
                    newrules.push(newrule);
                }
            }
        }
    }
function addRules ( state , newrules , rules ) { for ( var idx in rules ) { if ( rules . hasOwnProperty ( idx ) ) { var rule = rules [ idx ] ; var include = rule . include ; if ( include ) { if ( typeof ( include ) !== 'string' ) { throw monarchCommon . createError ( lexer , 'an \'include\' attribute must be a string at: ' + state ) ; } if ( include [ 0 ] === '@' ) { include = include . substr ( 1 ) ; } if ( ! json . tokenizer [ include ] ) { throw monarchCommon . createError ( lexer , 'include target \'' + include + '\' is not defined at: ' + state ) ; } addRules ( state + '.' + include , newrules , json . tokenizer [ include ] ) ; } else { var newrule = new Rule ( state ) ; if ( Array . isArray ( rule ) && rule . length >= 1 && rule . length <= 3 ) { newrule . setRegex ( lexerMin , rule [ 0 ] ) ; if ( rule . length >= 3 ) { if ( typeof ( rule [ 1 ] ) === 'string' ) { newrule . setAction ( lexerMin , { token : rule [ 1 ] , next : rule [ 2 ] } ) ; } else if ( typeof ( rule [ 1 ] ) === 'object' ) { var rule1 = rule [ 1 ] ; rule1 . next = rule [ 2 ] ; newrule . setAction ( lexerMin , rule1 ) ; } else { throw monarchCommon . createError ( lexer , 'a next state as the last element of a rule can only be given if the action is either an object or a string, at: ' + state ) ; } } else { newrule . setAction ( lexerMin , rule [ 1 ] ) ; } } else { if ( ! rule . regex ) { throw monarchCommon . createError ( lexer , 'a rule must either be an array, or an object with a \'regex\' or \'include\' field at: ' + state ) ; } if ( rule . name ) { if ( typeof rule . name === 'string' ) { newrule . name = rule . name ; } } if ( rule . matchOnlyAtStart ) { newrule . matchOnlyAtLineStart = bool ( rule . matchOnlyAtLineStart , false ) ; } newrule . setRegex ( lexerMin , rule . regex ) ; newrule . setAction ( lexerMin , rule . action ) ; } newrules . push ( newrule ) ; } } } }
Compile an array of rules into newrules where RegExp objects are created.
Compile an array of rules into newrules where RegExp objects are created .
// peel off starting @ // Set up new rule attributes