Skip to content

Commit

Permalink
Improved code for Schema, Rule and Mixin Statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishalk91-4 committed Aug 11, 2024
1 parent 4585159 commit c5b6fd0
Show file tree
Hide file tree
Showing 5 changed files with 176,868 additions and 168,279 deletions.
46 changes: 33 additions & 13 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ module.exports = grammar({

// Simple statements

_simple_statements: $ => seq(
_simple_statements: $ => prec(24, seq(
$._simple_statement,
$._newline,
),
)),

_simple_statement: $ => choice(
$.expression,
Expand All @@ -225,6 +225,7 @@ module.exports = grammar({
$.import_statement,
$.assert_statement,
$.type_alias_statement,
$.mixin_statement,
),

import_statement: $ => seq(
Expand Down Expand Up @@ -313,15 +314,28 @@ module.exports = grammar({
)
)),

rule_statement: $ => seq(
rule_statement: $ => prec.left(seq(
'rule',
field('name', $.identifier),
field('name', $.parameter),
optional(seq(
'(',
field('base', $.identifier),
')'
)),
optional(seq(
'for',
field('protocol', $.identifier)
field('protocol', $.identifier),
)),
':',
field('body', $._suite)
field('body', $._suite),
)),

parameter_list: $ => seq(
$.identifier,
repeat(seq(
',',
$.identifier
))
),

elif_clause: $ => seq(
Expand Down Expand Up @@ -465,18 +479,22 @@ module.exports = grammar({
field('base', $.identifier),
')'
)),
optional(seq(
'for',
field('protocol', $.identifier),
)),
':',
field('body', $._suite),
)),

mixin_statement: $ => seq(
'mixin',
field('name', $.identifier),
'for',
field('protocol', $.identifier),
':',
field('body', $._suite),
),
field('name', $.primary_expression),
optional(seq('for',
field('protocol', $.identifier),
':',
field('body', $._suite),
))),

protocol_statement: $ => seq(
'protocol',
Expand Down Expand Up @@ -541,6 +559,8 @@ module.exports = grammar({
_suite: $ => choice(
alias($._simple_statements, $.block),
seq($._indent, $.block),
seq($.assignment, $._newline),
seq($.comparison_operator, $._newline),
alias($._newline, $.block),
),

Expand Down Expand Up @@ -648,7 +668,7 @@ module.exports = grammar({

not_operator: $ => prec(PREC.not, seq(
'not',
field('argument', $.expression),
field('argument', $.primary_expression),
)),

boolean_operator: $ => choice(
Expand Down
167 changes: 132 additions & 35 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@
]
},
"_simple_statements": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_simple_statement"
},
{
"type": "SYMBOL",
"name": "_newline"
}
]
"type": "PREC",
"value": 24,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_simple_statement"
},
{
"type": "SYMBOL",
"name": "_newline"
}
]
}
},
"_simple_statement": {
"type": "CHOICE",
Expand Down Expand Up @@ -65,6 +69,10 @@
{
"type": "SYMBOL",
"name": "type_alias_statement"
},
{
"type": "SYMBOL",
"name": "mixin_statement"
}
]
},
Expand Down Expand Up @@ -560,6 +568,31 @@
}
]
},
"parameter_list": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
}
}
]
},
"elif_clause": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -1197,6 +1230,31 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "for"
},
{
"type": "FIELD",
"name": "protocol",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ":"
Expand Down Expand Up @@ -1224,32 +1282,45 @@
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "for"
},
{
"type": "FIELD",
"name": "protocol",
"content": {
"type": "SYMBOL",
"name": "identifier"
"name": "primary_expression"
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "_suite"
}
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "for"
},
{
"type": "FIELD",
"name": "protocol",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "_suite"
}
}
]
},
{
"type": "BLANK"
}
]
}
]
},
Expand Down Expand Up @@ -1503,6 +1574,32 @@
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "assignment"
},
{
"type": "SYMBOL",
"name": "_newline"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "comparison_operator"
},
{
"type": "SYMBOL",
"name": "_newline"
}
]
},
{
"type": "ALIAS",
"content": {
Expand Down Expand Up @@ -1969,7 +2066,7 @@
"name": "argument",
"content": {
"type": "SYMBOL",
"name": "expression"
"name": "primary_expression"
}
}
]
Expand Down
Loading

0 comments on commit c5b6fd0

Please sign in to comment.