Skip to content

Commit

Permalink
fix: model parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
victorhqc committed Sep 19, 2019
1 parent dbfd7c4 commit 27fe749
Show file tree
Hide file tree
Showing 5 changed files with 2,228 additions and 3,241 deletions.
112 changes: 85 additions & 27 deletions corpus/model.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,31 @@ model User {
(column_type
(identifier)
)
(new_line)
)
(column_declaration
(identifier)
(column_type
(identifier)
)
(new_line)
)
(column_declaration
(identifier)
(column_type
(identifier)
(array)
)
(new_line)
)
(column_declaration
(identifier)
(column_type
(identifier)
)
(new_line)
)
(column_declaration
(identifier)
(column_type
(identifier)
)
(new_line)
)
)
)
Expand All @@ -75,50 +70,113 @@ model User {
(column_type
(identifier)
)
(column_relation
(namespace
(call_expression
(identifier)
(arguments
(call_expression
(identifier)
(arguments)
)
(namespace
(call_expression
(identifier)
(arguments
(call_expression
(identifier)
(arguments)
)
)
)
(namespace
)
(namespace
(identifier)
)
)
(column_declaration
(identifier)
(column_type
(identifier)
)
(namespace
(identifier)
)
)
(column_declaration
(identifier)
(column_type
(identifier)
)
(namespace
(call_expression
(identifier)
(arguments)
)
)
(new_line)
)
)
)
)

=========================
Model with object namespace
=========================

model User {
id Number @id @db.int
}

---

(program
(model_declaration (identifier)
(statement_block
(column_declaration
(identifier)
(column_type
(identifier)
)
(column_relation
(namespace
(namespace
(identifier)
)
(namespace
(member_expression
(identifier)
(property_identifier)
)
)
(new_line)
)
)
)
)

===============================
Model with multiline column
===============================

model User {
id String @id
@default
first_name LongNumeric @default
}

---

(program
(model_declaration (identifier)
(statement_block
(column_declaration
(identifier)
(column_type
(identifier)
)
(column_relation
(namespace
(call_expression
(identifier)
(arguments)
)
)
(namespace
(identifier)
)
(namespace
(identifier)
)
)
(column_declaration
(identifier)
(column_type
(identifier)
)
(namespace
(identifier)
)
(new_line)
)
)
)
Expand Down
16 changes: 3 additions & 13 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ module.exports = grammar({
column_declaration: $ => seq(
$.identifier,
$.column_type,
optional($.column_relation),
// TODO: Check if it's really needed
$.new_line,
optional(repeat(
$.namespace
)),
),

assignment_pattern: $ => seq(
Expand Down Expand Up @@ -197,10 +197,6 @@ module.exports = grammar({
optional($.array),
),

column_relation: $ => repeat1(
$.namespace,
),

type_expression: $ => seq(
$.identifier,
':',
Expand Down Expand Up @@ -277,12 +273,6 @@ module.exports = grammar({
']'
),

// TODO: Check if it's really needed.
new_line: $ => seq(
'\n',
),


true: $ => 'true',
false: $ => 'false',
null: $ => 'null',
Expand Down
27 changes: 5 additions & 22 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,16 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "column_relation"
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "namespace"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "new_line"
}
]
},
Expand Down Expand Up @@ -845,13 +844,6 @@
}
]
},
"column_relation": {
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "namespace"
}
},
"type_expression": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -1200,15 +1192,6 @@
}
]
},
"new_line": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\n"
}
]
},
"true": {
"type": "STRING",
"value": "true"
Expand Down
28 changes: 0 additions & 28 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,6 @@
"multiple": true,
"required": false,
"types": [
{
"type": "column_relation",
"named": true
},
{
"type": "column_type",
"named": true
Expand All @@ -480,21 +476,6 @@
"type": "identifier",
"named": true
},
{
"type": "new_line",
"named": true
}
]
}
},
{
"type": "column_relation",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "namespace",
"named": true
Expand Down Expand Up @@ -739,11 +720,6 @@
]
}
},
{
"type": "new_line",
"named": true,
"fields": {}
},
{
"type": "program",
"named": true,
Expand Down Expand Up @@ -1100,10 +1076,6 @@
"type": "]",
"named": false
},
{
"type": "\n",
"named": false
},
{
"type": "true",
"named": true
Expand Down
Loading

0 comments on commit 27fe749

Please sign in to comment.