UNPKG

@rtinternal/tree-sitter-json

Version:

[Fork of tree-sitter/tree-sitter-json] JSON grammar for tree-sitter

531 lines (530 loc) 12.9 kB
{ "$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json", "name": "json", "rules": { "document": { "type": "REPEAT", "content": { "type": "SYMBOL", "name": "_value" } }, "_value": { "type": "CHOICE", "members": [ { "type": "SYMBOL", "name": "object" }, { "type": "SYMBOL", "name": "array" }, { "type": "SYMBOL", "name": "number" }, { "type": "SYMBOL", "name": "string" }, { "type": "SYMBOL", "name": "true" }, { "type": "SYMBOL", "name": "false" }, { "type": "SYMBOL", "name": "null" } ] }, "object": { "type": "SEQ", "members": [ { "type": "STRING", "value": "{" }, { "type": "CHOICE", "members": [ { "type": "SEQ", "members": [ { "type": "SYMBOL", "name": "pair" }, { "type": "REPEAT", "content": { "type": "SEQ", "members": [ { "type": "STRING", "value": "," }, { "type": "SYMBOL", "name": "pair" } ] } } ] }, { "type": "BLANK" } ] }, { "type": "STRING", "value": "}" } ] }, "pair": { "type": "SEQ", "members": [ { "type": "FIELD", "name": "key", "content": { "type": "SYMBOL", "name": "string" } }, { "type": "STRING", "value": ":" }, { "type": "FIELD", "name": "value", "content": { "type": "SYMBOL", "name": "_value" } } ] }, "array": { "type": "SEQ", "members": [ { "type": "STRING", "value": "[" }, { "type": "CHOICE", "members": [ { "type": "SEQ", "members": [ { "type": "SYMBOL", "name": "_value" }, { "type": "REPEAT", "content": { "type": "SEQ", "members": [ { "type": "STRING", "value": "," }, { "type": "SYMBOL", "name": "_value" } ] } } ] }, { "type": "BLANK" } ] }, { "type": "STRING", "value": "]" } ] }, "string": { "type": "CHOICE", "members": [ { "type": "SEQ", "members": [ { "type": "STRING", "value": "\"" }, { "type": "STRING", "value": "\"" } ] }, { "type": "SEQ", "members": [ { "type": "STRING", "value": "\"" }, { "type": "SYMBOL", "name": "_string_content" }, { "type": "STRING", "value": "\"" } ] } ] }, "_string_content": { "type": "REPEAT1", "content": { "type": "CHOICE", "members": [ { "type": "SYMBOL", "name": "string_content" }, { "type": "SYMBOL", "name": "escape_sequence" } ] } }, "string_content": { "type": "IMMEDIATE_TOKEN", "content": { "type": "PREC", "value": 1, "content": { "type": "PATTERN", "value": "[^\\\\\"\\n]+" } } }, "escape_sequence": { "type": "IMMEDIATE_TOKEN", "content": { "type": "SEQ", "members": [ { "type": "STRING", "value": "\\" }, { "type": "PATTERN", "value": "(\\\"|\\\\|\\/|b|f|n|r|t|u)" } ] } }, "number": { "type": "TOKEN", "content": { "type": "CHOICE", "members": [ { "type": "SEQ", "members": [ { "type": "SEQ", "members": [ { "type": "CHOICE", "members": [ { "type": "STRING", "value": "-" }, { "type": "BLANK" } ] }, { "type": "CHOICE", "members": [ { "type": "STRING", "value": "0" }, { "type": "SEQ", "members": [ { "type": "PATTERN", "value": "[1-9]" }, { "type": "CHOICE", "members": [ { "type": "PATTERN", "value": "\\d+" }, { "type": "BLANK" } ] } ] } ] } ] }, { "type": "STRING", "value": "." }, { "type": "CHOICE", "members": [ { "type": "PATTERN", "value": "\\d+" }, { "type": "BLANK" } ] }, { "type": "CHOICE", "members": [ { "type": "SEQ", "members": [ { "type": "CHOICE", "members": [ { "type": "STRING", "value": "e" }, { "type": "STRING", "value": "E" } ] }, { "type": "SEQ", "members": [ { "type": "CHOICE", "members": [ { "type": "STRING", "value": "-" }, { "type": "BLANK" } ] }, { "type": "PATTERN", "value": "\\d+" } ] } ] }, { "type": "BLANK" } ] } ] }, { "type": "SEQ", "members": [ { "type": "SEQ", "members": [ { "type": "CHOICE", "members": [ { "type": "STRING", "value": "-" }, { "type": "BLANK" } ] }, { "type": "CHOICE", "members": [ { "type": "STRING", "value": "0" }, { "type": "SEQ", "members": [ { "type": "PATTERN", "value": "[1-9]" }, { "type": "CHOICE", "members": [ { "type": "PATTERN", "value": "\\d+" }, { "type": "BLANK" } ] } ] } ] } ] }, { "type": "CHOICE", "members": [ { "type": "SEQ", "members": [ { "type": "CHOICE", "members": [ { "type": "STRING", "value": "e" }, { "type": "STRING", "value": "E" } ] }, { "type": "SEQ", "members": [ { "type": "CHOICE", "members": [ { "type": "STRING", "value": "-" }, { "type": "BLANK" } ] }, { "type": "PATTERN", "value": "\\d+" } ] } ] }, { "type": "BLANK" } ] } ] } ] } }, "true": { "type": "STRING", "value": "true" }, "false": { "type": "STRING", "value": "false" }, "null": { "type": "STRING", "value": "null" }, "comment": { "type": "TOKEN", "content": { "type": "CHOICE", "members": [ { "type": "SEQ", "members": [ { "type": "STRING", "value": "//" }, { "type": "PATTERN", "value": ".*" } ] }, { "type": "SEQ", "members": [ { "type": "STRING", "value": "/*" }, { "type": "PATTERN", "value": "[^*]*\\*+([^/*][^*]*\\*+)*" }, { "type": "STRING", "value": "/" } ] } ] } } }, "extras": [ { "type": "PATTERN", "value": "\\s" }, { "type": "SYMBOL", "name": "comment" } ], "conflicts": [], "precedences": [], "externals": [], "inline": [], "supertypes": [ "_value" ] }