diff --git a/queries/highlights.scm b/queries/highlights.scm index 8ee11890..7574bd09 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -51,11 +51,13 @@ "==" @operator ">" @operator "||" @operator +"##" @operator "." @delimiter ";" @delimiter (string_literal) @string +(stringification) @keyword (system_lib_string) @string (null) @constant diff --git a/src/grammar.json b/src/grammar.json index a3bd880e..af0acefd 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -1,7 +1,7 @@ { "$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json", "name": "c", - "word": "identifier", + "word": "_preproc_token", "rules": { "translation_unit": { "type": "REPEAT", @@ -1933,8 +1933,46 @@ "type": "PREC", "value": -1, "content": { - "type": "PATTERN", - "value": "\\S([^/\\n]|\\/[^*]|\\\\\\r?\\n)*" + "type": "SEQ", + "members": [ + { + "type": "PATTERN", + "value": "\\S([^/\\n]|\\/[^*]|\\\\\\r?\\n)*" + }, + { + "type": "REPEAT", + "content": { + "type": "SEQ", + "members": [ + { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "/*" + }, + { + "type": "PATTERN", + "value": "[^*]*\\*+([^/*][^*]*\\*+)*" + }, + { + "type": "STRING", + "value": "/" + }, + { + "type": "PATTERN", + "value": "([ \t]|\\\\\\r?\\n)*" + } + ] + }, + { + "type": "PATTERN", + "value": "\\S([^/\\n]|\\/[^*]|\\\\\\r?\\n)*" + } + ] + } + } + ] } } }, @@ -9339,67 +9377,80 @@ } }, "string_literal": { - "type": "SEQ", + "type": "CHOICE", "members": [ { - "type": "CHOICE", + "type": "SYMBOL", + "name": "stringification" + }, + { + "type": "SEQ", "members": [ { - "type": "STRING", - "value": "L\"" - }, - { - "type": "STRING", - "value": "u\"" - }, - { - "type": "STRING", - "value": "U\"" + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "L\"" + }, + { + "type": "STRING", + "value": "u\"" + }, + { + "type": "STRING", + "value": "U\"" + }, + { + "type": "STRING", + "value": "u8\"" + }, + { + "type": "STRING", + "value": "\"" + } + ] }, { - "type": "STRING", - "value": "u8\"" + "type": "REPEAT", + "content": { + "type": "CHOICE", + "members": [ + { + "type": "ALIAS", + "content": { + "type": "IMMEDIATE_TOKEN", + "content": { + "type": "PREC", + "value": 1, + "content": { + "type": "PATTERN", + "value": "[^\\\\\"\\n]+" + } + } + }, + "named": true, + "value": "string_content" + }, + { + "type": "SYMBOL", + "name": "escape_sequence" + } + ] + } }, { "type": "STRING", "value": "\"" } ] - }, - { - "type": "REPEAT", - "content": { - "type": "CHOICE", - "members": [ - { - "type": "ALIAS", - "content": { - "type": "IMMEDIATE_TOKEN", - "content": { - "type": "PREC", - "value": 1, - "content": { - "type": "PATTERN", - "value": "[^\\\\\"\\n]+" - } - } - }, - "named": true, - "value": "string_content" - }, - { - "type": "SYMBOL", - "name": "escape_sequence" - } - ] - } - }, - { - "type": "STRING", - "value": "\"" } ] }, + "stringification": { + "type": "PATTERN", + "value": "#[_a-zA-Z]\\w*" + }, "escape_sequence": { "type": "TOKEN", "content": { @@ -9518,10 +9569,25 @@ } ] }, - "identifier": { + "_preproc_token": { "type": "PATTERN", "value": "(\\p{XID_Start}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\\\U[0-9A-Fa-f]{8})(\\p{XID_Continue}|\\$|\\\\u[0-9A-Fa-f]{4}|\\\\U[0-9A-Fa-f]{8})*" }, + "identifier": { + "type": "SEQ", + "members": [ + { "type": "SYMBOL", "name": "_preproc_token" }, + { + "type": "REPEAT", "content": { + "type": "SEQ", + "members": [ + { "type": "STRING", "value": "##" }, + { "type": "SYMBOL", "name": "_preproc_token" } + ] + } + } + ] + }, "_type_identifier": { "type": "ALIAS", "content": {