Skip to content

Commit

Permalink
feat: AST comment as specified by prisma docs
Browse files Browse the repository at this point in the history
  • Loading branch information
victorhqc committed Sep 20, 2019
1 parent 5cb11f1 commit 7d81261
Show file tree
Hide file tree
Showing 5 changed files with 2,946 additions and 2,751 deletions.
19 changes: 10 additions & 9 deletions corpus/comments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,44 @@ Comment block

// Hello world
// This is a comment
/// This comment do shows up in AST

---

(program
(comment)
(comment)
)

=====================
Comment in datasource
=====================

// before datasource
// comment for the developer
datasource pg { // this should be fine
provider = "postgresql" // after a column
// url = env.POSTGRES_URL
enabled = true
provider = "postgresql" /// This comment is for documentation
url = env.POSTGRES_URL /// This one as well
// enabled = true
}

---

(program
(comment)
(datasource_declaration
(identifier)
(statement_block
(comment)
(assignment_expression
(variable)
(string)
)
(comment)
(comment)
(assignment_expression
(variable)
(true)
(member_expression
(identifier)
(property_identifier)
)
)
(comment)
)
)
)
9 changes: 5 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ module.exports = grammar({

extras: $ => [
$.comment,
$._comment,
/[\s\uFEFF\u2060\u200B\u00A0]/
],

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

rules: {
Expand Down Expand Up @@ -70,13 +71,13 @@ module.exports = grammar({
$.enum_declaration
),

comment: $ => token(
_comment: $ => token(
seq('//', /.*/),
),

info_comment: $ => token(
comment: $ => prec(PREC.COMMENT, token(
seq('///', /.*/),
),
)),

statement_block: $ => prec.right(seq(
'{',
Expand Down
40 changes: 24 additions & 16 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
}
]
},
"comment": {
"_comment": {
"type": "TOKEN",
"content": {
"type": "SEQ",
Expand All @@ -137,20 +137,24 @@
]
}
},
"info_comment": {
"type": "TOKEN",
"comment": {
"type": "PREC",
"value": 1,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "///"
},
{
"type": "PATTERN",
"value": ".*"
}
]
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "///"
},
{
"type": "PATTERN",
"value": ".*"
}
]
}
}
},
"statement_block": {
Expand Down Expand Up @@ -1231,6 +1235,10 @@
"type": "SYMBOL",
"name": "comment"
},
{
"type": "SYMBOL",
"name": "_comment"
},
{
"type": "PATTERN",
"value": "[\\s\\uFEFF\\u2060\\u200B\\u00A0]"
Expand All @@ -1246,8 +1254,8 @@
"assignment_expression"
],
[
"info_comment",
"comment"
"comment",
"_comment"
]
],
"externals": [],
Expand Down
4 changes: 0 additions & 4 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -936,10 +936,6 @@
"type": "comment",
"named": true
},
{
"type": "info_comment",
"named": true
},
{
"type": "{",
"named": false
Expand Down
Loading

0 comments on commit 7d81261

Please sign in to comment.