tree-sitter-json
Advanced tools
Comparing version 0.20.0 to 0.20.1
109
grammar.js
@@ -0,1 +1,13 @@ | ||
/** | ||
* @file JSON grammar for tree-sitter | ||
* @author Max Brunsfeld | ||
* @license MIT | ||
*/ | ||
/* eslint-disable arrow-parens */ | ||
/* eslint-disable camelcase */ | ||
/* eslint-disable-next-line spaced-comment */ | ||
/// <reference types="tree-sitter-cli/dsl" /> | ||
// @ts-check | ||
module.exports = grammar({ | ||
@@ -10,7 +22,7 @@ name: 'json', | ||
supertypes: $ => [ | ||
$._value | ||
$._value, | ||
], | ||
rules: { | ||
document: $ => $._value, | ||
document: $ => repeat($._value), | ||
@@ -24,17 +36,17 @@ _value: $ => choice( | ||
$.false, | ||
$.null | ||
$.null, | ||
), | ||
object: $ => seq( | ||
"{", commaSep($.pair), "}" | ||
'{', commaSep($.pair), '}', | ||
), | ||
pair: $ => seq( | ||
field("key", choice($.string, $.number)), | ||
":", | ||
field("value", $._value) | ||
field('key', choice($.string, $.number)), | ||
':', | ||
field('value', $._value), | ||
), | ||
array: $ => seq( | ||
"[", commaSep($._value), "]" | ||
'[', commaSep($._value), ']', | ||
), | ||
@@ -44,58 +56,43 @@ | ||
seq('"', '"'), | ||
seq('"', $.string_content, '"') | ||
seq('"', $.string_content, '"'), | ||
), | ||
string_content: $ => repeat1(choice( | ||
token.immediate(/[^\\"\n]+/), | ||
$.escape_sequence | ||
token.immediate(prec(1, /[^\\"\n]+/)), | ||
$.escape_sequence, | ||
)), | ||
escape_sequence: $ => token.immediate(seq( | ||
escape_sequence: _ => token.immediate(seq( | ||
'\\', | ||
/(\"|\\|\/|b|f|n|r|t|u)/ | ||
/(\"|\\|\/|b|f|n|r|t|u)/, | ||
)), | ||
number: $ => { | ||
const hex_literal = seq( | ||
choice('0x', '0X'), | ||
/[\da-fA-F]+/ | ||
) | ||
number: _ => { | ||
const decimal_digits = /\d+/; | ||
const signed_integer = seq(optional('-'), decimal_digits); | ||
const exponent_part = seq(choice('e', 'E'), signed_integer); | ||
const decimal_digits = /\d+/ | ||
const signed_integer = seq(optional(choice('-', '+')), decimal_digits) | ||
const exponent_part = seq(choice('e', 'E'), signed_integer) | ||
const binary_literal = seq(choice('0b', '0B'), /[0-1]+/) | ||
const octal_literal = seq(choice('0o', '0O'), /[0-7]+/) | ||
const decimal_integer_literal = seq( | ||
optional(choice('-', '+')), | ||
optional('-'), | ||
choice( | ||
'0', | ||
seq(/[1-9]/, optional(decimal_digits)) | ||
) | ||
) | ||
seq(/[1-9]/, optional(decimal_digits)), | ||
), | ||
); | ||
const decimal_literal = choice( | ||
seq(decimal_integer_literal, '.', optional(decimal_digits), optional(exponent_part)), | ||
seq('.', decimal_digits, optional(exponent_part)), | ||
seq(decimal_integer_literal, optional(exponent_part)) | ||
) | ||
seq(decimal_integer_literal, optional(exponent_part)), | ||
); | ||
return token(choice( | ||
hex_literal, | ||
decimal_literal, | ||
binary_literal, | ||
octal_literal | ||
)) | ||
return token(decimal_literal); | ||
}, | ||
true: $ => "true", | ||
true: _ => 'true', | ||
false: $ => "false", | ||
false: _ => 'false', | ||
null: $ => "null", | ||
null: _ => 'null', | ||
comment: $ => token(choice( | ||
comment: _ => token(choice( | ||
seq('//', /.*/), | ||
@@ -105,14 +102,30 @@ seq( | ||
/[^*]*\*+([^/*][^*]*\*+)*/, | ||
'/' | ||
) | ||
'/', | ||
), | ||
)), | ||
} | ||
}, | ||
}); | ||
/** | ||
* Creates a rule to match one or more of the rules separated by a comma | ||
* | ||
* @param {RuleOrLiteral} rule | ||
* | ||
* @return {SeqRule} | ||
* | ||
*/ | ||
function commaSep1(rule) { | ||
return seq(rule, repeat(seq(",", rule))) | ||
return seq(rule, repeat(seq(',', rule))); | ||
} | ||
/** | ||
* Creates a rule to optionally match one or more of the rules separated by a comma | ||
* | ||
* @param {RuleOrLiteral} rule | ||
* | ||
* @return {ChoiceRule} | ||
* | ||
*/ | ||
function commaSep(rule) { | ||
return optional(commaSep1(rule)) | ||
return optional(commaSep1(rule)); | ||
} |
{ | ||
"name": "tree-sitter-json", | ||
"version": "0.20.0", | ||
"version": "0.20.1", | ||
"description": "JSON grammar for tree-sitter", | ||
@@ -8,2 +8,3 @@ "main": "bindings/node", | ||
"parser", | ||
"lexer", | ||
"json" | ||
@@ -14,9 +15,12 @@ ], | ||
"dependencies": { | ||
"nan": "^2.14.1" | ||
"nan": "^2.18.0" | ||
}, | ||
"devDependencies": { | ||
"tree-sitter-cli": "^0.19.1" | ||
"eslint": ">=8.50.0", | ||
"eslint-config-google": "^0.14.0", | ||
"tree-sitter-cli": "^0.20.8" | ||
}, | ||
"scripts": { | ||
"build": "tree-sitter generate && node-gyp build", | ||
"lint": "eslint grammar.js", | ||
"test": "tree-sitter test" | ||
@@ -29,2 +33,5 @@ }, | ||
"json" | ||
], | ||
"highlights": [ | ||
"queries/highlights.scm" | ||
] | ||
@@ -31,0 +38,0 @@ } |
@@ -1,6 +0,5 @@ | ||
tree-sitter-json | ||
=========================== | ||
# tree-sitter-json | ||
[![Build/test](https://github.com/tree-sitter/tree-sitter-json/actions/workflows/ci.yml/badge.svg)](https://github.com/tree-sitter/tree-sitter-json/actions/workflows/ci.yml) | ||
[![CI](https://github.com/tree-sitter/tree-sitter-json/actions/workflows/ci.yml/badge.svg)](https://github.com/tree-sitter/tree-sitter-json/actions/workflows/ci.yml) | ||
JSON grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter) |
@@ -5,4 +5,7 @@ { | ||
"document": { | ||
"type": "SYMBOL", | ||
"name": "_value" | ||
"type": "REPEAT", | ||
"content": { | ||
"type": "SYMBOL", | ||
"name": "_value" | ||
} | ||
}, | ||
@@ -211,4 +214,8 @@ "_value": { | ||
"content": { | ||
"type": "PATTERN", | ||
"value": "[^\\\\\"\\n]+" | ||
"type": "PREC", | ||
"value": 1, | ||
"content": { | ||
"type": "PATTERN", | ||
"value": "[^\\\\\"\\n]+" | ||
} | ||
} | ||
@@ -248,75 +255,39 @@ }, | ||
{ | ||
"type": "CHOICE", | ||
"type": "SEQ", | ||
"members": [ | ||
{ | ||
"type": "STRING", | ||
"value": "0x" | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "STRING", | ||
"value": "-" | ||
}, | ||
{ | ||
"type": "BLANK" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "STRING", | ||
"value": "0X" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "PATTERN", | ||
"value": "[\\da-fA-F]+" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "SEQ", | ||
"members": [ | ||
{ | ||
"type": "SEQ", | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "STRING", | ||
"value": "-" | ||
}, | ||
{ | ||
"type": "STRING", | ||
"value": "+" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "BLANK" | ||
} | ||
] | ||
"type": "STRING", | ||
"value": "0" | ||
}, | ||
{ | ||
"type": "CHOICE", | ||
"type": "SEQ", | ||
"members": [ | ||
{ | ||
"type": "STRING", | ||
"value": "0" | ||
"type": "PATTERN", | ||
"value": "[1-9]" | ||
}, | ||
{ | ||
"type": "SEQ", | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "PATTERN", | ||
"value": "[1-9]" | ||
"value": "\\d+" | ||
}, | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "PATTERN", | ||
"value": "\\d+" | ||
}, | ||
{ | ||
"type": "BLANK" | ||
} | ||
] | ||
"type": "BLANK" | ||
} | ||
@@ -328,23 +299,41 @@ ] | ||
] | ||
}, | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "STRING", | ||
"value": "." | ||
}, | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "STRING", | ||
"value": "." | ||
"type": "PATTERN", | ||
"value": "\\d+" | ||
}, | ||
{ | ||
"type": "CHOICE", | ||
"type": "BLANK" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "SEQ", | ||
"members": [ | ||
{ | ||
"type": "PATTERN", | ||
"value": "\\d+" | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "STRING", | ||
"value": "e" | ||
}, | ||
{ | ||
"type": "STRING", | ||
"value": "E" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "BLANK" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "SEQ", | ||
@@ -357,7 +346,6 @@ "members": [ | ||
"type": "STRING", | ||
"value": "e" | ||
"value": "-" | ||
}, | ||
{ | ||
"type": "STRING", | ||
"value": "E" | ||
"type": "BLANK" | ||
} | ||
@@ -367,40 +355,19 @@ ] | ||
{ | ||
"type": "SEQ", | ||
"members": [ | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "STRING", | ||
"value": "-" | ||
}, | ||
{ | ||
"type": "STRING", | ||
"value": "+" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "BLANK" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "PATTERN", | ||
"value": "\\d+" | ||
} | ||
] | ||
"type": "PATTERN", | ||
"value": "\\d+" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "BLANK" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "BLANK" | ||
} | ||
] | ||
}, | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "SEQ", | ||
"members": [ | ||
{ | ||
@@ -410,55 +377,36 @@ "type": "SEQ", | ||
{ | ||
"type": "STRING", | ||
"value": "." | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "STRING", | ||
"value": "-" | ||
}, | ||
{ | ||
"type": "BLANK" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "PATTERN", | ||
"value": "\\d+" | ||
}, | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "STRING", | ||
"value": "0" | ||
}, | ||
{ | ||
"type": "SEQ", | ||
"members": [ | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "STRING", | ||
"value": "e" | ||
}, | ||
{ | ||
"type": "STRING", | ||
"value": "E" | ||
} | ||
] | ||
"type": "PATTERN", | ||
"value": "[1-9]" | ||
}, | ||
{ | ||
"type": "SEQ", | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "STRING", | ||
"value": "-" | ||
}, | ||
{ | ||
"type": "STRING", | ||
"value": "+" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "BLANK" | ||
} | ||
] | ||
"type": "PATTERN", | ||
"value": "\\d+" | ||
}, | ||
{ | ||
"type": "PATTERN", | ||
"value": "\\d+" | ||
"type": "BLANK" | ||
} | ||
@@ -468,5 +416,2 @@ ] | ||
] | ||
}, | ||
{ | ||
"type": "BLANK" | ||
} | ||
@@ -478,3 +423,3 @@ ] | ||
{ | ||
"type": "SEQ", | ||
"type": "CHOICE", | ||
"members": [ | ||
@@ -488,16 +433,8 @@ { | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "STRING", | ||
"value": "-" | ||
}, | ||
{ | ||
"type": "STRING", | ||
"value": "+" | ||
} | ||
] | ||
"type": "STRING", | ||
"value": "e" | ||
}, | ||
{ | ||
"type": "BLANK" | ||
"type": "STRING", | ||
"value": "E" | ||
} | ||
@@ -507,37 +444,2 @@ ] | ||
{ | ||
"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", | ||
@@ -550,7 +452,6 @@ "members": [ | ||
"type": "STRING", | ||
"value": "e" | ||
"value": "-" | ||
}, | ||
{ | ||
"type": "STRING", | ||
"value": "E" | ||
"type": "BLANK" | ||
} | ||
@@ -560,85 +461,15 @@ ] | ||
{ | ||
"type": "SEQ", | ||
"members": [ | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "STRING", | ||
"value": "-" | ||
}, | ||
{ | ||
"type": "STRING", | ||
"value": "+" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "BLANK" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "PATTERN", | ||
"value": "\\d+" | ||
} | ||
] | ||
"type": "PATTERN", | ||
"value": "\\d+" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "BLANK" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "SEQ", | ||
"members": [ | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "STRING", | ||
"value": "0b" | ||
}, | ||
{ | ||
"type": "STRING", | ||
"value": "0B" | ||
"type": "BLANK" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "PATTERN", | ||
"value": "[0-1]+" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "SEQ", | ||
"members": [ | ||
{ | ||
"type": "CHOICE", | ||
"members": [ | ||
{ | ||
"type": "STRING", | ||
"value": "0o" | ||
}, | ||
{ | ||
"type": "STRING", | ||
"value": "0O" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "PATTERN", | ||
"value": "[0-7]+" | ||
} | ||
] | ||
} | ||
@@ -645,0 +476,0 @@ ] |
@@ -56,4 +56,4 @@ [ | ||
"children": { | ||
"multiple": false, | ||
"required": true, | ||
"multiple": true, | ||
"required": false, | ||
"types": [ | ||
@@ -60,0 +60,0 @@ { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75182
27
3
869
6
Updatednan@^2.18.0