generateSequence()

in wasm/wasm-sharding-js/sharding/strgen.js [432:545]


    generateSequence() { // split each value in the sequence and push it to the generated_value_list array
        var string_value = "";
        var last_operator = "none";
        var temp_string;
        this.createLogEntry("Processing sequence at pattern position " + (this.current_index + 1));

        while(this.current() != ')') { // while the current character is not the end of the sequence
            if (this.lookahead() == '|' || this.lookahead() == ')' || this.lookahead() == '&') { // if the next character is a closing bracket or sequence operators
                if (this.lookahead() == '|' && last_operator != "&" || last_operator == '|' && this.lookahead() == ')') {
                    // if next character is OR operator and last_operator is not AND, or, if last_operator is OR operator and next character is end of sequence - perform OR
                    this.createLogEntry("OR operator - last operator", last_operator);
                    last_operator = '|';

                    if (string_value != "") {
                        this.temporary_value_list.push(string_value);
                        this.createLogEntry("OR word parsed", string_value);
                        string_value = "";                       
                    }

                    if (this.lookahead() == ')') { break; } else { this.next(); }
                } else if (this.lookahead() == '&' || last_operator == '&' && this.lookahead() == ')' || last_operator == '&' && this.lookahead() == '|') {
                    // if next character is AND operator, or, if last_operator is AND operator and next character is end of sequence or OR operator - perform AND
                    this.createLogEntry("AND operator - last operator", last_operator);
                    last_operator = "&";

                    if (temp_string == undefined) {
                        temp_string = string_value;
                    } else {
                        temp_string += string_value;
                    }

                    this.createLogEntry("AND word parsed", string_value);
                    string_value = "";

                    if (this.lookahead() == ')' || this.lookahead() == '|') { // if next character is end or OR operator (AND operator has ended/no more ANDs yet) - split temp_string and create random word
                        this.createLogEntry("OR operator or end ahead");
                        var output_string = "";
                        var temp_string_length = temp_string.length;
                        var temp_string_array = temp_string.split("");

                        this.createLogEntry("Combined string character range", temp_string_array.toString());

                        this.generated_value_list.push(this.generateAndString(temp_string_array));
                        temp_string = "";

                        if (this.lookahead() == ')') { // if next character is end of sequence, break loop
                            break;  
                        } else if (this.lookahead() == '|') { // if next character is OR operator, set last_operator to OR and move to next character
                            if (last_operator = '&') {
                                this.createLogEntry("Storing " + this.generated_value_list.toString() + " in a different list temporarily");
                                this.temporary_value_list = this.temporary_value_list.concat(this.generated_value_list);
                                this.generated_value_list = [];
                            }
                            last_operator = '|'
                            this.createLogEntry("last_operator set to '|'");
                            this.next();
                        }
                    } else { 
                        this.next(); 
                    }
                }
                else if (this.lookahead() == ')' && last_operator == "none" || this.lookahead() == '') {
                    if (string_value == "") {
                        this.outputWarning("Unbroken Sequence starting at position " + (this.current_index + 1) + " does not contain any values.");
                    } else {
                        this.generated_value_list.push(string_value);
                        //this.outputWarning("Sequence starting at position " + ((this.current_index + 1) - string_value.length) + " only contains one value.")         
                    }
                    break;
                }
            }
            else if (this.lookahead() != '') {
                this.next();
                if (this.operators.includes(this.current()) == true || this.symbol_quantifiers.includes(this.current()) == true) {
                    if (this.current() == "[") {
                        this.getCharacterSet();
                    } else if (this.current() == "]") {
                        this.createLogEntry("End of range reached", this.generated_value_list.toString());
                        if (this.lookahead() != '{' && !this.symbol_quantifiers.includes(this.lookahead())) {
                            string_value += this.selectValueFromList(this.quantifier_value, undefined, this.allow_duplicate_characters);
                        }  
                    } else if (this.current() == "{") {
                        this.quantifier_value = this.getQuantifier();
                    } else if (this.current() == "}") {
                        if (this.quantifier_value == 0) {
                            this.createLogEntry("End of quantifier reached", "0");
                            this.createLogEntry("No generation as quantifier is 0");  
                        } else {
                            this.createLogEntry("End of quantifier reached", this.quantifier_value);
                            this.createLogEntry("Contents of value list", this.generated_value_list.toString());

                            string_value += this.selectValueFromList(this.quantifier_value, undefined, this.allow_duplicate_characters);
                        }
                        this.quantifier_value = 1;
                        this.generated_value_list = [];
                    } else if (this.symbol_quantifiers.includes(this.current())) {
                        this.quantifier_value = this.getQuantifier(this.current());

                        string_value += this.selectValueFromList(this.quantifier_value, undefined, this.allow_duplicate_characters);

                        this.quantifier_value = 1;
                        this.generated_value_list = [];
                    } else if (this.current() == "/") {
                        string_value += this.next();
                    }
                } else {
                    string_value += this.current();                   
                }
            } else {
                this.outputError("End of sequence expected at position " + (this.current_index + 1) + ".");
                break;
            }
        }
    };