Compare commits

..

6 commits

Author SHA1 Message Date
Bruno BELANYI a2cc89a55c WIP
Some checks failed
ci/woodpecker/push/check Pipeline failed
2024-04-13 18:29:41 +01:00
Bruno BELANYI fc82b7e8bf WIP(tests): Hide 'select_cases' rule
It doesn't provide any more information to expose it.
2024-04-13 18:29:35 +01:00
Bruno BELANYI 6ece5d984a Release 0.3.0
All checks were successful
ci/woodpecker/push/check Pipeline was successful
2024-04-13 18:27:56 +01:00
Bruno BELANYI e6a2757c51 Alias 'default_case' to 'select_case'
There's not much use in the node being a different name.
2024-04-13 18:23:06 +01:00
Bruno BELANYI 8db7b053f5 Add 'default' alias
This makes it appear in the tree as a named node.
2024-04-13 18:21:58 +01:00
Bruno BELANYI d297f38e6a Fix typos in indentation test runner
All checks were successful
ci/woodpecker/push/check Pipeline was successful
2024-04-13 18:17:22 +01:00
7 changed files with 1170 additions and 957 deletions

View file

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

View file

@ -2,6 +2,10 @@ function commaSeparated(elem) {
return seq(elem, repeat(seq(",", elem)), optional(","))
}
function trailingCommaSeparated(elem) {
return repeat(seq(elem, ","))
}
module.exports = grammar({
name: "bp",
@ -151,16 +155,24 @@ module.exports = grammar({
_select_cases: ($) => seq(
"{",
optional(repeat(seq($.select_case, ","))),
optional(trailingCommaSeparated($.select_case)),
// default *must* be the last one, enforced at parse-time...
optional(seq(alias($.default_case, $.select_case), ",")),
"}",
),
select_case: ($) => seq(
field("pattern", choice(alias("default", $.default), $._string_literal)),
field("pattern", $._string_literal),
":",
field("value", $._case_value)
),
default_case: ($) => seq(
field("pattern", alias("default", $.default)),
":",
field("value", $._case_value),
),
_case_value: ($) => choice(
alias("unset", $.unset),
$._expr,

View file

@ -1,6 +1,6 @@
{
"name": "tree-sitter-bp",
"version": "0.2.0",
"version": "0.3.0",
"description": "Blueprint grammar for tree-sitter",
"main": "bindings/node",
"keywords": [

74
src/grammar.json generated
View file

@ -628,6 +628,32 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "default_case"
},
"named": true,
"value": "select_case"
},
{
"type": "STRING",
"value": ","
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "}"
@ -641,22 +667,38 @@
"type": "FIELD",
"name": "pattern",
"content": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "default"
},
"named": true,
"value": "default"
},
{
"type": "SYMBOL",
"name": "_string_literal"
}
]
"type": "SYMBOL",
"name": "_string_literal"
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "_case_value"
}
}
]
},
"default_case": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "pattern",
"content": {
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "default"
},
"named": true,
"value": "default"
}
},
{

2022
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -130,9 +130,10 @@ foo = select(variant("VARIANT"), {
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(default)
(unset))
(ERROR
(select_case
(default)
(unset)))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))

View file

@ -41,7 +41,7 @@ describe("indent Blueprint:", function()
runner:new_line("test/indent/select.bp", { on_line = 11, text = 'default: "value"', indent = 4 }, "default case, trailing")
runner:new_line("test/indent/select.bp", { on_line = 16, text = '"case": "value"', indent = 8 }, "select case, alternate formatting")
runner:new_line("test/indent/select.bp", { on_line = 16, text = 'default: "value"', indent = 8 }, "default case, alternate formatting")
runner:new_line("test/indent/select.bp", { on_line = 26, text = '"case": "value"', indent = 8 }, "select case, trailing, alternate formattingg")
runner:new_line("test/indent/select.bp", { on_line = 26, text = 'default: "value"', indent = 8 }, "default case, trailing, alternate formattingn")
runner:new_line("test/indent/select.bp", { on_line = 26, text = '"case": "value"', indent = 8 }, "select case, trailing, alternate formatting")
runner:new_line("test/indent/select.bp", { on_line = 26, text = 'default: "value"', indent = 8 }, "default case, trailing, alternate formatting")
end)
end)