Fix with_clause

pull/70/head
Stephan Seitz 2021-11-28 13:03:47 +07:00
parent 90d1c56314
commit 9a33a3412f
5 changed files with 89555 additions and 76182 deletions

@ -114,12 +114,16 @@ function clSymbol(symbol) {
return seq(optional(seq('cl', ':')), symbol)
}
function optSeq(...args) {
return optional(seq(...args))
}
module.exports = grammar(clojure, {
name: 'commonlisp',
extras: ($, original) => [...original, $.block_comment],
conflicts: ($, original) => [...original, [$.with_clause], [$.for_clause], [$.accumulation_clause], [$.loop_macro, $.defun_keyword, $.package_lit]],
conflicts: ($, original) => [...original, [$.with_clause, $.package_lit], [$.with_clause], [$.for_clause], [$.accumulation_clause], [$.loop_macro, $.defun_keyword, $.package_lit]],
rules: {
block_comment: _ => token(seq('#|', repeat(choice(/[^|]/, /\|[^#]/)), '|#')),
@ -226,7 +230,7 @@ module.exports = grammar(clojure, {
for_clause: $ => choice(seq(choice(clSymbol('for'), clSymbol('and'), clSymbol('as')), repeat($._gap), field('variable', $._form), optional(field('type', seq(repeat($._gap), $._form))),
repeat1($._for_part)), clSymbol('and')),
with_clause: $ => seq(clSymbol('with'), repeat($._gap), $._form, optional(field('type', repeat($._gap), $._form)), repeat($._gap), optional(clSymbol("=")), repeat($._gap), optional($._form)),
with_clause: $ => seq(clSymbol('with'), repeat($._gap), choice($._form, seq($._form, repeat($._gap), field('type', $._form))), repeat($._gap), optSeq(clSymbol("="), repeat($._gap)), optSeq($._form, repeat($._gap))),
do_clause: $ => prec.left(seq(clSymbol('do'), repeat1(prec.left(seq(repeat($._gap), $._form, repeat($._gap)))))),
while_clause: $ => prec.left(seq(choice(clSymbol('while'), clSymbol('until')), repeat($._gap), $._form)),
repeat_clause: $ => prec.left(seq(clSymbol('repeat'), repeat($._gap), $._form)),

@ -2759,26 +2759,36 @@
"name": "_gap"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_form"
},
{
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "_form"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
}
},
{
"type": "BLANK"
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "_form"
}
}
]
}
]
},
@ -2792,6 +2802,9 @@
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
@ -2822,25 +2835,39 @@
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_form"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
}
]
},
{
"type": "BLANK"
}
@ -4193,6 +4220,10 @@
}
],
"conflicts": [
[
"with_clause",
"package_lit"
],
[
"with_clause"
],

@ -4299,11 +4299,99 @@
"required": false,
"types": [
{
"type": "comment",
"type": "#",
"named": false
},
{
"type": ".",
"named": false
},
{
"type": "char_lit",
"named": true
},
{
"type": "dis_expr",
"type": "complex_num_lit",
"named": true
},
{
"type": "fancy_literal",
"named": true
},
{
"type": "include_reader_macro",
"named": true
},
{
"type": "kwd_lit",
"named": true
},
{
"type": "list_lit",
"named": true
},
{
"type": "nil_lit",
"named": true
},
{
"type": "num_lit",
"named": true
},
{
"type": "package_lit",
"named": true
},
{
"type": "path_lit",
"named": true
},
{
"type": "quoting_lit",
"named": true
},
{
"type": "read_cond_lit",
"named": true
},
{
"type": "self_referential_reader_macro",
"named": true
},
{
"type": "set_lit",
"named": true
},
{
"type": "splicing_read_cond_lit",
"named": true
},
{
"type": "str_lit",
"named": true
},
{
"type": "sym_lit",
"named": true
},
{
"type": "syn_quoting_lit",
"named": true
},
{
"type": "unquote_splicing_lit",
"named": true
},
{
"type": "unquoting_lit",
"named": true
},
{
"type": "var_quoting_lit",
"named": true
},
{
"type": "vec_lit",
"named": true
}
]

File diff suppressed because it is too large Load Diff

@ -1175,3 +1175,33 @@ loop with
(list_lit
(sym_lit)
(sym_lit)))))))
================================================================================
loop with 2
================================================================================
(loop with consecutive-yields fixnum = 0)
(loop with consecutive-yields fixnum = 0 do
(block block))
--------------------------------------------------------------------------------
(source
(list_lit
(loop_macro
(loop_clause
(with_clause
(sym_lit)
(sym_lit)
(num_lit)))))
(list_lit
(loop_macro
(loop_clause
(with_clause
(sym_lit)
(sym_lit)
(num_lit)))
(loop_clause
(do_clause
(list_lit
(sym_lit)
(sym_lit)))))))