Compare commits
6 commits
629a7cd5a7
...
a2cc89a55c
Author | SHA1 | Date | |
---|---|---|---|
Bruno BELANYI | a2cc89a55c | ||
Bruno BELANYI | fc82b7e8bf | ||
Bruno BELANYI | 6ece5d984a | ||
Bruno BELANYI | e6a2757c51 | ||
Bruno BELANYI | 8db7b053f5 | ||
Bruno BELANYI | d297f38e6a |
|
@ -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"
|
||||
|
|
16
grammar.js
16
grammar.js
|
@ -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,
|
||||
|
|
|
@ -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
74
src/grammar.json
generated
|
@ -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
2022
src/parser.c
generated
File diff suppressed because it is too large
Load diff
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue