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,
EOL: -1,
TEXT_BLOCK_CONTENT: -1,
UNQUOTED_STRING: 0,
UNQUOTED_STRING: -1,
CONTAINER: 2,
CONNECTION: 2,
SHAPE: 3,
@ -266,7 +266,8 @@ module.exports = grammar({
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]+/)), "`")
),
boolean: ($) => choice("true", "false"),
integer: ($) => /[0-9]+/,
float: ($) => /[0-9]+\.[0-9]+/,
line_comment: ($) => token(prec(PREC.COMMENT, seq("#", /.*/))),
_eol: ($) => token(prec(PREC.EOL, "\n")),

View file

@ -1115,6 +1115,18 @@
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "boolean"
},
{
"type": "SYMBOL",
"name": "integer"
},
{
"type": "SYMBOL",
"name": "float"
},
{
"type": "SYMBOL",
"name": "string"
@ -1182,7 +1194,7 @@
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 0,
"value": -1,
"content": {
"type": "PATTERN",
"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": {
"type": "TOKEN",
"content": {

View file

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

Binary file not shown.

View file

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