Fix unquoting in defuns

pull/70/head
Stephan Seitz 2021-11-28 14:51:05 +07:00
parent 9a7474e00d
commit cfce2b5a58
5 changed files with 71458 additions and 71163 deletions

@ -3,7 +3,7 @@
* Copyright (C) 2021 Stephan Seitz <stephan.seitz@fau.de>
* Adapted from tree-sitter-clojure
*
* Distributed under terms of the GPLv3 license.
* Distributed under terms of the MIT license.
*/
const clojure = require("tree-sitter-clojure/grammar");
@ -275,7 +275,11 @@ module.exports = grammar(clojure, {
defun_keyword: _ => prec(10, clSymbol(choice('defun', 'defmacro', 'defgeneric', 'defmethod'))),
defun_header: $ =>
choice(
prec(PREC.SPECIAL, choice(
seq(field('keyword', $.defun_keyword),
repeat($._gap),
choice($.unquoting_lit, $.unquote_splicing_lit)
),
seq(field('keyword', $.defun_keyword),
repeat($._gap),
field('function_name', $._form),
@ -285,7 +289,7 @@ module.exports = grammar(clojure, {
seq(field('keyword', alias('lambda', $.defun_keyword)),
repeat($._gap),
field('lambda_list', choice($.list_lit, $.unquoting_lit)))
),
)),
array_dimension: _ => prec(100, /\d+[aA]/),

@ -3888,140 +3888,177 @@
}
},
"defun_header": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "keyword",
"content": {
"type": "SYMBOL",
"name": "defun_keyword"
}
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
},
{
"type": "FIELD",
"name": "function_name",
"content": {
"type": "SYMBOL",
"name": "_form"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "specifier",
"content": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "kwd_lit"
},
{
"type": "SYMBOL",
"name": "sym_lit"
}
]
}
]
}
},
{
"type": "BLANK"
"type": "PREC",
"value": 5,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "keyword",
"content": {
"type": "SYMBOL",
"name": "defun_keyword"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
},
{
"type": "FIELD",
"name": "lambda_list",
"content": {
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "list_lit"
"name": "unquoting_lit"
},
{
"type": "SYMBOL",
"name": "unquoting_lit"
"name": "unquote_splicing_lit"
}
]
}
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "keyword",
"content": {
"type": "ALIAS",
]
},
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "keyword",
"content": {
"type": "STRING",
"value": "lambda"
},
"named": true,
"value": "defun_keyword"
}
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
},
{
"type": "FIELD",
"name": "lambda_list",
"content": {
"type": "SYMBOL",
"name": "defun_keyword"
}
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
},
{
"type": "FIELD",
"name": "function_name",
"content": {
"type": "SYMBOL",
"name": "_form"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "list_lit"
"type": "FIELD",
"name": "specifier",
"content": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "kwd_lit"
},
{
"type": "SYMBOL",
"name": "sym_lit"
}
]
}
]
}
},
{
"type": "SYMBOL",
"name": "unquoting_lit"
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
},
{
"type": "FIELD",
"name": "lambda_list",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "list_lit"
},
{
"type": "SYMBOL",
"name": "unquoting_lit"
}
]
}
}
}
]
}
]
]
},
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "keyword",
"content": {
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "lambda"
},
"named": true,
"value": "defun_keyword"
}
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
},
{
"type": "FIELD",
"name": "lambda_list",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "list_lit"
},
{
"type": "SYMBOL",
"name": "unquoting_lit"
}
]
}
}
]
}
]
}
},
"array_dimension": {
"type": "PREC",

@ -601,7 +601,7 @@
},
"lambda_list": {
"multiple": false,
"required": true,
"required": false,
"types": [
{
"type": "list_lit",
@ -657,6 +657,14 @@
{
"type": "dis_expr",
"named": true
},
{
"type": "unquote_splicing_lit",
"named": true
},
{
"type": "unquoting_lit",
"named": true
}
]
}

File diff suppressed because it is too large Load Diff

@ -775,23 +775,45 @@ Multiple gaps in Loop
(sym_lit)))))))))))))
================================================================================
Unquoting in defun
Unquoting in defun 2
================================================================================
(defun ,foo ,arguments
)
`((defmacro ,name))
`((defmacro ,name))
`((defmacro ,name)
,(function-location (macro-function name)))
--------------------------------------------------------------------------------
(source
(list_lit
(defun
(defun_header
(defun_keyword)
(unquoting_lit
(sym_lit))
(unquoting_lit
(sym_lit))))))
(syn_quoting_lit
(list_lit
(list_lit
(defun
(defun_header
(defun_keyword)
(unquoting_lit
(sym_lit)))))))
(syn_quoting_lit
(list_lit
(list_lit
(defun
(defun_header
(defun_keyword)
(unquoting_lit
(sym_lit)))))))
(syn_quoting_lit
(list_lit
(list_lit
(defun
(defun_header
(defun_keyword)
(unquoting_lit
(sym_lit)))))
(unquoting_lit
(list_lit
(sym_lit)
(list_lit
(sym_lit)
(sym_lit)))))))
================================================================================
Weird quoting