// Highlighter rules based on Ace Editor <https://github.com/ajaxorg/ace/blob/master/lib/ace/mode/c_cpp_highlight_rules.js>
// made by David Parreño Barbuzano <david.parreno101@alu.ulpgc.es>
{
    "name": "c-tokenizer",
    "extension": [ ".c", ".h" ],
    "check_rules": false,
    "inherit_rules": "text_tokenizer_rules",
    "states": {
        "start": [
            {
                "token": "comment.line",
                "regex": "\\/\\/$",
                "next": "start"
            },
            {
                "token": "comment",
                "regex": "\\/\\/",
                "next": "singleLineComment"
            },
            {
                "token": "comment.block",
                "regex": "\\/\\*(\\*?)",
                "next": "multipleLineComment"
            },
            {
                "token": "string",
                "regex": "'(?:\\\\(?:['\"?\\\\abfnrtv]|[0-7]{1,3}|x[a-fA-F\\d]{2}|u[a-fA-F\\d]{4}U[a-fA-F\\d]{8}|.)|.)?'"
            },
            {
                "token": "string",
                "regex": "\"",
                "next": "qqstring"
            },
            {
                "token": "string",
                "regex": "R\"\\(",
                "next": "rawString"
            },
            {
                "token": "constant.numeric",
                "regex": "0[xX][0-9a-fA-F]+(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b"
            },
            {
                "token": "constant.numeric",
                "regex": "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b"
            },
            {
                "token": "keyword",
                "regex": "#\\s*(?:include|pragma|line|undef|ifdef|define|ifndef)\\b",
                "next": "directive"
            },
            {
                "token": "keyword",
                "regex": "#\\s*(?:endif|if|else|elif)\\b"
            },
            {
                "token": "support.function",
                "regex": "\\b(?:hypot(?:f|l)?|s(?:scanf|ystem|nprintf|ca(?:nf|lb(?:n(?:f|l)?|ln(?:f|l)?))|i(?:n(?:h(?:f|l)?|f|l)?|gn(?:al|bit))|tr(?:s(?:tr|pn)|nc(?:py|at|mp)|c(?:spn|hr|oll|py|at|mp)|to(?:imax|d|u(?:l(?:l)?|max)|k|f|l(?:d|l)?)|error|pbrk|ftime|len|rchr|xfrm)|printf|et(?:jmp|vbuf|locale|buf)|qrt(?:f|l)?|w(?:scanf|printf)|rand)|n(?:e(?:arbyint(?:f|l)?|xt(?:toward(?:f|l)?|after(?:f|l)?))|an(?:f|l)?)|c(?:s(?:in(?:h(?:f|l)?|f|l)?|qrt(?:f|l)?)|cos(?:h(?:f)?|f|l)?|imag(?:f|l)?|t(?:ime|an(?:h(?:f|l)?|f|l)?)|o(?:s(?:h(?:f|l)?|f|l)?|nj(?:f|l)?|pysign(?:f|l)?)|p(?:ow(?:f|l)?|roj(?:f|l)?)|e(?:il(?:f|l)?|xp(?:f|l)?)|l(?:o(?:ck|g(?:f|l)?)|earerr)|a(?:sin(?:h(?:f|l)?|f|l)?|cos(?:h(?:f|l)?|f|l)?|tan(?:h(?:f|l)?|f|l)?|lloc|rg(?:f|l)?|bs(?:f|l)?)|real(?:f|l)?|brt(?:f|l)?)|t(?:ime|o(?:upper|lower)|an(?:h(?:f|l)?|f|l)?|runc(?:f|l)?|gamma(?:f|l)?|mp(?:nam|file))|i(?:s(?:space|n(?:ormal|an)|cntrl|inf|digit|u(?:nordered|pper)|p(?:unct|rint)|finite|w(?:space|c(?:ntrl|type)|digit|upper|p(?:unct|rint)|lower|al(?:num|pha)|graph|xdigit|blank)|l(?:ower|ess(?:equal|greater)?)|al(?:num|pha)|gr(?:eater(?:equal)?|aph)|xdigit|blank)|logb(?:f|l)?|max(?:div|abs))|di(?:v|fftime)|_Exit|unget(?:c|wc)|p(?:ow(?:f|l)?|ut(?:s|c(?:har)?|wc(?:har)?)|error|rintf)|e(?:rf(?:c(?:f|l)?|f|l)?|x(?:it|p(?:2(?:f|l)?|f|l|m1(?:f|l)?)?))|v(?:s(?:scanf|nprintf|canf|printf|w(?:scanf|printf))|printf|f(?:scanf|printf|w(?:scanf|printf))|w(?:scanf|printf)|a_(?:start|copy|end|arg))|qsort|f(?:s(?:canf|e(?:tpos|ek))|close|tell|open|dim(?:f|l)?|p(?:classify|ut(?:s|c|w(?:s|c))|rintf)|e(?:holdexcept|set(?:e(?:nv|xceptflag)|round)|clearexcept|testexcept|of|updateenv|r(?:aiseexcept|ror)|get(?:e(?:nv|xceptflag)|round))|flush|w(?:scanf|ide|printf|rite)|loor(?:f|l)?|abs(?:f|l)?|get(?:s|c|pos|w(?:s|c))|re(?:open|e|ad|xp(?:f|l)?)|m(?:in(?:f|l)?|od(?:f|l)?|a(?:f|l|x(?:f|l)?)?))|l(?:d(?:iv|exp(?:f|l)?)|o(?:ngjmp|cal(?:time|econv)|g(?:1(?:p(?:f|l)?|0(?:f|l)?)|2(?:f|l)?|f|l|b(?:f|l)?)?)|abs|l(?:div|abs|r(?:int(?:f|l)?|ound(?:f|l)?))|r(?:int(?:f|l)?|ound(?:f|l)?)|gamma(?:f|l)?)|w(?:scanf|c(?:s(?:s(?:tr|pn)|nc(?:py|at|mp)|c(?:spn|hr|oll|py|at|mp)|to(?:imax|d|u(?:l(?:l)?|max)|k|f|l(?:d|l)?|mbs)|pbrk|ftime|len|r(?:chr|tombs)|xfrm)|to(?:b|mb)|rtomb)|printf|mem(?:set|c(?:hr|py|mp)|move))|a(?:s(?:sert|ctime|in(?:h(?:f|l)?|f|l)?)|cos(?:h(?:f|l)?|f|l)?|t(?:o(?:i|f|l(?:l)?)|exit|an(?:h(?:f|l)?|2(?:f|l)?|f|l)?)|b(?:s|ort))|g(?:et(?:s|c(?:har)?|env|wc(?:har)?)|mtime)|r(?:int(?:f|l)?|ound(?:f|l)?|e(?:name|alloc|wind|m(?:ove|quo(?:f|l)?|ainder(?:f|l)?))|a(?:nd|ise))|b(?:search|towc)|m(?:odf(?:f|l)?|em(?:set|c(?:hr|py|mp)|move)|ktime|alloc|b(?:s(?:init|towcs|rtowcs)|towc|len|r(?:towc|len))))\\b"
            },
            {
                "token": "keyword.control",
                "regex": "(?:break|case|continue|default|do|else|for|goto|if|_Pragma|return|switch|while)\\b"
            },
            {
                "token": "storage.modifier",
                "regex":  "(?:const|extern|static|volatile|inline)\\b"
            },
            {
                "token": "storage.type",
                "regex": "(?:bool|_Bool|size_t|char|double|float|long|short|typedef|int|enum|struct|signed|unsigned|void|int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|_Complex|_Imaginary)\\b"
            },
            {
                "token": "keyword.operator",
                "regex": "(?:sizeof)\\b"
            },
            {
                "token": "constant.language",
                "regex": "(?:NULL|true|false|TRUE|FALSE)\\b"
            },
            {
                "token": "identifier",
                "regex": "[a-zA-Z_$][a-zA-Z0-9_$]*"
            },
            {
                "token": "keyword.operator",
                "regex": "--|\\+\\+|<<=|>>=|>>>=|<>|&&|\\|\\||\\?:|\\->|[*%\\/\\+\\-&\\^|~!<>=]=?"
            },
            {
                "token": "keyword.operator",
                "regex": "\\?:|,|;|\\."
            },
            {
                "token": "paren.lparen",
                "regex": "[[({]"
            },
            {
                "token": "paren.rparen",
                "regex": "[\\])}]"
            },
            {
                "token": "text",
                "regex": "\\s+"
            }
        ],
        "qqstring": [
            {
                "token": "string",
                "regex": "\\\\s*$",
                "next": "qqstring"
            },
            {
                "token": "constant.language.escape",
                "regex": "\\\\(?: ['\"?\\abfnrtv]|[0-7]{1,3}|x[a-fA-F\\d]{2}|u[a-fA-F\\d]{4}U[a-fA-F\\d]{8}|.)"
            },
            {
                "token": "constant.language.escape",
                "regex": "%(\\d+\\$)?[#0\\- +']*[,;:_]?((-?\\d+)|\\*(-?\\d+\\$)?)?(\\.((-?\\d+)|\\*(-?\\d+\\$)?)?)?(hh|h|ll|l|j|t|z|q|L|vh|vl|v|hv|hl)?(\\[[^\"\\]]+\\]|[diouxXDOUeEfFgGaACcSspn%])"
            },
            {
                "token": "string",
                "regex": "\"|$",
                "next": "start"
            },
            {
                "default_token": "string"
            }
        ],
        "rawString": [
            {
                "token": "string",
                "regex": "\\)\"",
                "next": "start"
            },
            {
                "default_token": "string"
            }
        ],
        "singleLineComment": [
            {
                "token": "comment.line",
                "regex": "\\$",
                "next": "singleLineComment"
            },
            {
                "token": "comment.line",
                "regex": "$",
                "next": "start"
            },
            {
                "default_token": "comment.line"
            }
        ],
        "multipleLineComment": [
            {
                "token": "comment.block",
                "regex": "\\*\\/",
                "next": "start"
            },
            {
                "default_token": "comment.block"
            }
        ],
        "directive": [
            {
                "token": "constant.other",
                "regex": "\\\\"
            },
            {
                "token": "constant.other",
                "regex": ".*\\\\"
            },
            {
                "token": "constant.other",
                "regex": "\\s*<.+?>",
                "next": "start"
            },
            {
                "token": "constant.other",
                "regex": "\\s*[\"](?:(?:\\\\.)|(?:[^\"\\\\]))*?[\"]",
                "next": "start"
            },
            {
                "token": "constant.other",
                "regex": "\\s*['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']",
                "next": "start"
            },
            {
                "token": "constant.other",
                "regex": "[^\\\\\\/]+",
                "next": "start"
            }
        ]
    }
}