Fix #5: allow package literal "cl"

pull/70/head
Stephan Seitz 2021-11-27 12:00:27 +07:00
parent 0e6fb49af1
commit b506e326cd
5 changed files with 64247 additions and 63439 deletions

@ -119,7 +119,7 @@ module.exports = grammar(clojure, {
name: 'commonlisp', name: 'commonlisp',
extras: ($, original) => [...original, $.block_comment], extras: ($, original) => [...original, $.block_comment],
conflicts: ($, original) => [...original, [$.for_clause], [$.accumulation_clause],], conflicts: ($, original) => [...original, [$.for_clause], [$.accumulation_clause], [$.loop_macro, $.defun_keyword, $.package_lit]],
rules: { rules: {
block_comment: _ => token(seq('#|', repeat(choice(/[^|]/, /\|[^#]/)), '|#')), block_comment: _ => token(seq('#|', repeat(choice(/[^|]/, /\|[^#]/)), '|#')),
@ -257,7 +257,7 @@ module.exports = grammar(clojure, {
repeat(choice($.loop_clause, $._gap)), repeat(choice($.loop_clause, $._gap)),
field('close', ")"))), field('close', ")"))),
defun_keyword: _ => clSymbol(choice('defun', 'defmacro', 'defgeneric', 'defmethod')), defun_keyword: _ => prec(10, clSymbol(choice('defun', 'defmacro', 'defgeneric', 'defmethod'))),
defun_header: $ => defun_header: $ =>
choice( choice(
@ -294,11 +294,11 @@ module.exports = grammar(clojure, {
repeat(choice(field('value', $._form), $._gap)), repeat(choice(field('value', $._form), $._gap)),
field('close', ")"))), field('close', ")"))),
package_lit: $ => prec(PREC.PACKAGE_LIT, seq( package_lit: $ => prec(PREC.PACKAGE_LIT, choice(seq(
field('package', choice($.sym_lit, 'cl')), // Make optional, instead of keywords? field('package', choice($.sym_lit, 'cl')), // Make optional, instead of keywords?
choice(':', '::'), choice(':', '::'),
field('symbol', $.sym_lit) field('symbol', $.sym_lit)
)), ), prec(1, 'cl'))),
_package_lit_without_slash: $ => seq( _package_lit_without_slash: $ => seq(
field('package', choice($._sym_lit_without_slash, 'cl')), // Make optional, instead of keywords? field('package', choice($._sym_lit_without_slash, 'cl')), // Make optional, instead of keywords?

@ -1645,8 +1645,39 @@
] ]
}, },
"derefing_lit": { "derefing_lit": {
"type": "SYMBOL", "type": "SEQ",
"name": "complex_num_lit" "members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_metadata_lit"
}
},
{
"type": "FIELD",
"name": "marker",
"content": {
"type": "STRING",
"value": "@"
}
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "_form"
}
}
]
}, },
"quoting_lit": { "quoting_lit": {
"type": "SEQ", "type": "SEQ",
@ -3737,51 +3768,55 @@
} }
}, },
"defun_keyword": { "defun_keyword": {
"type": "SEQ", "type": "PREC",
"members": [ "value": 10,
{ "content": {
"type": "CHOICE", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SEQ", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "STRING", "type": "SEQ",
"value": "cl" "members": [
}, {
{ "type": "STRING",
"type": "STRING", "value": "cl"
"value": ":" },
} {
] "type": "STRING",
}, "value": ":"
{ }
"type": "BLANK" ]
} },
] {
}, "type": "BLANK"
{ }
"type": "CHOICE", ]
"members": [ },
{ {
"type": "STRING", "type": "CHOICE",
"value": "defun" "members": [
}, {
{ "type": "STRING",
"type": "STRING", "value": "defun"
"value": "defmacro" },
}, {
{ "type": "STRING",
"type": "STRING", "value": "defmacro"
"value": "defgeneric" },
}, {
{ "type": "STRING",
"type": "STRING", "value": "defgeneric"
"value": "defmethod" },
} {
] "type": "STRING",
} "value": "defmethod"
] }
]
}
]
}
}, },
"defun_header": { "defun_header": {
"type": "CHOICE", "type": "CHOICE",
@ -4008,44 +4043,57 @@
"type": "PREC", "type": "PREC",
"value": 2, "value": 2,
"content": { "content": {
"type": "SEQ", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "FIELD", "type": "SEQ",
"name": "package",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "sym_lit"
},
{
"type": "STRING",
"value": "cl"
}
]
}
},
{
"type": "CHOICE",
"members": [ "members": [
{ {
"type": "STRING", "type": "FIELD",
"value": ":" "name": "package",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "sym_lit"
},
{
"type": "STRING",
"value": "cl"
}
]
}
}, },
{ {
"type": "STRING", "type": "CHOICE",
"value": "::" "members": [
{
"type": "STRING",
"value": ":"
},
{
"type": "STRING",
"value": "::"
}
]
},
{
"type": "FIELD",
"name": "symbol",
"content": {
"type": "SYMBOL",
"name": "sym_lit"
}
} }
] ]
}, },
{ {
"type": "FIELD", "type": "PREC",
"name": "symbol", "value": 1,
"content": { "content": {
"type": "SYMBOL", "type": "STRING",
"name": "sym_lit" "value": "cl"
} }
} }
] ]
@ -4296,6 +4344,11 @@
], ],
[ [
"accumulation_clause" "accumulation_clause"
],
[
"loop_macro",
"defun_keyword",
"package_lit"
] ]
], ],
"precedences": [], "precedences": [],

@ -2218,7 +2218,7 @@
"fields": { "fields": {
"package": { "package": {
"multiple": false, "multiple": false,
"required": true, "required": false,
"types": [ "types": [
{ {
"type": "cl", "type": "cl",
@ -2232,7 +2232,7 @@
}, },
"symbol": { "symbol": {
"multiple": false, "multiple": false,
"required": true, "required": false,
"types": [ "types": [
{ {
"type": "sym_lit", "type": "sym_lit",

File diff suppressed because it is too large Load Diff

@ -1109,3 +1109,19 @@ Self-references
(sym_lit))) (sym_lit)))
(list_lit (list_lit
(sym_lit))))) (sym_lit)))))
================================================================================
Issue #5 (defpackage)
================================================================================
(defpackage foo-bar
(:use cl))
--------------------------------------------------------------------------------
(source
(list_lit
(sym_lit)
(sym_lit)
(list_lit
(kwd_lit
(kwd_symbol))
(package_lit))))