add all keywords

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-04 23:45:53 +03:00
parent 949e58bb56
commit 2bd0ded807
Signed by: pleshevskiy
GPG Key ID: 1B59187B161C0215
5 changed files with 452 additions and 170 deletions

View File

@ -7,26 +7,11 @@ module.exports = grammar({
// TODO: add the actual grammar rules
source_file: ($) => repeat($._definition),
_definition: ($) => choice($.attribute, $.connection, $.shape),
_end: ($) => choice(";", "\n", "\0"),
attribute: ($) =>
_definition: ($) =>
choice(
seq(
$.identifier,
repeat1(seq($.dot, $.keyword)),
":",
alias($.label, $.attribute_value),
$._end
),
seq(
$.keyword,
repeat(seq($.dot, $.keyword)),
":",
alias($.label, $.attribute_value),
$._end
)
choice($._root_attribute, $._shape_attribute),
$.connection,
$.shape
),
connection: ($) =>
@ -47,13 +32,73 @@ module.exports = grammar({
$._end
),
dot: ($) => ".",
label: ($) => choice($.string, $._unquoted_string),
identifier: ($) => $._identifier,
keyword: ($) => choice("direction"),
attr_value: ($) => choice($.string, $._unquoted_string),
_root_attribute: ($) =>
seq(
alias($._root_attr_key, $.attr_key),
":",
alias($.label, $.attr_value),
$._end
),
_root_attr_key: ($) => "direction",
_style_attribute: ($) =>
seq(
alias("style", $.attr_key),
$.dot,
alias($._style_attr_key, $.attr_key),
":",
$.attr_value,
$._end
),
_shape_attribute: ($) =>
seq(
$.identifier,
$.dot,
choice(
seq(alias($._shape_attr_key, $.attr_key), ":", $.attr_value, $._end),
$._style_attribute
)
),
_shape_attr_key: ($) =>
choice(
"shape",
"label",
// sql
"constraint",
// image
"icon",
"width",
"height"
),
_style_attr_key: ($) =>
choice(
"opacity",
"fill",
"stroke",
"stroke-width",
"stroke-dash",
"border-radius",
"font-color",
"shadow",
"multiple",
"animated",
"3d",
"link"
),
_text_attr_key: ($) => "near",
_connection_attr_key: ($) => choice("source-arrowhead", "target-arrowhead"),
_identifier: ($) =>
prec.right(
@ -91,5 +136,9 @@ module.exports = grammar({
seq('"', repeat(token(/[^'\n]+/)), '"'),
seq("`", repeat(token(/[^'\n]+/)), "`")
),
_end: ($) => choice(";", "\n", "\0"),
dot: ($) => ".",
},
});

View File

@ -13,8 +13,17 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "attribute"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_root_attribute"
},
{
"type": "SYMBOL",
"name": "_shape_attribute"
}
]
},
{
"type": "SYMBOL",
@ -26,112 +35,6 @@
}
]
},
"_end": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "STRING",
"value": "\n"
},
{
"type": "STRING",
"value": "\u0000"
}
]
},
"attribute": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "dot"
},
{
"type": "SYMBOL",
"name": "keyword"
}
]
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "label"
},
"named": true,
"value": "attribute_value"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "keyword"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "dot"
},
{
"type": "SYMBOL",
"name": "keyword"
}
]
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "label"
},
"named": true,
"value": "attribute_value"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
}
]
},
"connection": {
"type": "SEQ",
"members": [
@ -247,10 +150,6 @@
}
]
},
"dot": {
"type": "STRING",
"value": "."
},
"label": {
"type": "CHOICE",
"members": [
@ -268,12 +167,237 @@
"type": "SYMBOL",
"name": "_identifier"
},
"keyword": {
"attr_value": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "_unquoted_string"
}
]
},
"_root_attribute": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_root_attr_key"
},
"named": true,
"value": "attr_key"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "label"
},
"named": true,
"value": "attr_value"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
},
"_root_attr_key": {
"type": "STRING",
"value": "direction"
},
"_style_attribute": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "style"
},
"named": true,
"value": "attr_key"
},
{
"type": "SYMBOL",
"name": "dot"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_style_attr_key"
},
"named": true,
"value": "attr_key"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "attr_value"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
},
"_shape_attribute": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "dot"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_shape_attr_key"
},
"named": true,
"value": "attr_key"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "attr_value"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
},
{
"type": "SYMBOL",
"name": "_style_attribute"
}
]
}
]
},
"_shape_attr_key": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "direction"
"value": "shape"
},
{
"type": "STRING",
"value": "label"
},
{
"type": "STRING",
"value": "constraint"
},
{
"type": "STRING",
"value": "icon"
},
{
"type": "STRING",
"value": "width"
},
{
"type": "STRING",
"value": "height"
}
]
},
"_style_attr_key": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "opacity"
},
{
"type": "STRING",
"value": "fill"
},
{
"type": "STRING",
"value": "stroke"
},
{
"type": "STRING",
"value": "stroke-width"
},
{
"type": "STRING",
"value": "stroke-dash"
},
{
"type": "STRING",
"value": "border-radius"
},
{
"type": "STRING",
"value": "font-color"
},
{
"type": "STRING",
"value": "shadow"
},
{
"type": "STRING",
"value": "multiple"
},
{
"type": "STRING",
"value": "animated"
},
{
"type": "STRING",
"value": "3d"
},
{
"type": "STRING",
"value": "link"
}
]
},
"_text_attr_key": {
"type": "STRING",
"value": "near"
},
"_connection_attr_key": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "source-arrowhead"
},
{
"type": "STRING",
"value": "target-arrowhead"
}
]
},
@ -530,6 +654,27 @@
]
}
]
},
"_end": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "STRING",
"value": "\n"
},
{
"type": "STRING",
"value": "\u0000"
}
]
},
"dot": {
"type": "STRING",
"value": "."
}
},
"extras": [

View File

@ -5,34 +5,12 @@
"fields": {}
},
{
"type": "attribute",
"type": "attr_key",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "attribute_value",
"named": true
},
{
"type": "dot",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "keyword",
"named": true
}
]
}
"fields": {}
},
{
"type": "attribute_value",
"type": "attr_value",
"named": true,
"fields": {},
"children": {
@ -74,11 +52,6 @@
"named": true,
"fields": {}
},
{
"type": "keyword",
"named": true,
"fields": {}
},
{
"type": "label",
"named": true,
@ -126,13 +99,25 @@
"required": false,
"types": [
{
"type": "attribute",
"type": "attr_key",
"named": true
},
{
"type": "attr_value",
"named": true
},
{
"type": "connection",
"named": true
},
{
"type": "dot",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "shape",
"named": true
@ -173,6 +158,10 @@
"type": "->",
"named": false
},
{
"type": "3d",
"named": false
},
{
"type": ":",
"named": false
@ -194,11 +183,83 @@
"named": false
},
{
"type": "direction",
"type": "animated",
"named": false
},
{
"type": "border-radius",
"named": false
},
{
"type": "constraint",
"named": false
},
{
"type": "dot",
"named": true
},
{
"type": "fill",
"named": false
},
{
"type": "font-color",
"named": false
},
{
"type": "height",
"named": false
},
{
"type": "icon",
"named": false
},
{
"type": "label",
"named": false
},
{
"type": "link",
"named": false
},
{
"type": "multiple",
"named": false
},
{
"type": "opacity",
"named": false
},
{
"type": "shadow",
"named": false
},
{
"type": "shape",
"named": false
},
{
"type": "source-arrowhead",
"named": false
},
{
"type": "stroke",
"named": false
},
{
"type": "stroke-dash",
"named": false
},
{
"type": "stroke-width",
"named": false
},
{
"type": "target-arrowhead",
"named": false
},
{
"type": "width",
"named": false
}
]

Binary file not shown.

View File

@ -1,5 +1,5 @@
==================
Keywords
Root attribute
==================
direction: value
@ -7,6 +7,33 @@ direction: value
---
(source_file
(attribute (keyword) (attribute_value))
(attr_key) (attr_value)
)
==================
Inline shape attribute
==================
foo.shape: oval
---
(source_file
(identifier) (dot) (attr_key) (attr_value)
)
==================
Inline style attribute
==================
foo.style.opacity: 5
---
(source_file
(identifier) (dot) (attr_key) (dot) (attr_key) (attr_value)
)