Compare commits

...

4 commits

Author SHA1 Message Date
Bruno BELANYI c5d3860a83 Release 0.1.1 2024-04-08 02:14:37 +01:00
Bruno BELANYI e508ac4554 Add 'bump-version' script 2024-04-08 02:14:21 +01:00
Bruno BELANYI 2cb15e1b5f Add 'operator' aliases 2024-04-08 02:13:43 +01:00
Bruno BELANYI 32da7a37a6 Add binary expression 2024-04-08 02:12:22 +01:00
10 changed files with 1364 additions and 971 deletions

View file

@ -1,7 +1,7 @@
[package]
name = "tree-sitter-blueprint"
description = "Blueprint grammar for the tree-sitter parsing library"
version = "0.1.0"
version = "0.1.1"
keywords = ["incremental", "parsing", "android", "blueprint"]
categories = ["parsing", "text-editors"]
repository = "https://git.belanyi.fr/ambroisie/tree-sitter-blueprint"

View file

@ -46,6 +46,20 @@
overlays = [ ];
};
bump-version = pkgs.writeShellScriptBin "bump-version" ''
set -eu
NEW_VERSION="''${1}"
${pkgs.jq}/bin/jq ".version = \"''${NEW_VERSION}\"" package.json > package.json.tmp
mv package.json.tmp package.json
${pkgs.gnused}/bin/sed -i -e "s/version = \"[0-9.]\\+\"/version = \"''${NEW_VERSION}\"/" Cargo.toml
git add Cargo.toml package.json
echo "Release ''${NEW_VERSION}" | git commit -eF -
git tag -a "v''${NEW_VERSION}" -m "Release ''${NEW_VERSION}"
'';
tree-sitter-env = pkgs.stdenv.mkDerivation {
name = "tree-sitter-env";
@ -96,6 +110,7 @@
devShells = {
default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
bump-version
nodejs
(tree-sitter.override { webUISupport = true; })
];

View file

@ -28,7 +28,7 @@ module.exports = grammar({
assignment: ($) => seq(
field("left", $.identifier),
field("operator", choice("=", "+=")),
field("operator", alias(choice("=", "+="), $.operator)),
field("right", $._expr),
),
@ -71,6 +71,8 @@ module.exports = grammar({
// Composites
$.list_expression,
$.map_expression,
// Operators
$.binary_expression,
),
// The Blueprint scanner makes use of Go's lexer, so copy their rule
@ -185,6 +187,12 @@ module.exports = grammar({
"}",
),
binary_expression: ($) => prec.left(seq(
field("left", $._expr),
field("operator", alias("+", $.operator)),
field("right", $._expr),
)),
// }}}
// Properties {{{

View file

@ -1,6 +1,6 @@
{
"name": "tree-sitter-blueprint",
"version": "0.1.0",
"version": "0.1.1",
"description": "Blueprint grammar for tree-sitter",
"main": "bindings/node",
"keywords": [

69
src/grammar.json generated
View file

@ -49,17 +49,22 @@
"type": "FIELD",
"name": "operator",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "STRING",
"value": "+="
}
]
"type": "ALIAS",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "STRING",
"value": "+="
}
]
},
"named": true,
"value": "operator"
}
},
{
@ -279,6 +284,10 @@
{
"type": "SYMBOL",
"name": "map_expression"
},
{
"type": "SYMBOL",
"name": "binary_expression"
}
]
},
@ -830,6 +839,44 @@
}
]
},
"binary_expression": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "left",
"content": {
"type": "SYMBOL",
"name": "_expr"
}
},
{
"type": "FIELD",
"name": "operator",
"content": {
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "+"
},
"named": true,
"value": "operator"
}
},
{
"type": "FIELD",
"name": "right",
"content": {
"type": "SYMBOL",
"name": "_expr"
}
}
]
}
},
"_colon_property": {
"type": "SEQ",
"members": [

136
src/node-types.json generated
View file

@ -18,12 +18,8 @@
"required": true,
"types": [
{
"type": "+=",
"named": false
},
{
"type": "=",
"named": false
"type": "operator",
"named": true
}
]
},
@ -31,6 +27,110 @@
"multiple": false,
"required": true,
"types": [
{
"type": "binary_expression",
"named": true
},
{
"type": "boolean_literal",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "integer_literal",
"named": true
},
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "list_expression",
"named": true
},
{
"type": "map_expression",
"named": true
},
{
"type": "raw_string_literal",
"named": true
},
{
"type": "select_expression",
"named": true
}
]
}
}
},
{
"type": "binary_expression",
"named": true,
"fields": {
"left": {
"multiple": false,
"required": true,
"types": [
{
"type": "binary_expression",
"named": true
},
{
"type": "boolean_literal",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "integer_literal",
"named": true
},
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "list_expression",
"named": true
},
{
"type": "map_expression",
"named": true
},
{
"type": "raw_string_literal",
"named": true
},
{
"type": "select_expression",
"named": true
}
]
},
"operator": {
"multiple": false,
"required": true,
"types": [
{
"type": "operator",
"named": true
}
]
},
"right": {
"multiple": false,
"required": true,
"types": [
{
"type": "binary_expression",
"named": true
},
{
"type": "boolean_literal",
"named": true
@ -95,6 +195,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "binary_expression",
"named": true
},
{
"type": "boolean_literal",
"named": true
@ -163,6 +267,10 @@
"multiple": true,
"required": false,
"types": [
{
"type": "binary_expression",
"named": true
},
{
"type": "boolean_literal",
"named": true
@ -269,6 +377,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "binary_expression",
"named": true
},
{
"type": "boolean_literal",
"named": true
@ -327,6 +439,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "binary_expression",
"named": true
},
{
"type": "boolean_literal",
"named": true
@ -528,10 +644,6 @@
"type": ")",
"named": false
},
{
"type": "+=",
"named": false
},
{
"type": ",",
"named": false
@ -572,6 +684,10 @@
"type": "identifier",
"named": true
},
{
"type": "operator",
"named": true
},
{
"type": "raw_string_literal",
"named": true

2030
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -17,6 +17,7 @@ foo = 42
(source_file
(assignment
(identifier)
(operator)
(integer_literal)))
================================================================================
@ -30,6 +31,7 @@ foo = bar
(source_file
(assignment
(identifier)
(operator)
(identifier)))
================================================================================
@ -43,6 +45,7 @@ foo += 12
(source_file
(assignment
(identifier)
(operator)
(integer_literal)))
================================================================================
@ -57,9 +60,11 @@ bar = 27
(source_file
(assignment
(identifier)
(operator)
(integer_literal))
(assignment
(identifier)
(operator)
(integer_literal)))
================================================================================
@ -78,19 +83,25 @@ qux += 1
(source_file
(assignment
(identifier)
(operator)
(integer_literal))
(assignment
(identifier)
(operator)
(integer_literal))
(assignment
(identifier)
(operator)
(integer_literal))
(assignment
(identifier)
(operator)
(integer_literal))
(assignment
(identifier)
(operator)
(integer_literal))
(assignment
(identifier)
(operator)
(integer_literal)))

View file

@ -10,9 +10,11 @@ foo = true
(source_file
(assignment
(identifier)
(operator)
(boolean_literal))
(assignment
(identifier)
(operator)
(boolean_literal)))
================================================================================
@ -27,9 +29,11 @@ false = true
(source_file
(assignment
(identifier)
(operator)
(boolean_literal))
(assignment
(identifier)
(operator)
(boolean_literal)))
================================================================================
@ -44,9 +48,11 @@ foo = 42
(source_file
(assignment
(identifier)
(operator)
(integer_literal))
(assignment
(identifier)
(operator)
(integer_literal)))
================================================================================
@ -61,9 +67,11 @@ foo = -42
(source_file
(assignment
(identifier)
(operator)
(integer_literal))
(assignment
(identifier)
(operator)
(integer_literal)))
================================================================================
@ -77,6 +85,7 @@ foo = "Hello World!"
(source_file
(assignment
(identifier)
(operator)
(interpreted_string_literal)))
================================================================================
@ -90,6 +99,7 @@ foo = "Hello\nWorld!"
(source_file
(assignment
(identifier)
(operator)
(interpreted_string_literal
(escape_sequence))))
@ -104,6 +114,7 @@ foo = `Hello\nWorld!`
(source_file
(assignment
(identifier)
(operator)
(raw_string_literal)))
================================================================================
@ -117,6 +128,7 @@ foo = []
(source_file
(assignment
(identifier)
(operator)
(list_expression)))
================================================================================
@ -130,6 +142,7 @@ foo = [42]
(source_file
(assignment
(identifier)
(operator)
(list_expression
(integer_literal))))
@ -146,6 +159,7 @@ foo = [
(source_file
(assignment
(identifier)
(operator)
(list_expression
(integer_literal))))
@ -162,6 +176,7 @@ foo = [
(source_file
(assignment
(identifier)
(operator)
(list_expression
(integer_literal))))
@ -179,6 +194,7 @@ foo = [
(source_file
(assignment
(identifier)
(operator)
(list_expression
(integer_literal)
(interpreted_string_literal))))
@ -198,6 +214,7 @@ foo = [
(source_file
(assignment
(identifier)
(operator)
(list_expression
(list_expression
(integer_literal))
@ -218,6 +235,7 @@ foo = [
(source_file
(assignment
(identifier)
(operator)
(list_expression
(ERROR))))
@ -232,6 +250,7 @@ foo = {}
(source_file
(assignment
(identifier)
(operator)
(map_expression)))
================================================================================
@ -245,6 +264,7 @@ foo = {foo:42}
(source_file
(assignment
(identifier)
(operator)
(map_expression
(property
(identifier)
@ -263,6 +283,7 @@ foo = {
(source_file
(assignment
(identifier)
(operator)
(map_expression
(property
(identifier)
@ -281,6 +302,7 @@ foo = {
(source_file
(assignment
(identifier)
(operator)
(map_expression
(property
(identifier)
@ -300,6 +322,7 @@ foo = {
(source_file
(assignment
(identifier)
(operator)
(map_expression
(property
(identifier)
@ -321,6 +344,7 @@ foo = {
(source_file
(assignment
(identifier)
(operator)
(map_expression
(property
(identifier)
@ -342,5 +366,34 @@ foo = {
(source_file
(assignment
(identifier)
(operator)
(map_expression
(ERROR))))
================================================================================
Binary operators
================================================================================
foo = [
-12 + -27 + 42,
"a" + "b",
]
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(list_expression
(binary_expression
(binary_expression
(integer_literal)
(operator)
(integer_literal))
(operator)
(integer_literal))
(binary_expression
(interpreted_string_literal)
(operator)
(interpreted_string_literal)))))

View file

@ -12,6 +12,7 @@ foo = select(release_variable("RELEASE_TEST"), {
(source_file
(assignment
(identifier)
(operator)
(select_expression
(select_value
(selection_type)
@ -37,6 +38,7 @@ foo = select(soong_config_variable("my_namespace", "my_var"), {
(source_file
(assignment
(identifier)
(operator)
(select_expression
(soong_config_variable
(selection_type)
@ -66,6 +68,7 @@ foo = select(variant("arch"), {
(source_file
(assignment
(identifier)
(operator)
(select_expression
(select_value
(selection_type)
@ -95,6 +98,7 @@ foo = select(variant("VARIANT"), {})
(source_file
(assignment
(identifier)
(operator)
(select_expression
(select_value
(selection_type)
@ -118,6 +122,7 @@ foo = select(variant("VARIANT"), {
(source_file
(assignment
(identifier)
(operator)
(select_expression
(select_value
(selection_type)
@ -153,6 +158,7 @@ foo = select(variant(), {
(source_file
(assignment
(identifier)
(operator)
(select_expression
(select_value
(selection_type)
@ -178,6 +184,7 @@ foo = select(some_unknown_type("CONDITION"), {
(source_file
(assignment
(identifier)
(operator)
(ERROR
(identifier)
(identifier)