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

View file

@ -46,6 +46,20 @@
overlays = [ ]; 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 { tree-sitter-env = pkgs.stdenv.mkDerivation {
name = "tree-sitter-env"; name = "tree-sitter-env";
@ -96,6 +110,7 @@
devShells = { devShells = {
default = pkgs.mkShell { default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [
bump-version
nodejs nodejs
(tree-sitter.override { webUISupport = true; }) (tree-sitter.override { webUISupport = true; })
]; ];

View file

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

View file

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

69
src/grammar.json generated
View file

@ -49,17 +49,22 @@
"type": "FIELD", "type": "FIELD",
"name": "operator", "name": "operator",
"content": { "content": {
"type": "CHOICE", "type": "ALIAS",
"members": [ "content": {
{ "type": "CHOICE",
"type": "STRING", "members": [
"value": "=" {
}, "type": "STRING",
{ "value": "="
"type": "STRING", },
"value": "+=" {
} "type": "STRING",
] "value": "+="
}
]
},
"named": true,
"value": "operator"
} }
}, },
{ {
@ -279,6 +284,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "map_expression" "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": { "_colon_property": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [

136
src/node-types.json generated
View file

@ -18,12 +18,8 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "+=", "type": "operator",
"named": false "named": true
},
{
"type": "=",
"named": false
} }
] ]
}, },
@ -31,6 +27,110 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "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", "type": "boolean_literal",
"named": true "named": true
@ -95,6 +195,10 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binary_expression",
"named": true
},
{ {
"type": "boolean_literal", "type": "boolean_literal",
"named": true "named": true
@ -163,6 +267,10 @@
"multiple": true, "multiple": true,
"required": false, "required": false,
"types": [ "types": [
{
"type": "binary_expression",
"named": true
},
{ {
"type": "boolean_literal", "type": "boolean_literal",
"named": true "named": true
@ -269,6 +377,10 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binary_expression",
"named": true
},
{ {
"type": "boolean_literal", "type": "boolean_literal",
"named": true "named": true
@ -327,6 +439,10 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binary_expression",
"named": true
},
{ {
"type": "boolean_literal", "type": "boolean_literal",
"named": true "named": true
@ -528,10 +644,6 @@
"type": ")", "type": ")",
"named": false "named": false
}, },
{
"type": "+=",
"named": false
},
{ {
"type": ",", "type": ",",
"named": false "named": false
@ -572,6 +684,10 @@
"type": "identifier", "type": "identifier",
"named": true "named": true
}, },
{
"type": "operator",
"named": true
},
{ {
"type": "raw_string_literal", "type": "raw_string_literal",
"named": true "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 (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(integer_literal))) (integer_literal)))
================================================================================ ================================================================================
@ -30,6 +31,7 @@ foo = bar
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(identifier))) (identifier)))
================================================================================ ================================================================================
@ -43,6 +45,7 @@ foo += 12
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(integer_literal))) (integer_literal)))
================================================================================ ================================================================================
@ -57,9 +60,11 @@ bar = 27
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(integer_literal)) (integer_literal))
(assignment (assignment
(identifier) (identifier)
(operator)
(integer_literal))) (integer_literal)))
================================================================================ ================================================================================
@ -78,19 +83,25 @@ qux += 1
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(integer_literal)) (integer_literal))
(assignment (assignment
(identifier) (identifier)
(operator)
(integer_literal)) (integer_literal))
(assignment (assignment
(identifier) (identifier)
(operator)
(integer_literal)) (integer_literal))
(assignment (assignment
(identifier) (identifier)
(operator)
(integer_literal)) (integer_literal))
(assignment (assignment
(identifier) (identifier)
(operator)
(integer_literal)) (integer_literal))
(assignment (assignment
(identifier) (identifier)
(operator)
(integer_literal))) (integer_literal)))

View file

@ -10,9 +10,11 @@ foo = true
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(boolean_literal)) (boolean_literal))
(assignment (assignment
(identifier) (identifier)
(operator)
(boolean_literal))) (boolean_literal)))
================================================================================ ================================================================================
@ -27,9 +29,11 @@ false = true
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(boolean_literal)) (boolean_literal))
(assignment (assignment
(identifier) (identifier)
(operator)
(boolean_literal))) (boolean_literal)))
================================================================================ ================================================================================
@ -44,9 +48,11 @@ foo = 42
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(integer_literal)) (integer_literal))
(assignment (assignment
(identifier) (identifier)
(operator)
(integer_literal))) (integer_literal)))
================================================================================ ================================================================================
@ -61,9 +67,11 @@ foo = -42
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(integer_literal)) (integer_literal))
(assignment (assignment
(identifier) (identifier)
(operator)
(integer_literal))) (integer_literal)))
================================================================================ ================================================================================
@ -77,6 +85,7 @@ foo = "Hello World!"
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(interpreted_string_literal))) (interpreted_string_literal)))
================================================================================ ================================================================================
@ -90,6 +99,7 @@ foo = "Hello\nWorld!"
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(interpreted_string_literal (interpreted_string_literal
(escape_sequence)))) (escape_sequence))))
@ -104,6 +114,7 @@ foo = `Hello\nWorld!`
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(raw_string_literal))) (raw_string_literal)))
================================================================================ ================================================================================
@ -117,6 +128,7 @@ foo = []
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(list_expression))) (list_expression)))
================================================================================ ================================================================================
@ -130,6 +142,7 @@ foo = [42]
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(list_expression (list_expression
(integer_literal)))) (integer_literal))))
@ -146,6 +159,7 @@ foo = [
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(list_expression (list_expression
(integer_literal)))) (integer_literal))))
@ -162,6 +176,7 @@ foo = [
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(list_expression (list_expression
(integer_literal)))) (integer_literal))))
@ -179,6 +194,7 @@ foo = [
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(list_expression (list_expression
(integer_literal) (integer_literal)
(interpreted_string_literal)))) (interpreted_string_literal))))
@ -198,6 +214,7 @@ foo = [
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(list_expression (list_expression
(list_expression (list_expression
(integer_literal)) (integer_literal))
@ -218,6 +235,7 @@ foo = [
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(list_expression (list_expression
(ERROR)))) (ERROR))))
@ -232,6 +250,7 @@ foo = {}
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(map_expression))) (map_expression)))
================================================================================ ================================================================================
@ -245,6 +264,7 @@ foo = {foo:42}
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(map_expression (map_expression
(property (property
(identifier) (identifier)
@ -263,6 +283,7 @@ foo = {
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(map_expression (map_expression
(property (property
(identifier) (identifier)
@ -281,6 +302,7 @@ foo = {
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(map_expression (map_expression
(property (property
(identifier) (identifier)
@ -300,6 +322,7 @@ foo = {
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(map_expression (map_expression
(property (property
(identifier) (identifier)
@ -321,6 +344,7 @@ foo = {
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(map_expression (map_expression
(property (property
(identifier) (identifier)
@ -342,5 +366,34 @@ foo = {
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(map_expression (map_expression
(ERROR)))) (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 (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(select_expression (select_expression
(select_value (select_value
(selection_type) (selection_type)
@ -37,6 +38,7 @@ foo = select(soong_config_variable("my_namespace", "my_var"), {
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(select_expression (select_expression
(soong_config_variable (soong_config_variable
(selection_type) (selection_type)
@ -66,6 +68,7 @@ foo = select(variant("arch"), {
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(select_expression (select_expression
(select_value (select_value
(selection_type) (selection_type)
@ -95,6 +98,7 @@ foo = select(variant("VARIANT"), {})
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(select_expression (select_expression
(select_value (select_value
(selection_type) (selection_type)
@ -118,6 +122,7 @@ foo = select(variant("VARIANT"), {
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(select_expression (select_expression
(select_value (select_value
(selection_type) (selection_type)
@ -153,6 +158,7 @@ foo = select(variant(), {
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(select_expression (select_expression
(select_value (select_value
(selection_type) (selection_type)
@ -178,6 +184,7 @@ foo = select(some_unknown_type("CONDITION"), {
(source_file (source_file
(assignment (assignment
(identifier) (identifier)
(operator)
(ERROR (ERROR
(identifier) (identifier)
(identifier) (identifier)