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) return seq(optional(seq('cl', ':')), symbol)
} }
function optSeq(...args) {
return optional(seq(...args))
}
module.exports = grammar(clojure, { module.exports = grammar(clojure, {
name: 'commonlisp', name: 'commonlisp',
extras: ($, original) => [...original, $.block_comment], 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: { rules: {
block_comment: _ => token(seq('#|', repeat(choice(/[^|]/, /\|[^#]/)), '|#')), 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))), 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')), 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)))))), 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)), while_clause: $ => prec.left(seq(choice(clSymbol('while'), clSymbol('until')), repeat($._gap), $._form)),
repeat_clause: $ => prec.left(seq(clSymbol('repeat'), repeat($._gap), $._form)), repeat_clause: $ => prec.left(seq(clSymbol('repeat'), repeat($._gap), $._form)),

@ -2759,26 +2759,36 @@
"name": "_gap" "name": "_gap"
} }
}, },
{
"type": "SYMBOL",
"name": "_form"
},
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "FIELD", "type": "SYMBOL",
"name": "type", "name": "_form"
"content": {
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
}
}, },
{ {
"type": "BLANK" "type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_form"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "_form"
}
}
]
} }
] ]
}, },
@ -2796,29 +2806,41 @@
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "CHOICE", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SEQ", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "STRING", "type": "SEQ",
"value": "cl" "members": [
{
"type": "STRING",
"value": "cl"
},
{
"type": "STRING",
"value": ":"
}
]
}, },
{ {
"type": "STRING", "type": "BLANK"
"value": ":"
} }
] ]
}, },
{ {
"type": "BLANK" "type": "STRING",
"value": "="
} }
] ]
}, },
{ {
"type": "STRING", "type": "REPEAT",
"value": "=" "content": {
"type": "SYMBOL",
"name": "_gap"
}
} }
] ]
}, },
@ -2827,19 +2849,24 @@
} }
] ]
}, },
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
},
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SEQ",
"name": "_form" "members": [
{
"type": "SYMBOL",
"name": "_form"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_gap"
}
}
]
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -4193,6 +4220,10 @@
} }
], ],
"conflicts": [ "conflicts": [
[
"with_clause",
"package_lit"
],
[ [
"with_clause" "with_clause"
], ],

@ -4299,11 +4299,99 @@
"required": false, "required": false,
"types": [ "types": [
{ {
"type": "comment", "type": "#",
"named": false
},
{
"type": ".",
"named": false
},
{
"type": "char_lit",
"named": true "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 "named": true
} }
] ]

File diff suppressed because it is too large Load Diff

@ -1175,3 +1175,33 @@ loop with
(list_lit (list_lit
(sym_lit) (sym_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)))))))