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> * Copyright (C) 2021 Stephan Seitz <stephan.seitz@fau.de>
* Adapted from tree-sitter-clojure * 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"); 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_keyword: _ => prec(10, clSymbol(choice('defun', 'defmacro', 'defgeneric', 'defmethod'))),
defun_header: $ => 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), seq(field('keyword', $.defun_keyword),
repeat($._gap), repeat($._gap),
field('function_name', $._form), field('function_name', $._form),
@ -285,7 +289,7 @@ module.exports = grammar(clojure, {
seq(field('keyword', alias('lambda', $.defun_keyword)), seq(field('keyword', alias('lambda', $.defun_keyword)),
repeat($._gap), repeat($._gap),
field('lambda_list', choice($.list_lit, $.unquoting_lit))) field('lambda_list', choice($.list_lit, $.unquoting_lit)))
), )),
array_dimension: _ => prec(100, /\d+[aA]/), array_dimension: _ => prec(100, /\d+[aA]/),

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

@ -601,7 +601,7 @@
}, },
"lambda_list": { "lambda_list": {
"multiple": false, "multiple": false,
"required": true, "required": false,
"types": [ "types": [
{ {
"type": "list_lit", "type": "list_lit",
@ -657,6 +657,14 @@
{ {
"type": "dis_expr", "type": "dis_expr",
"named": true "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))))))))))))) (sym_lit)))))))))))))
================================================================================ ================================================================================
Unquoting in defun Unquoting in defun 2
================================================================================ ================================================================================
`((defmacro ,name))
(defun ,foo ,arguments `((defmacro ,name))
) `((defmacro ,name)
,(function-location (macro-function name)))
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source (source
(list_lit (syn_quoting_lit
(defun (list_lit
(defun_header (list_lit
(defun_keyword) (defun
(unquoting_lit (defun_header
(sym_lit)) (defun_keyword)
(unquoting_lit (unquoting_lit
(sym_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 Weird quoting