Skip to content

Commit

Permalink
fix declaration bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
victorhqc committed Sep 19, 2019
1 parent 85dca95 commit eaf6eb9
Show file tree
Hide file tree
Showing 5 changed files with 4,347 additions and 6,053 deletions.
16 changes: 16 additions & 0 deletions corpus/model.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ model User {
id Int
email String?
posts Post?[]
type String
number Int?
}

---
Expand Down Expand Up @@ -35,6 +37,20 @@ model User {
)
(new_line)
)
(column_declaration
(identifier)
(column_type
(identifier)
)
(new_line)
)
(column_declaration
(identifier)
(column_type
(identifier)
)
(new_line)
)
)
)
)
Expand Down
29 changes: 10 additions & 19 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,12 @@ module.exports = grammar({
// ],

conflicts: $ => [
[$.type_declaration, $.column_declaration],
[$.column_declaration, $.type_declaration],
[$.assignment_pattern, $.assignment_expression],
],

rules: {
program: $ => repeat($._definition),

_definition: $ => choice(
$.datasource_declaration,
$.model_declaration,
$.type_declaration,
$.generator_declaration,
),
program: $ => repeat($._declaration),

datasource_declaration: $ => seq(
'datasource',
Expand All @@ -86,6 +79,13 @@ module.exports = grammar({
),
)),

_declaration: $ => choice(
$.datasource_declaration,
$.model_declaration,
$.generator_declaration,
$.type_declaration,
),

comment: $ => token(
seq('//', /.*/),
),
Expand All @@ -97,13 +97,6 @@ module.exports = grammar({
)),

_statement: $ => choice(
$._declaration,
),

_declaration: $ => choice(
$.datasource_declaration,
$.model_declaration,
$.type_declaration,
$.column_declaration,
$.block_attribute_declaration,
$.assignment_expression,
Expand Down Expand Up @@ -134,7 +127,6 @@ module.exports = grammar({
$.type_expression,
$.block_attribute_declaration,
$.namespace,
// $.column_type,
$.member_expression,
$.number,
$.string,
Expand Down Expand Up @@ -245,15 +237,14 @@ module.exports = grammar({
// $.name_pattern,
),


_expression: $ => choice(
$._constructable_expression,

$.assignment_expression,
$.call_expression,
$.binary_expression,
),
//

// identifier: $ => /[a-zA-Z-_][a-zA-Z0-9-_]*/,
identifier: $ => /[a-zA-Z-_][a-zA-Z0-9-_]*/,
string: $ => token(choice(
Expand Down
69 changes: 24 additions & 45 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,9 @@
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_definition"
"name": "_declaration"
}
},
"_definition": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "datasource_declaration"
},
{
"type": "SYMBOL",
"name": "model_declaration"
},
{
"type": "SYMBOL",
"name": "type_declaration"
},
{
"type": "SYMBOL",
"name": "generator_declaration"
}
]
},
"datasource_declaration": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -100,6 +79,27 @@
]
}
},
"_declaration": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "datasource_declaration"
},
{
"type": "SYMBOL",
"name": "model_declaration"
},
{
"type": "SYMBOL",
"name": "generator_declaration"
},
{
"type": "SYMBOL",
"name": "type_declaration"
}
]
},
"comment": {
"type": "TOKEN",
"content": {
Expand Down Expand Up @@ -143,27 +143,6 @@
"_statement": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_declaration"
}
]
},
"_declaration": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "datasource_declaration"
},
{
"type": "SYMBOL",
"name": "model_declaration"
},
{
"type": "SYMBOL",
"name": "type_declaration"
},
{
"type": "SYMBOL",
"name": "column_declaration"
Expand Down Expand Up @@ -1206,8 +1185,8 @@
],
"conflicts": [
[
"type_declaration",
"column_declaration"
"column_declaration",
"type_declaration"
],
[
"assignment_pattern",
Expand Down
12 changes: 0 additions & 12 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -746,18 +746,6 @@
{
"type": "column_declaration",
"named": true
},
{
"type": "datasource_declaration",
"named": true
},
{
"type": "model_declaration",
"named": true
},
{
"type": "type_declaration",
"named": true
}
]
}
Expand Down
Loading

0 comments on commit eaf6eb9

Please sign in to comment.