ChFlick/firecode

View on GitHub
syntaxes/firestorerules.tmLanguage.json

Summary

Maintainability
Test Coverage
{
    "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
    "name": "firestorerules",
    "scopeName": "source.firebase",
    "patterns": [
        {
            "include": "#firestore-root"
        },
        {
            "include": "#version"
        },
        {
            "include": "#function-declaration"
        },
        {
            "include": "#comments"
        }
    ],
    "repository": {
        "constants": {
            "patterns": [
                {
                    "name": "constant.numeric.firestorerules",
                    "match": "\\d+"
                },
                {
                    "name": "constant.language.firestorerules",
                    "match": "\\b(true|false|write|read|get|list|update|delete|create)\\b"
                }
            ]
        },
        "comments": {
            "match": "\/\/.*",
            "name": "comment.line"
        },
        "type-primitive": {
            "name": "support.type.primitive.fs",
            "match": "\\b(bool|bytes|constraint|duration|float|int|latlng|list|number|map|string|timestamp|path|request)\\b"
        },
        "type-builtin-literals": {
            "name": "support.type.builtin.fs",
            "match": "\\b(true|false|null|undefined)\\b"
        },
        "version": {
            "name": "comment.block.documentation.fs",
            "match": "rules_version?\\s*=?\\s*'\\d'?\\s*;"
        },
        "firestore-root": {
            "name": "meta.root.fs",
            "begin": "(service)\\s+(cloud|firebase)\\.(firestore|storage)\\s*{",
            "beginCaptures": {
                "1": {
                    "name": "keyword.control.fs"
                },
                "2": {
                    "name": "keyword.control.fs"
                },
                "3": {
                    "name": "storage.type.class.fs"
                }
            },
            "end": "\\}",
            "patterns": [
                {
                    "include": "#matcher"
                },
                {
                    "include": "#function-declaration"
                },
                {
                    "include": "#comments"
                }
            ]
        },
        "matcher": {
            "name": "meta.matcher.fs",
            "begin": "match",
            "beginCaptures": {
                "0": {
                    "name": "keyword.control.fs"
                }
            },
            "end": "\\}",
            "patterns": [
                {
                    "include": "#matcher"
                },
                {
                    "include": "#matcher-path"
                },
                {
                    "include": "#function-declaration"
                },
                {
                    "include": "#allow-statement"
                },
                {
                    "include": "#comments"
                }
            ]
        },
        "matcher-path": {
            "name": "string.unquoted.fs",
            "begin": "(?<=match) \\/",
            "end": " ",
            "patterns": [
                {
                    "include": "#matcher-param"
                }
            ]
        },
        "matcher-param": {
            "name": "variable.parameter.fs",
            "begin": "\\{\\w+",
            "end": "\\}"
        },
        "function-declaration": {
            "name": "meta.function.fs",
            "begin": "(function)\\s+(\\w+)\\s?(\\()([^)]*)(\\))\\s*\\{",
            "beginCaptures": {
                "1": {
                    "name": "storage.type.function.fs"
                },
                "2": {
                    "name": "support.function.fs"
                },
                "3": {
                    "name": "punctuation.definition.parameters.fs"
                },
                "4": {
                    "name": "variable.parameter.function.fs"
                },
                "5": {
                    "name": "punctuation.definition.parameters.fs"
                }
            },
            "end": "(?<!\\w)\\}",
            "patterns": [
                {
                    "include": "#function-expression"
                },
                {
                    "include": "#comments"
                },
                {
                    "include": "#variable-declaration"
                }
            ]
        },
        "function-expression": {
            "name": "meta.function.expression.fs",
            "begin": "return",
            "beginCaptures": {
                "0": {
                    "name": "keyword.control.return.fs"
                }
            },
            "end": "(?=\\})",
            "patterns": [
                {
                    "include": "#comments"
                },
                {
                    "include": "#expression"
                }
            ]
        },
        "variable-declaration": {
            "name": "meta.variable.declaration.fs",
            "begin": "(let)\\s+(\\w+)\\s+=",
            "beginCaptures": {
                "1": {
                    "name": "storage.type.fs"
                },
                "2": {
                    "name": "variable.other.fs"
                }
            },
            "end": "(?=(let|return))",
            "patterns": [
                {
                    "include": "#expression"
                }
            ]
        },
        "allow-statement": {
            "name": "meta.allow.fs",
            "begin": "(allow)",
            "beginCaptures": {
                "1": {
                    "name": "storage.type.function.fs"
                }
            },
            "end": "\\;|(?=allow)|(?=match)|(?=\\})",
            "patterns": [
                {
                    "include": "#allow-head"
                },
                {
                    "include": "#allow-body"
                },
                {
                    "include": "#comments"
                }
            ]
        },
        "allow-body": {
            "name": "meta.allow.body.fs",
            "begin": "\\:",
            "end": "(?=\\;)|(?=allow)|(?=match)|(?=\\})",
            "patterns": [
                {
                    "include": "#allow-if-statement"
                }
            ]
        },
        "allow-if-statement": {
            "name": "meta.allow.body.if.fs",
            "begin": "(if)",
            "beginCaptures": {
                "1": {
                    "name": "keyword.control.fs"
                }
            },
            "end": "(?=\\;)|(?=allow)|(?=match)|(?=\\})",
            "patterns": [
                {
                    "include": "#expression"
                }
            ]
        },
        "allow-head": {
            "name": "meta.allow.head.fs",
            "begin": "(?<=allow)",
            "end": "(?=\\:)|(?=\\/\\/)|(?=\\;)|(?=allow)|(?=match)",
            "patterns": [
                {
                    "include": "#allow-scope"
                }
            ]
        },
        "allow-scope": {
            "name": "meta.allow.scope.fs",
            "match": "\\s+((write|read|get|list|update|delete|create)(\\s*,\\s*(write|read|get|list|update|delete|create))*)\\s*",
            "captures": {
                "1": {
                    "name": "support.type.builtin.fs"
                },
                "2": {
                    "name": "support.type.builtin.fs"
                }
            }
        },
        "function-call": {
            "name": "meta.functioncall.fs",
            "begin": "(\\w+)\\(",
            "beginCaptures": {
                "1": {
                    "name": "support.function.fs"
                }
            },
            "end": "\\)",
            "patterns": [
                {
                    "include": "#strings"
                },
                {
                    "include": "#identifiers"
                },
                {
                    "name": "variable.parameter.functioncall.fs",
                    "match": "(?<=[\\(,])\\s*(\\w|\\.)+\\s*(?=[\\),])"
                }
            ]
        },
        "operators": {
            "name": "keyword.operator.firestorerules",
            "match": "(==|!=|&&|is(?= )|\\|{2}|<=|>=|<|>|!)"
        },
        "strings": {
            "patterns": [
                {
                    "include": "#strings-quoted"
                },
                {
                    "name": "string.unquoted.firestorerules",
                    "match": "\\/\\w((\\w|\\/)*)(?=\\W)",
                    "patterns": [
                        {
                            "name": "constant.character.escape.firestorerules",
                            "match": "\\\\."
                        }
                    ]
                }
            ]
        },
        "strings-quoted": {
            "name": "string.quoted.firestorerules",
            "begin": "\\\"|'",
            "end": "\\\"|'",
            "patterns": [
                {
                    "name": "constant.character.escape.firestorerules",
                    "match": "\\\\."
                }
            ]
        },
        "expression": {
            "patterns": [
                {
                    "include": "#paren-expression"
                },
                {
                    "include": "#operators"
                },
                {
                    "include": "#type-primitive"
                },
                {
                    "include": "#type-builtin-literals"
                },
                {
                    "include": "#function-call"
                },
                {
                    "include": "#identifiers"
                },
                {
                    "include": "#strings"
                },
                {
                    "include": "#comments"
                }
            ]
        },
        "paren-expression": {
            "paren-expression": {
                "begin": "\\(",
                "beginCaptures": {
                    "0": {
                        "name": "meta.brace.round.fs"
                    }
                },
                "end": "\\)",
                "endCaptures": {
                    "0": {
                        "name": "meta.brace.round.fs"
                    }
                },
                "patterns": [
                    {
                        "include": "#expression"
                    }
                ]
            }
        },
        "identifiers": {
            "patterns": [
                {
                    "name": "variable.parameter.fs",
                    "match": "([_$[:alpha:]][_$[:alnum:]]*)"
                }
            ]
        }
    }
}