"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.svcompletion_grammar = void 0;
const grammar_engine_1 = require("./grammar_engine");
function toAssignmentExpression(scopeName, listRegExp, listTokens, listContext, endRegExp, endTokens) {
    return {
        scopeName: scopeName,
        patterns: [
            {
                match: listRegExp,
                tokens: listTokens,
                pop: listContext
            },
            {
                match: endRegExp,
                tokens: endTokens,
                pop: ""
            },
            { include: "BaseGrammar" }
        ]
    };
}
function toPortListBody(scopeNamePrefix, termRegExp, termTokens, contextName) {
    return {
        scopeName: `${scopeNamePrefix}.list.systemverilog`,
        patterns: [
            {
                match: termRegExp,
                tokens: termTokens,
                pop: ""
            },
            {
                match: grammar_engine_1.r `(=)`,
                tokens: ["operator.equals.systemverilog"],
                pop: toAssignmentExpression(`${scopeNamePrefix}.expression.systemverilog`, grammar_engine_1.r `(,)`, ["operator.comma.systemverilog"], contextName, termRegExp, termTokens)
            },
            { include: "AllAllow" },
            { include: "AttributeInstance" },
            { include: "CommaOperator" },
            { include: "Dimension" },
            { include: "EnumDeclaration" },
            { include: "GeneralParanthesesBlock" },
            { include: "StructUnionDeclaration" },
            { include: "Identifier" }
        ]
    };
}
function toIgnoreBlock(startRegExp, startTokens, endRegExp, endTokens, scopeNamePrefix, contextName) {
    return {
        patterns: [
            {
                match: startRegExp,
                tokens: startTokens,
                push: {
                    scopeName: `${scopeNamePrefix}.declaration.systemverilog`,
                    patterns: [
                        {
                            match: endRegExp,
                            tokens: endTokens,
                            pop: ""
                        },
                        { include: contextName },
                        { include: "BaseGrammar" }
                    ]
                }
            }
        ]
    };
}
function toIgnoreStatement(startRegExp, startTokens, scopeNamePrefix) {
    return {
        patterns: [
            {
                match: startRegExp,
                tokens: startTokens,
                push: {
                    scopeName: `${scopeNamePrefix}.statement.systemverilog`,
                    patterns: [
                        {
                            match: grammar_engine_1.r `(;)`,
                            tokens: ["operator.semicolon.systemverilog"],
                            pop: ""
                        },
                        { include: "BaseGrammar" }
                    ]
                }
            }
        ]
    };
}
exports.svcompletion_grammar = {
    Main: {
        scopeName: "source.systemverilog",
        patterns: [
            { include: "AttributeInstance" },
            { include: "ContinuousBlock" },
            { include: "EnumDeclaration" },
            { include: "BeginEndBlock" },
            { include: "ExportDeclaration" },
            { include: "GenerateBlock" },
            { include: "IgnoreBlocksStatements" },
            { include: "ImportDeclaration" },
            { include: "ModPortDeclaration" },
            { include: "ParameterDeclaration" },
            { include: "PortDeclaration" },
            { include: "RoutineDeclaration" },
            { include: "StructUnionDeclaration" },
            { include: "SvContainer" },
            { include: "SvPackage" },
            { include: "TypeDefDeclaration" },
            { include: "BaseGrammar" }
        ]
    },
    AllAllow: {
        patterns: [
            { include: "Macro" },
            { include: "Comment" },
            { include: "Whitespace" }
        ]
    },
    AssignmentExpression: {
        patterns: [
            {
                //TBD match: r`((?:<)?=(?!==?))`, //Non-blocking assignment is confused with less-than-equals operator
                match: grammar_engine_1.r `((?<!<)=(?!==?))`,
                tokens: ["assignment.begin.systemverilog"],
                push: {
                    scopeName: "assignment.expression.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(;)`,
                            tokens: ["assignment.end.systemverilog"],
                            pop: ""
                        },
                        { include: "BaseGrammar" }
                    ]
                }
            }
        ]
    },
    AssignmentPattern: {
        patterns: [
            {
                match: grammar_engine_1.r `('\{)`,
                tokens: ["assignment_pattern.begin.systemverilog"],
                push: {
                    scopeName: "assignment_pattern.expression.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(\})`,
                            tokens: ["assignment_pattern.end.systemverilog"],
                            pop: ""
                        },
                        { include: "BaseGrammar" }
                    ]
                }
            }
        ]
    },
    AttributeInstance: {
        patterns: [
            {
                match: grammar_engine_1.r `((?<!@ *)\(\*)`,
                tokens: ["attribute.begin.systemverilog"],
                push: "AttributeInstanceBody"
            }
        ]
    },
    AttributeInstanceBody: {
        scopeName: "attribute.inst.systemverilog",
        patterns: [
            {
                match: grammar_engine_1.r `(\*\))`,
                tokens: ["attribute.end.systemverilog"],
                pop: ""
            },
            { include: "Identifier" },
            {
                match: grammar_engine_1.r `(=)`,
                tokens: ["operator.equals.systemverilog"],
                pop: toAssignmentExpression("attribute.expression.systemverilog", grammar_engine_1.r `(,)`, ["operator.comma.systemverilog"], "AttributeInstanceBody", grammar_engine_1.r `(\*\))`, ["attribute.end.systemverilog"])
            },
            { include: "AllAllow" }
        ]
    },
    BaseGrammar: {
        patterns: [
            { include: "AllAllow" },
            { include: "AttributeInstance" },
            //TBC { include: "AssignmentExpression" },
            { include: "AssignmentPattern" },
            { include: "EnumDeclaration" },
            { include: "StructUnionDeclaration" },
            { include: "TypeDefDeclaration" },
            { include: "CaseStatement" },
            { include: "CommaOperator" },
            { include: "CompletionItems" },
            { include: "Dimension" },
            { include: "GeneralBracesBlock" },
            { include: "GeneralParanthesesBlock" },
            { include: "QuotedString" },
            { include: "SpecialTokens" },
            { include: "SvNumber" },
            { include: "SvOperators" }
        ]
    },
    BeginEndBlock: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(begin)\b`,
                tokens: ["keyword.begin.systemverilog"],
                pushScopes: ["begin.block.systemverilog"]
            },
            {
                match: grammar_engine_1.r `\b(end)\b`,
                tokens: ["keyword.end.systemverilog"],
                popScopes: ["begin.block.systemverilog"]
            }
        ]
    },
    CaseStatement: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(case[xz]?|randcase)\b`,
                tokens: ["keyword.case.systemverilog"],
                pushScopes: ["case.body.systemverilog"]
            },
            {
                match: grammar_engine_1.r `\b(endcase)\b`,
                tokens: ["keyword.endcase.systemverilog"],
                popScopes: ["case.body.systemverilog"]
            }
        ]
    },
    CommaOperator: {
        patterns: [
            {
                match: grammar_engine_1.r `(,)`,
                tokens: ["operator.comma.systemverilog"]
            }
        ]
    },
    Comment: {
        patterns: [
            {
                match: grammar_engine_1.r `(/\*(?:.|\n|\r)*?(?:\*/|$))`,
                tokens: ["comment.block.systemverilog"],
            },
            {
                match: grammar_engine_1.r `(//.*(?:\n|\r|$))`,
                tokens: ["comment.line.systemverilog"],
            }
        ]
    },
    CompletionItems: {
        patterns: [
            { include: "Identifier" },
            { include: "SystemTask" }
        ]
    },
    ContinuousBlock: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(assign)\b`,
                tokens: ["keyword.assign.systemverilog"],
                push: "ContinuousBlockBody"
            }
        ]
    },
    ContinuousBlockBody: {
        scopeName: "continuous.block.systemverilog",
        patterns: [
            {
                match: grammar_engine_1.r `(;)`,
                tokens: "operator.semicolon.systemverilog",
                pop: ""
            },
            {
                match: grammar_engine_1.r `(=)`,
                tokens: ["operator.equals.systemverilog"],
                pop: toAssignmentExpression("continuous.expression.systemverilog", grammar_engine_1.r `(,)`, ["operator.comma.systemverilog"], "ContinuousBlockBody", grammar_engine_1.r `(;)`, ["operaator.semicolon.systemverilog"])
            },
            { include: "BaseGrammar" }
        ]
    },
    Dimension: {
        patterns: [
            {
                match: grammar_engine_1.r `(\[)`,
                tokens: ["operator.open_bracket.systemverilog"],
                push: {
                    scopeName: "dimension.expression.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(\])`,
                            tokens: ["operator.close_bracket.systemverilog"],
                            pop: ""
                        },
                        { include: "RangeOperator" },
                        { include: "BaseGrammar" }
                    ]
                }
            }
        ]
    },
    GenerateBlock: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(generate)\b`,
                tokens: ["keyword.generate.systemverilog"],
                pushScopes: ["generate.block.systemverilog"]
            },
            {
                match: grammar_engine_1.r `\b(endgenerate)\b`,
                tokens: ["keyword.endgenerate.systemverilog"],
                popScopes: ["generate.block.systemverilog"]
            }
        ]
    },
    EnumDeclaration: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(enum)\b`,
                tokens: ["keyword.enum.systemverilog"],
                push: {
                    scopeName: "enum.declaration.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(\{)`,
                            tokens: ["enum_list.begin.systemverilog"],
                            pop: "EnumListBody",
                        },
                        { include: "AllAllow" },
                        { include: "Identifier" },
                        { include: "Dimension" }
                    ]
                }
            },
        ]
    },
    EnumListBody: {
        scopeName: "enum_list.body.systemverilog",
        patterns: [
            {
                match: grammar_engine_1.r `(\})`,
                tokens: ["enum_list.end.systemverilog"],
                pop: ""
            },
            {
                match: grammar_engine_1.r `(=)`,
                tokens: ["operator.equals.systemverilog"],
                pop: toAssignmentExpression("enum.expression.systemverilog", grammar_engine_1.r `(,)`, ["operator.comma.systemverilog"], "EnumListBody", grammar_engine_1.r `(\})`, ["enum_list.end.systemverilog"])
            },
            { include: "AllAllow" },
            { include: "CommaOperator" },
            { include: "Dimension" },
            { include: "Identifier" }
        ]
    },
    ExportDeclaration: {
        patterns: [
            {
                match: grammar_engine_1.r `(\bexport\b)`,
                tokens: ["keyword.export.systemverilog"],
                push: {
                    scopeName: "export.declaration.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(;)`,
                            tokens: ["operator.semicolon.systemverilog"],
                            pop: ""
                        },
                        {
                            match: grammar_engine_1.r `(\*::\*)`,
                            tokens: ["identifier.scoped.systemverilog"]
                        },
                        { include: "AllAllow" },
                        { include: "Identifier" }
                    ]
                }
            }
        ]
    },
    ForkJoinBlock: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(fork)\b`,
                tokens: ["keyword.fork.systemverilog"],
                push: {
                    scopeName: "fork.body.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `\b(join|join_any|join_none)\b`,
                            tokens: ["keyword.join.systemverilog"],
                            pop: ""
                        },
                        { include: "ForkJoinBlock" },
                        { include: "BaseGrammar" }
                    ]
                }
            }
        ]
    },
    GeneralBracesBlock: {
        patterns: [
            {
                match: grammar_engine_1.r `(\{)`,
                tokens: ["braces.begin.systemverilog"],
                push: {
                    scopeName: "braces.block.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(\})`,
                            tokens: ["braces.end.systemverilog"],
                            pop: ""
                        },
                        { include: "BaseGrammar" }
                    ]
                }
            }
        ]
    },
    GeneralParanthesesBlock: {
        patterns: [
            {
                match: grammar_engine_1.r `(\()`,
                tokens: ["parantheses.begin.systemverilog"],
                push: {
                    scopeName: "parantheses.block.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(\))`,
                            tokens: ["parantheses.end.systemverilog"],
                            pop: ""
                        },
                        { include: "BaseGrammar" }
                    ]
                }
            }
        ]
    },
    Identifier: {
        patterns: [
            {
                match: grammar_engine_1.r `([a-zA-Z_][a-zA-Z0-9_$]*::(?:[a-zA-Z_][a-zA-Z0-9_$]*(?:::)?)*\*?)`,
                tokens: ["identifier.scoped.systemverilog"]
            },
            {
                match: grammar_engine_1.r `([a-zA-Z_][a-zA-Z0-9_$]*\.(?:[a-zA-Z_][a-zA-Z0-9_$]*\.?)*)`,
                tokens: ["identifier.hierarchical.systemverilog"]
            },
            {
                match: grammar_engine_1.r `([a-zA-Z_][a-zA-Z0-9_$]*)`,
                tokens: ["identifier.simple.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(\\\S+(?:\s|\n|\r))`,
                tokens: ["identifier.escaped.systemverilog"]
            }
        ]
    },
    IgnoreBlocksStatements: {
        patterns: [
            { include: "IgnoreCheckerDeclaration" },
            { include: "IgnoreClassDeclaration" },
            { include: "IgnoreCoverGroupDeclaration" },
            { include: "IgnoreDefparamStatement" },
            { include: "IgnoreExternConstraintDeclaration" },
            { include: "IgnoreLetStatement" },
            { include: "IgnorePropertyDeclaration" },
            { include: "IgnoreSequenceDeclaration" },
            { include: "IgnoreSpecifyBlock" },
            { include: "IgnoreSpecparamDeclaration" }
        ]
    },
    IgnoreCheckerDeclaration: toIgnoreBlock(grammar_engine_1.r `\b(checker)\b`, ["keyword.checker.systemverilog"], grammar_engine_1.r `\b(endchecker)\b`, ["keyword.endchecker.systemverilog"], "checker", "IgnoreCheckerDeclaration"),
    IgnoreClassDeclaration: toIgnoreBlock(grammar_engine_1.r `\b(class)\b`, ["keyword.class.systemverilog"], grammar_engine_1.r `\b(endclass)\b`, ["keyword.endclass.systemverilog"], "class", "IgnoreClassDeclaration"),
    IgnoreCoverGroupDeclaration: toIgnoreBlock(grammar_engine_1.r `\b(covergroup)\b`, ["keyword.covergroup.systemverilog"], grammar_engine_1.r `\b(endgroup)\b`, ["keyword.endgroup.systemverilog"], "covergroup", "IgnoreCoverGroupDeclaration"),
    IgnoreDefparamStatement: toIgnoreStatement(grammar_engine_1.r `\b(defparam)\b`, ["keyword.defparam.systemverilog"], "defparam"),
    IgnoreExternConstraintDeclaration: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(constraint)\b`,
                tokens: ["keyword.constraint.systemverilog"],
                push: {
                    scopeName: "constraint.declaration.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(\{)`,
                            tokens: ["operator.open_braces.systemverilog"],
                            pop: {
                                scopeName: "constraint.body.systemverilog",
                                patterns: [
                                    {
                                        match: grammar_engine_1.r `(\})`,
                                        tokens: ["operator.close_braces.systemverilog"],
                                        pop: ""
                                    },
                                    { include: "BaseGrammar" }
                                ]
                            }
                        },
                        { include: "AllAllow" },
                        { include: "Identifier" }
                    ]
                }
            }
        ]
    },
    IgnoreLetStatement: toIgnoreStatement(grammar_engine_1.r `\b(let)\b`, ["keyword.let.systemverilog"], "let"),
    IgnorePropertyDeclaration: toIgnoreBlock(grammar_engine_1.r `\b(property)\b`, ["keyword.property.systemverilog"], grammar_engine_1.r `\b(endproperty)\b`, ["keyword.endproperty.systemverilog"], "property", "IgnorePropertyDeclaration"),
    IgnoreSequenceDeclaration: toIgnoreBlock(grammar_engine_1.r `\b(sequence)\b`, ["keyword.sequence.systemverilog"], grammar_engine_1.r `\b(endsequence)\b`, ["keyword.endsequence.systemverilog"], "sequence", "IgnoreSequenceDeclaration"),
    IgnoreSpecifyBlock: toIgnoreBlock(grammar_engine_1.r `\b(specify)\b`, ["keyword.specify.systemverilog"], grammar_engine_1.r `\b(endspecify)\b`, ["keyword.endspecify.systemverilog"], "specify", "IgnoreSpecifyBlock"),
    IgnoreSpecparamDeclaration: toIgnoreStatement(grammar_engine_1.r `\b(specparam)\b`, ["keyword.specparam.systemverilog"], "specparam"),
    ImportDeclaration: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(import)\b`,
                tokens: ["keyword.import.systemverilog"],
                push: {
                    scopeName: "import.statement.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(;)`,
                            tokens: ["operator.semicolon.systemverilog"],
                            pop: ""
                        },
                        { include: "AllAllow" },
                        { include: "CommaOperator" },
                        { include: "Identifier" }
                    ]
                }
            }
        ]
    },
    Macro: {
        patterns: [
            {
                match: grammar_engine_1.r `(\`(?:[a-zA-Z_][a-zA-Z0-9_$]*\s*|\\\S+\s+)\()`,
                tokens: ["macro.call.systemverilog"],
                push: {
                    scopeName: "macro.args.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(\))`,
                            tokens: ["macro.end.systemverilog"],
                            pop: "",
                        },
                        { include: "BaseGrammar" }
                    ]
                }
            },
            //TODO : fix
            {
                match: grammar_engine_1.r `(\`define)\b`,
                tokens: ["preproc.define.systemverilog"],
                push: {
                    scopeName: "preproc.declaration.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(\\\\)`,
                            tokens: ["escaped.backslash.systemverilog"]
                        },
                        {
                            match: grammar_engine_1.r `(\\(?:\n|\r))`,
                            tokens: ["escaped.newline.systemverilog"]
                        },
                        {
                            match: grammar_engine_1.r `(//.*(?:\n|\r|$))`,
                            tokens: ["comment.line.systemverilog"],
                            pop: ""
                        },
                        {
                            match: grammar_engine_1.r `(\n|\r|$)`,
                            tokens: ["meta.whitespace.systemverilog"],
                            pop: ""
                        },
                        { include: "Identifier" },
                        { include: "Macro" },
                        { include: "QuotedString" },
                        { include: "SvNumber" },
                        { include: "SvOperators" },
                        { include: "Whitespace" }
                    ]
                }
            },
            {
                match: grammar_engine_1.r `(\`ifdef|\`ifndef)\b`,
                tokens: ["preproc.if.systemverilog"],
                saveState: true,
                push: {
                    scopeName: "macro.conditional.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `([a-zA-Z_][0-9a-zA-Z_$]*|\\\S+\s)`,
                            tokens: ["identifier.macro.systemverilog"],
                            pop: ""
                        },
                        { include: "AllAllow" }
                    ]
                }
            },
            {
                match: grammar_engine_1.r `(\`elsif)\b`,
                tokens: ["preproc.elsif.systemverilog"],
                restoreState: true,
                push: {
                    scopeName: "macro.conditional.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `([a-zA-Z_][0-9a-zA-Z_$]*|\\\S+\s)`,
                            tokens: ["identifier.macro.systemverilog"],
                            pop: ""
                        },
                        { include: "AllAllow" }
                    ]
                }
            },
            {
                match: grammar_engine_1.r `(\`else)\b`,
                tokens: ["preproc.else.systemverilog"],
                restoreState: true
            },
            {
                match: grammar_engine_1.r `(\`endif)\b`,
                tokens: ["preproc.endif.systemverilog"],
                deleteState: true
            },
            {
                match: grammar_engine_1.r `(\`(?:[a-zA-Z_][a-zA-Z0-9_$]*|\\\S+\s))`,
                tokens: ["macro.identifier.systemverilog"]
            }
        ]
    },
    ModPortDeclaration: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(modport)\b`,
                tokens: ["keyword.modport.systemverilog"],
                push: {
                    scopeName: "modport.declaration.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(;)`,
                            tokens: ["operator.semicolon.systemverilog"],
                            pop: ""
                        },
                        { include: "PortList" },
                        { include: "BaseGrammar" }
                    ]
                }
            }
        ]
    },
    ParameterDeclaration: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(parameter|localparam)\b`,
                tokens: ["keyword.parameter.systemverilog"],
                push: "ParameterDeclarationBody"
            }
        ]
    },
    ParameterDeclarationBody: {
        scopeName: "parameter.declaration.systemverilog",
        patterns: [
            {
                match: grammar_engine_1.r `(;)`,
                tokens: ["operator.semicolon.systemverilog"],
                pop: "",
            },
            {
                match: grammar_engine_1.r `(=)`,
                tokens: ["operator.equals.systemverilog"],
                pop: toAssignmentExpression("parameter.expression.systemverilog", grammar_engine_1.r `(,)`, ["operator.comma.systemverilog"], "ParameterDeclarationBody", grammar_engine_1.r `(;)`, ["operator.semicolon.systemverilog"])
            },
            { include: "AllAllow" },
            { include: "Dimension" },
            { include: "EnumDeclaration" },
            { include: "GeneralParanthesesBlock" },
            { include: "StructUnionDeclaration" },
            { include: "Identifier" }
        ]
    },
    ParameterPortList: {
        patterns: [
            {
                match: grammar_engine_1.r `(#\()`,
                tokens: ["operator.hash_open_parantheses.systemverilog"],
                push: "ParameterPortListBody"
            }
        ]
    },
    ParameterPortListBody: toPortListBody("parameter", grammar_engine_1.r `(\))`, ["operator.close_parantheses.systemverilog"], "ParameterPortListBody"),
    PortDeclaration: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(input|output|inout|ref)\b`,
                tokens: ["keyword.port_direction.systemverilog"],
                push: "PortDeclarationBody"
            }
        ]
    },
    PortDeclarationBody: toPortListBody("port_declaration", grammar_engine_1.r `(;)`, ["operator.semicolon.systemverilog"], "PortDeclarationBody"),
    PortList: {
        patterns: [
            {
                match: grammar_engine_1.r `((?<!#)\()`,
                tokens: ["operator.open_parantheses.systemverilog"],
                push: "PortListBody"
            }
        ]
    },
    PortListBody: toPortListBody("port", grammar_engine_1.r `(\))`, ["operator.close_parantheses.systemverilog"], "PortListBody"),
    QuotedString: {
        patterns: [
            {
                match: grammar_engine_1.r `(")`,
                tokens: ["string.begin.systemverilog"],
                push: {
                    scopeName: "string.body.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(")`,
                            tokens: ["string.end.systemverilog"],
                            pop: "",
                        },
                        {
                            match: grammar_engine_1.r `(\\\\)`,
                            tokens: ["escaped.backslash.systemverilog"]
                        },
                        {
                            match: grammar_engine_1.r `(\\")`,
                            tokens: ["escaped.quote.systemverilog"]
                        },
                        {
                            match: grammar_engine_1.r `(\\)`,
                            tokens: ["regular.backslash.systemverilog"]
                        },
                        {
                            match: grammar_engine_1.r `([^"\\]+)`,
                            tokens: ["string.characters.systemverilog"]
                        }
                    ]
                }
            }
        ]
    },
    RandSequenceBlock: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(randsequence)\b`,
                tokens: ["keyword.randsequence.systemverilog"],
                push: {
                    scopeName: "randsequence.body.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `\b(endsequence)\b`,
                            tokens: ["keyword.endsequence.systemverilog"],
                            pop: ""
                        },
                        { include: "RandSequenceBlock" },
                        { include: "BaseGrammar" }
                    ]
                }
            }
        ]
    },
    RangeOperator: {
        patterns: [
            {
                match: grammar_engine_1.r `((?:\+|-)?:)`,
                tokens: ["operator.range.systemverilog"]
            }
        ]
    },
    RoutineDeclaration: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(function|task)\b`,
                tokens: ["keyword.routine.systemverilog"],
                push: {
                    scopeName: "routine.header.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(;)`,
                            tokens: ["operator.semicolon.systemverilog"],
                            pop: ""
                        },
                        { include: "AllAllow" },
                        { include: "Dimension" },
                        { include: "Identifier" },
                        { include: "PortList" }
                    ]
                }
            }
        ]
    },
    StructUnionDeclaration: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(struct|union)\b`,
                tokens: ["keyword.struct_union.systemverilog"],
                push: {
                    scopeName: "struct_union.declaration.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(\{)`,
                            tokens: ["struct_union_member_list.begin.systemverilog"],
                            pop: "StructUnionMemberListBody",
                        },
                        { include: "AllAllow" },
                        { include: "Identifier" }
                    ]
                }
            }
        ]
    },
    StructUnionMemberListBody: {
        scopeName: "struct_union_member_list.body.systemverilog",
        patterns: [
            {
                match: grammar_engine_1.r `(\})`,
                tokens: ["struct_union_member_list.end.systemverilog"],
                pop: ""
            },
            {
                match: grammar_engine_1.r `(=)`,
                tokens: ["operator.equals.systemverilog"],
                pop: toAssignmentExpression("struct_union_member.expression.systemverilog", grammar_engine_1.r `(;)`, ["operator.comma.systemverilog"], "StructUnionMemberListBody", grammar_engine_1.r `(\})`, ["struct_union_member_list.end.systemverilog"])
            },
            {
                match: grammar_engine_1.r `(;)`,
                tokens: ["operator.semicolon.systemverilog"]
            },
            { include: "AllAllow" },
            { include: "Dimension" },
            { include: "StructUnionDeclaration" },
            { include: "EnumDeclaration" },
            { include: "Identifier" }
        ]
    },
    SvContainer: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(module|macromodule|interface|program)\b`,
                tokens: ["keyword.container.systemverilog"],
                push: {
                    scopeName: "container.header.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(;)`,
                            tokens: ["operator.semicolon.systemverilog"],
                            pop: ""
                        },
                        { include: "AllAllow" },
                        { include: "ImportDeclaration" },
                        { include: "Identifier" },
                        { include: "ParameterPortList" },
                        { include: "PortList" }
                    ]
                }
            }
        ]
    },
    SpecialTokens: {
        patterns: [
            {
                match: grammar_engine_1.r `(\'")`,
                tokens: ["macro.quote.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(\`\\")`,
                tokens: ["macro.escaped_quote.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(\`\`)`,
                tokens: ["macro.concat.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(\\\\)`,
                tokens: ["escaped.backslash.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(\\(?:\n|\r))`,
                tokens: ["escaped.new_line.systemverilog"]
            }
        ]
    },
    SvNumber: {
        patterns: [
            {
                match: `([0-9][0-9]*(?:\.[0-9][0-9*])?(?:s|ms|us|ns|ps|fs))`,
                tokens: ["literal.time.systemverilog"]
            },
            {
                match: grammar_engine_1.r `((?:\d+)?'[sS]?[bB][01xXzZ?][01xXzZ?_]*)`,
                tokens: ["literal.number.systemverilog"]
            },
            {
                match: grammar_engine_1.r `((?:\d+)?'[sS]?[oO][0-7xXzZ?][0-7xXzZ?_]*)`,
                tokens: ["literal.number.systemverilog"]
            },
            {
                match: grammar_engine_1.r `((?:\d+)?'[sS]?[dD][0-9][0-9_]*)`,
                tokens: ["literal.number.systemverilog"]
            },
            {
                match: grammar_engine_1.r `((?:\d+)?'[sS]?[dD][xXzZ?]_*)`,
                tokens: ["literal.number.systemverilog"]
            },
            {
                match: grammar_engine_1.r `((?:\d+)?'[sS]?[hH][0-9a-fA-FxXzZ?][0-9a-fA-F_xXzZ?]*)`,
                tokens: ["literal.number.systemverilog"]
            },
            {
                match: grammar_engine_1.r `('[01xXzZ?])`,
                tokens: ["literal.number.systemverilog"]
            },
            {
                match: grammar_engine_1.r `([0-9][0-9_]*(?:\.[0-9][0-9_]*)?(?:[eE](?:\+|-)?[0-9][0-9_]*)?)`,
                tokens: ["literal.number.systemverilog"]
            }
        ]
    },
    SvOperators: {
        patterns: [
            {
                match: grammar_engine_1.r `(===|!==|==|!=|<=|>=|<<|>>|<|>)`,
                tokens: ["operator.comparison.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(->[>]?)`,
                tokens: ["operator.trigger.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(=)`,
                tokens: ["operator.equals.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(:=|:/)`,
                tokens: ["operator.constraint.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(\-\-|\+\+|\-|\+|\*|\/|%)`,
                tokens: ["operator.arithmetic.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(!|&&|\|\|)`,
                tokens: ["operator.logical.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(\bor\b)`,
                tokens: ["operator.logical.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(&|\||\^|~)`,
                tokens: ["operator.bitwise.systemverilog"]
            },
            // GeneralBracesBlock
            //{
            //    match: r`(\{|})`,
            //    tokens: ["operator.other.systemverilog"]
            //},
            {
                match: grammar_engine_1.r `(\?|:)`,
                tokens: ["operator.ternary.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(#)(1step)`,
                tokens: ["operator.delay.systemverilog", "keyword.other.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(##|#|@|\.|')`,
                tokens: ["operator.other.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(;)`,
                tokens: ["operator.semicolon.systemverilog"]
            },
            {
                match: grammar_engine_1.r `(\\)`,
                tokens: ["operator.backslash.systemverilog"]
            }
        ]
    },
    SvPackage: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(package)\b`,
                tokens: ["keyword.package.systemverilog"],
                push: {
                    scopeName: "package.header.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(;)`,
                            tokens: ["operator.semicolon.systemverilog"],
                            pop: ""
                        },
                        { include: "AllAllow" },
                        { include: "Identifier" }
                    ]
                }
            }
        ]
    },
    SystemTask: {
        patterns: [
            {
                match: grammar_engine_1.r `(\$[a-zA-Z_][a-zA-Z0-9_$]*\()`,
                tokens: ["system.task.systemverilog"],
                push: {
                    scopeName: "system.args.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(\))`,
                            tokens: ["system.end.systemverilog"],
                            pop: "",
                        },
                        { include: "BaseGrammar" }
                    ]
                }
            },
            {
                match: grammar_engine_1.r `(\$[a-zA-Z_][a-zA-Z0-9_$]*)`,
                tokens: ["system.identifier.systemverilog"]
            }
        ]
    },
    TypeDefDeclaration: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(typedef)\b`,
                tokens: ["keyword.typedef.systemverilog"],
                push: {
                    scopeName: "typedef.declaration.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(;)`,
                            tokens: ["operator.semicolon.systemverilog"],
                            pop: ""
                        },
                        { include: "BaseGrammar" }
                    ]
                }
            }
        ]
    },
    TypeReference: {
        patterns: [
            {
                match: grammar_engine_1.r `\b(type)\b`,
                tokens: ["keyword.type.systemverilog"],
                push: {
                    scopeName: "type.reference.systemverilog",
                    patterns: [
                        {
                            match: grammar_engine_1.r `(\()`,
                            tokens: ["parantheses.begin.systemverilog"],
                            pop: {
                                scopeName: "type.expression.systemverilog",
                                patterns: [
                                    {
                                        match: grammar_engine_1.r `(\))`,
                                        tokens: ["parantheses.end.systemverilog"],
                                        pop: ""
                                    },
                                    { include: "BaseGrammar" }
                                ]
                            }
                        },
                        { include: "AllAllow" }
                    ]
                }
            }
        ]
    },
    Whitespace: {
        patterns: [
            {
                match: grammar_engine_1.r `((?:\s|\n|\r)+)`,
                tokens: ["meta.whitespace.systemverilog"]
            }
        ]
    }
};
