add primitive types

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-09 18:49:33 +03:00
parent 99d9fbbf63
commit b3a382ff5b
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
5 changed files with 147 additions and 74 deletions

View file

@ -2,7 +2,7 @@ const PREC = {
COMMENT: -2, COMMENT: -2,
EOL: -1, EOL: -1,
TEXT_BLOCK_CONTENT: -1, TEXT_BLOCK_CONTENT: -1,
UNQUOTED_STRING: 0, UNQUOTED_STRING: -1,
CONTAINER: 2, CONTAINER: 2,
CONNECTION: 2, CONNECTION: 2,
SHAPE: 3, SHAPE: 3,
@ -266,7 +266,8 @@ module.exports = grammar({
label: ($) => choice($.string, $._unquoted_string), label: ($) => choice($.string, $._unquoted_string),
attr_value: ($) => seq(choice($.string, $._unquoted_string)), attr_value: ($) =>
seq(choice($.boolean, $.integer, $.float, $.string, $._unquoted_string)),
// -------------------------------------------- // --------------------------------------------
@ -288,6 +289,12 @@ module.exports = grammar({
seq("`", repeat(token.immediate(/[^`\n]+/)), "`") seq("`", repeat(token.immediate(/[^`\n]+/)), "`")
), ),
boolean: ($) => choice("true", "false"),
integer: ($) => /[0-9]+/,
float: ($) => /[0-9]+\.[0-9]+/,
line_comment: ($) => token(prec(PREC.COMMENT, seq("#", /.*/))), line_comment: ($) => token(prec(PREC.COMMENT, seq("#", /.*/))),
_eol: ($) => token(prec(PREC.EOL, "\n")), _eol: ($) => token(prec(PREC.EOL, "\n")),

View file

@ -1115,6 +1115,18 @@
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "SYMBOL",
"name": "boolean"
},
{
"type": "SYMBOL",
"name": "integer"
},
{
"type": "SYMBOL",
"name": "float"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "string" "name": "string"
@ -1182,7 +1194,7 @@
"type": "TOKEN", "type": "TOKEN",
"content": { "content": {
"type": "PREC", "type": "PREC",
"value": 0, "value": -1,
"content": { "content": {
"type": "PATTERN", "type": "PATTERN",
"value": "[^'\"`|\\n\\s;{}]([^\\n;{}]*[^\\n\\s;{}])?" "value": "[^'\"`|\\n\\s;{}]([^\\n;{}]*[^\\n\\s;{}])?"
@ -1263,6 +1275,27 @@
} }
] ]
}, },
"boolean": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "true"
},
{
"type": "STRING",
"value": "false"
}
]
},
"integer": {
"type": "PATTERN",
"value": "[0-9]+"
},
"float": {
"type": "PATTERN",
"value": "[0-9]+\\.[0-9]+"
},
"line_comment": { "line_comment": {
"type": "TOKEN", "type": "TOKEN",
"content": { "content": {

View file

@ -22,6 +22,18 @@
"multiple": false, "multiple": false,
"required": false, "required": false,
"types": [ "types": [
{
"type": "boolean",
"named": true
},
{
"type": "float",
"named": true
},
{
"type": "integer",
"named": true
},
{ {
"type": "string", "type": "string",
"named": true "named": true
@ -91,6 +103,11 @@
] ]
} }
}, },
{
"type": "boolean",
"named": true,
"fields": {}
},
{ {
"type": "connection", "type": "connection",
"named": true, "named": true,
@ -349,10 +366,18 @@
"type": "dot", "type": "dot",
"named": true "named": true
}, },
{
"type": "false",
"named": false
},
{ {
"type": "fill", "type": "fill",
"named": false "named": false
}, },
{
"type": "float",
"named": true
},
{ {
"type": "font-color", "type": "font-color",
"named": false "named": false
@ -365,6 +390,10 @@
"type": "icon", "type": "icon",
"named": false "named": false
}, },
{
"type": "integer",
"named": true
},
{ {
"type": "label", "type": "label",
"named": false "named": false
@ -421,6 +450,10 @@
"type": "target-arrowhead", "type": "target-arrowhead",
"named": false "named": false
}, },
{
"type": "true",
"named": false
},
{ {
"type": "width", "type": "width",
"named": false "named": false

Binary file not shown.

View file

@ -4,17 +4,17 @@ Root attribute
direction: value direction: value
shape: oval shape: oval
label: ten label: 'one two'
constraint: utehu constraint: utehu
icon: ./test.svg icon: ./test.svg
opacity: 1 opacity: 0.5
fill: red fill: red
stroke: red stroke: red
stroke-width: 5 stroke-width: 5
stroke-dash: 4 stroke-dash: 4
border-radius: 1 border-radius: 1
font-color: red font-color: red
shadow: true shadow: false
multiple: true multiple: true
animated: true animated: true
link: https://to link: https://to
@ -26,19 +26,19 @@ near: abc
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key (reserved)) (attr_value)) (attribute (attr_key (reserved)) (attr_value))
(attribute (attr_key (reserved)) (attr_value (string)))
(attribute (attr_key (reserved)) (attr_value)) (attribute (attr_key (reserved)) (attr_value))
(attribute (attr_key (reserved)) (attr_value)) (attribute (attr_key (reserved)) (attr_value))
(attribute (attr_key (reserved)) (attr_value (float)))
(attribute (attr_key (reserved)) (attr_value)) (attribute (attr_key (reserved)) (attr_value))
(attribute (attr_key (reserved)) (attr_value)) (attribute (attr_key (reserved)) (attr_value))
(attribute (attr_key (reserved)) (attr_value (integer)))
(attribute (attr_key (reserved)) (attr_value (integer)))
(attribute (attr_key (reserved)) (attr_value (integer)))
(attribute (attr_key (reserved)) (attr_value)) (attribute (attr_key (reserved)) (attr_value))
(attribute (attr_key (reserved)) (attr_value)) (attribute (attr_key (reserved)) (attr_value (boolean)))
(attribute (attr_key (reserved)) (attr_value)) (attribute (attr_key (reserved)) (attr_value (boolean)))
(attribute (attr_key (reserved)) (attr_value)) (attribute (attr_key (reserved)) (attr_value (boolean)))
(attribute (attr_key (reserved)) (attr_value))
(attribute (attr_key (reserved)) (attr_value))
(attribute (attr_key (reserved)) (attr_value))
(attribute (attr_key (reserved)) (attr_value))
(attribute (attr_key (reserved)) (attr_value))
(attribute (attr_key (reserved)) (attr_value)) (attribute (attr_key (reserved)) (attr_value))
(attribute (attr_key (reserved)) (attr_value)) (attribute (attr_key (reserved)) (attr_value))
) )
@ -46,14 +46,14 @@ near: abc
================================================================================ ================================================================================
Style attribute Style attribute
================================================================================ ================================================================================
foo.style.opacity: 5 foo.style.opacity: 0.5
foo.style.fill: red foo.style.fill: red
foo.style.stroke: red foo.style.stroke: red
foo.style.stroke-width: 5 foo.style.stroke-width: 5
foo.style.stroke-dash: 4 foo.style.stroke-dash: 4
foo.style.border-radius: 1 foo.style.border-radius: 1
foo.style.font-color: red foo.style.font-color: red
foo.style.shadow: true foo.style.shadow: false
foo.style.multiple: true foo.style.multiple: true
foo.style.animated: true foo.style.animated: true
foo.style.link: https://to foo.style.link: https://to
@ -61,16 +61,16 @@ foo.style.link: https://to
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (float)))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))) (shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))) (shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (integer)))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (integer)))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (integer)))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))) (shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))) (shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (boolean)))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))) (shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (boolean)))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))) (shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (boolean)))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))) (shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
) )
@ -78,14 +78,14 @@ foo.style.link: https://to
Block style attributes Block style attributes
================================================================================ ================================================================================
foo.style: { foo.style: {
opacity: 5 opacity: 0.5
fill: red fill: red
stroke: red stroke: red
stroke-width: 5 stroke-width: 5
stroke-dash: 4 stroke-dash: 4
border-radius: 1 border-radius: 1
font-color: red font-color: red
shadow: true shadow: false
multiple: true multiple: true
animated: true animated: true
link: https://to link: https://to
@ -99,16 +99,16 @@ foo.style: {
(attribute (attribute
(attr_key) (attr_key)
(block (block
(attribute (attr_key) (attr_value (float)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (boolean)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (boolean)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (boolean)))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
) )
) )
@ -120,7 +120,7 @@ Container attributes
================================================================================ ================================================================================
foo: { foo: {
shape: oval shape: oval
label: Baz label: 'Baz'
constraint: primary-key constraint: primary-key
icon: pathto icon: pathto
width: 100 width: 100
@ -134,11 +134,11 @@ foo: {
(container_key) (container_key)
(block (block
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value (string)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value))
) )
) )
) )
@ -147,7 +147,7 @@ foo: {
Container style attributes Container style attributes
================================================================================ ================================================================================
foo: { foo: {
style.opacity: 5 style.opacity: 0.5
style.fill: red style.fill: red
style.stroke: red style.stroke: red
style.stroke-width: 5 style.stroke-width: 5
@ -166,16 +166,16 @@ foo: {
(container (container
(container_key) (container_key)
(block (block
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value (float))))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value))) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value))) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value (integer))))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value (integer))))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value (integer))))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value))) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value))) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (boolean))))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value))) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (boolean))))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value))) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (boolean))))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value))) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
) )
) )
@ -186,7 +186,7 @@ Block style attributes inside a container
================================================================================ ================================================================================
foo: { foo: {
style: { style: {
opacity: 5 opacity: 0.5
fill: red fill: red
stroke: red stroke: red
stroke-width: 5 stroke-width: 5
@ -209,16 +209,16 @@ foo: {
(attribute (attribute
(attr_key) (attr_key)
(block (block
(attribute (attr_key) (attr_value (float)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (boolean)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (boolean)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (boolean)))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
) )
) )
@ -231,14 +231,14 @@ Block style attributes inside a connection
================================================================================ ================================================================================
foo -> bar: { foo -> bar: {
style: { style: {
opacity: 5 opacity: 0.5
fill: red fill: red
stroke: red stroke: red
stroke-width: 5 stroke-width: 5
stroke-dash: 4 stroke-dash: 4
border-radius: 1 border-radius: 1
font-color: red font-color: red
shadow: true shadow: false
multiple: true multiple: true
animated: true animated: true
link: https://to link: https://to
@ -256,16 +256,16 @@ foo -> bar: {
(attribute (attribute
(attr_key) (attr_key)
(block (block
(attribute (attr_key) (attr_value (float)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (boolean)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (boolean)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (boolean)))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
) )
) )
@ -307,14 +307,14 @@ Block style attributes inside a connection arrowhead
foo -> bar: { foo -> bar: {
target-arrowhead: { target-arrowhead: {
style: { style: {
opacity: 5 opacity: 0.5
fill: red fill: red
stroke: red stroke: red
stroke-width: 5 stroke-width: 5
stroke-dash: 4 stroke-dash: 4
border-radius: 1 border-radius: 1
font-color: red font-color: red
shadow: true shadow: false
multiple: true multiple: true
animated: true animated: true
link: https://to link: https://to
@ -336,16 +336,16 @@ foo -> bar: {
(attribute (attribute
(attr_key) (attr_key)
(block (block
(attribute (attr_key) (attr_value (float)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (boolean)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (boolean)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (boolean)))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
) )
) )
@ -361,7 +361,7 @@ Container attributes inside a connection arrowhead
foo -> bar: { foo -> bar: {
target-arrowhead: { target-arrowhead: {
shape: oval shape: oval
label: Baz label: 'Baz'
constraint: primary-key constraint: primary-key
icon: pathto icon: pathto
width: 100 width: 100
@ -381,11 +381,11 @@ foo -> bar: {
(attr_key) (attr_key)
(block (block
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value (string)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value))
) )
) )
) )