Skip to content

Commit

Permalink
Merge pull request #24 from Vishalk91-4/imp-schm
Browse files Browse the repository at this point in the history
Adding import with multiple files, type system and various schemas
  • Loading branch information
Peefy authored Jul 25, 2024
2 parents e225df4 + ec2fd3e commit a32ed22
Show file tree
Hide file tree
Showing 7 changed files with 82,900 additions and 78,918 deletions.
21 changes: 18 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ module.exports = grammar({
$.dict_expr,
),

schema_instantiation: $ => seq(
field('constructor', $.call),
field('initialization', $.dictionary)
),

schema_index_signature: $ => seq(
'[',
optional(seq(
Expand Down Expand Up @@ -576,13 +581,16 @@ module.exports = grammar({
$.lambda_expr,
$.quant_expr,
$.schema_expr,
$.schema_instantiation,
$.paren_expression,
$.braces_expression,
$.optional_attribute,
$.optional_item,
$.optional_attribute_declaration,
$.null_coalesce,
$.string_literal_expr,
$.config_expr,
$.selector_expression
)),

paren_expression: $ => seq(
Expand Down Expand Up @@ -675,7 +683,8 @@ module.exports = grammar({
$.string,
$.integer,
$.float,
$.paren_expression
$.paren_expression,
$.config_expr
)),

dotted_identifier: $ => prec(4, seq(
Expand Down Expand Up @@ -759,7 +768,7 @@ module.exports = grammar({
assignment: $ => seq(
field('left', $.dotted_name),
choice(
seq('=', field('right', choice($.dotted_name,$.expression,))),
seq('=', field('right', choice($.dotted_name,$.expression, $.selector_expression, $.schema_instantiation))),
seq(':', field('type', $.type), '=', field('right', $.expression)),
alias(seq(':',field('type', $.type)),'null_assignment'),
),
Expand Down Expand Up @@ -802,6 +811,12 @@ module.exports = grammar({
field('attribute', $.identifier),
)),

optional_attribute_declaration: $ => prec(2, seq(
field('attribute', $.identifier),
'?:',
field('type', $.type),
)),

optional_item: $ => prec(PREC.call, seq(
field('object', $.primary_expression),
'?[',
Expand Down Expand Up @@ -1081,4 +1096,4 @@ function commaSep1(rule) {
*/
function sep1(rule, separator) {
return seq(rule, repeat(seq(separator, rule)));
}
}
74 changes: 74 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,27 @@
}
]
},
"schema_instantiation": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "constructor",
"content": {
"type": "SYMBOL",
"name": "call"
}
},
{
"type": "FIELD",
"name": "initialization",
"content": {
"type": "SYMBOL",
"name": "dictionary"
}
}
]
},
"schema_index_signature": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -1650,6 +1671,10 @@
"type": "SYMBOL",
"name": "schema_expr"
},
{
"type": "SYMBOL",
"name": "schema_instantiation"
},
{
"type": "SYMBOL",
"name": "paren_expression"
Expand All @@ -1666,6 +1691,10 @@
"type": "SYMBOL",
"name": "optional_item"
},
{
"type": "SYMBOL",
"name": "optional_attribute_declaration"
},
{
"type": "SYMBOL",
"name": "null_coalesce"
Expand All @@ -1677,6 +1706,10 @@
{
"type": "SYMBOL",
"name": "config_expr"
},
{
"type": "SYMBOL",
"name": "selector_expression"
}
]
}
Expand Down Expand Up @@ -2091,6 +2124,10 @@
{
"type": "SYMBOL",
"name": "paren_expression"
},
{
"type": "SYMBOL",
"name": "config_expr"
}
]
}
Expand Down Expand Up @@ -2881,6 +2918,14 @@
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "SYMBOL",
"name": "selector_expression"
},
{
"type": "SYMBOL",
"name": "schema_instantiation"
}
]
}
Expand Down Expand Up @@ -3193,6 +3238,35 @@
]
}
},
"optional_attribute_declaration": {
"type": "PREC",
"value": 2,
"content": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "attribute",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "?:"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "type"
}
}
]
}
},
"optional_item": {
"type": "PREC",
"value": 22,
Expand Down
84 changes: 78 additions & 6 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@
"type": "optional_attribute",
"named": true
},
{
"type": "optional_attribute_declaration",
"named": true
},
{
"type": "optional_item",
"named": true
Expand All @@ -223,10 +227,18 @@
"type": "schema_expr",
"named": true
},
{
"type": "schema_instantiation",
"named": true
},
{
"type": "select_suffix",
"named": true
},
{
"type": "selector_expression",
"named": true
},
{
"type": "string",
"named": true
Expand Down Expand Up @@ -364,6 +376,10 @@
{
"type": "expression",
"named": true
},
{
"type": "schema_instantiation",
"named": true
}
]
},
Expand Down Expand Up @@ -786,10 +802,6 @@
{
"type": "primary_expression",
"named": true
},
{
"type": "selector_expression",
"named": true
}
]
}
Expand Down Expand Up @@ -1674,6 +1686,32 @@
}
}
},
{
"type": "optional_attribute_declaration",
"named": true,
"fields": {
"attribute": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"type": {
"multiple": false,
"required": true,
"types": [
{
"type": "type",
"named": true
}
]
}
}
},
{
"type": "optional_item",
"named": true,
Expand Down Expand Up @@ -2006,6 +2044,32 @@
}
}
},
{
"type": "schema_instantiation",
"named": true,
"fields": {
"constructor": {
"multiple": false,
"required": true,
"types": [
{
"type": "call",
"named": true
}
]
},
"initialization": {
"multiple": false,
"required": true,
"types": [
{
"type": "dictionary",
"named": true
}
]
}
}
},
{
"type": "schema_statement",
"named": true,
Expand Down Expand Up @@ -2212,6 +2276,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "config_expr",
"named": true
},
{
"type": "dotted_name",
"named": true
Expand Down Expand Up @@ -2582,6 +2650,10 @@
"type": "?.",
"named": false
},
{
"type": "?:",
"named": false
},
{
"type": "?[",
"named": false
Expand Down Expand Up @@ -2704,11 +2776,11 @@
},
{
"type": "float",
"named": true
"named": false
},
{
"type": "float",
"named": false
"named": true
},
{
"type": "for",
Expand Down
Loading

0 comments on commit a32ed22

Please sign in to comment.