Add loop test

pull/70/head
Stephan Seitz 2021-04-03 02:31:47 +07:00
parent fbf1f672c5
commit cc0a1401cf
6 changed files with 13566 additions and 13216 deletions

@ -23,7 +23,7 @@ module.exports = grammar(clojure, {
name: 'commonlisp', name: 'commonlisp',
extras: ($, original) => [...original, $.block_comment], extras: ($, original) => [...original, $.block_comment],
conflicts: ($, original) => [...original, [$.for_clause]], conflicts: ($, original) => [...original, [$.for_clause], [$.accumulation_clause]],
rules: { rules: {
block_comment: _ => token(seq('#|', repeat(choice(/[^|]/, /\|[^#]/)), '|#')), block_comment: _ => token(seq('#|', repeat(choice(/[^|]/, /\|[^#]/)), '|#')),
@ -61,13 +61,13 @@ module.exports = grammar(clojure, {
accumulation_verb: _ => /(collect|append|nconc|count|sum|maximize|minimize)(ing)?/, accumulation_verb: _ => /(collect|append|nconc|count|sum|maximize|minimize)(ing)?/,
for_clause: $ => seq(choice('for', 'and'), optional($._gap), field('variable', $.sym_lit), for_clause: $ => seq(choice('for', 'and'), optional($._gap), field('variable', $._form),
$._for_part, optional($._for_part)), $._for_part, optional($._for_part)),
with_clause: $ => prec.left(seq('with', optional($._gap), $._form, optional($._gap), "=", optional($._gap), $._form)), with_clause: $ => prec.left(seq('with', optional($._gap), $._form, optional($._gap), "=", optional($._gap), $._form)),
do_clause: $ => prec.left(seq('do', optional($._gap), $._form)), do_clause: $ => prec.left(seq('do', optional($._gap), $._form)),
condition_clause: $ => prec.left(seq(choice('when', 'if', 'unless', 'always', 'thereis', 'never'), optional($._gap), $._form)), condition_clause: $ => prec.left(seq(choice('when', 'if', 'unless', 'always', 'thereis', 'never'), optional($._gap), $._form)),
accumulation_clause: $ => prec.left(seq($.accumulation_verb, optional($._gap), $._form, optional($._gap), optional(seq('into', optional($._gap), $._form)))), accumulation_clause: $ => seq($.accumulation_verb, optional($._gap), $._form, optional(seq(optional($._gap), 'into', optional($._gap), $._form))),
termination_clause: $ => prec.left(seq(choice('finally', 'return', 'initially'), optional($._gap), $._form)), termination_clause: $ => prec.left(seq(choice('finally', 'return', 'initially'), optional($._gap), $._form)),

@ -1907,7 +1907,7 @@
"name": "variable", "name": "variable",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "sym_lit" "name": "_form"
} }
}, },
{ {
@ -2073,78 +2073,74 @@
} }
}, },
"accumulation_clause": { "accumulation_clause": {
"type": "PREC_LEFT", "type": "SEQ",
"value": 0, "members": [
"content": { {
"type": "SEQ", "type": "SYMBOL",
"members": [ "name": "accumulation_verb"
{ },
"type": "SYMBOL", {
"name": "accumulation_verb" "type": "CHOICE",
}, "members": [
{ {
"type": "CHOICE", "type": "SYMBOL",
"members": [ "name": "_gap"
{ },
"type": "SYMBOL", {
"name": "_gap" "type": "BLANK"
}, }
{ ]
"type": "BLANK" },
} {
] "type": "SYMBOL",
}, "name": "_form"
{ },
"type": "SYMBOL", {
"name": "_form" "type": "CHOICE",
}, "members": [
{ {
"type": "CHOICE", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "CHOICE",
"name": "_gap" "members": [
}, {
{ "type": "SYMBOL",
"type": "BLANK" "name": "_gap"
} },
] {
}, "type": "BLANK"
{ }
"type": "CHOICE", ]
"members": [ },
{ {
"type": "SEQ", "type": "STRING",
"members": [ "value": "into"
{ },
"type": "STRING", {
"value": "into" "type": "CHOICE",
}, "members": [
{ {
"type": "CHOICE", "type": "SYMBOL",
"members": [ "name": "_gap"
{ },
"type": "SYMBOL", {
"name": "_gap" "type": "BLANK"
}, }
{ ]
"type": "BLANK" },
} {
] "type": "SYMBOL",
}, "name": "_form"
{ }
"type": "SYMBOL", ]
"name": "_form" },
} {
] "type": "BLANK"
}, }
{ ]
"type": "BLANK" }
} ]
]
}
]
}
}, },
"termination_clause": { "termination_clause": {
"type": "PREC_LEFT", "type": "PREC_LEFT",
@ -2354,6 +2350,9 @@
"conflicts": [ "conflicts": [
[ [
"for_clause" "for_clause"
],
[
"accumulation_clause"
] ]
], ],
"precedences": [], "precedences": [],

@ -904,9 +904,85 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "char_lit",
"named": true
},
{
"type": "derefing_lit",
"named": true
},
{
"type": "evaling_lit",
"named": true
},
{
"type": "fancy_literal",
"named": true
},
{
"type": "kwd_lit",
"named": true
},
{
"type": "list_lit",
"named": true
},
{
"type": "nil_lit",
"named": true
},
{
"type": "num_lit",
"named": true
},
{
"type": "quoting_lit",
"named": true
},
{
"type": "read_cond_lit",
"named": true
},
{
"type": "set_lit",
"named": true
},
{
"type": "splicing_read_cond_lit",
"named": true
},
{
"type": "str_lit",
"named": true
},
{ {
"type": "sym_lit", "type": "sym_lit",
"named": true "named": true
},
{
"type": "sym_val_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

@ -1,7 +1,9 @@
(loop for dim-idx in xyz below x (loop for dim-idx in xyz below x
for y from 0 for y from 0
for letter in (list 'x 'y 'z) in 2 for letter in (list 'x 'y 'z) in 2
collect x) collect x into 1)
(loop for x below 3 in 2 (loop for x below 3 in 2
do (format t "~A~%" x)) do (format t "~A~%" x))
(asd into)

@ -100,3 +100,12 @@ Loop Macro
--- ---
(source (list_lit (loop_macro (loop_clause (for_clause (sym_lit) (sym_lit))) (loop_clause (for_clause (sym_lit) (list_lit (sym_lit) (quoting_lit (sym_lit)) (quoting_lit (sym_lit)) (quoting_lit (sym_lit))))) (loop_clause (accumulation_clause (accumulation_verb) (list_lit (sym_lit) (list_lit (list_lit (sym_lit) (list_lit (sym_lit) (sym_lit) (sym_lit)))) (syn_quoting_lit (list_lit (unquoting_lit (list_lit (sym_lit) (sym_lit))) (list_lit (sym_lit) (unquoting_lit (list_lit (sym_lit) (sym_lit))) (list_lit (sym_lit) (unquoting_lit (list_lit (sym_lit) (sym_lit))) (unquoting_lit (list_lit (sym_lit) (sym_lit) (list_lit (sym_lit) (quoting_lit (list_lit (sym_lit) (sym_lit) (list_lit (sym_lit) (sym_lit) (sym_lit))))) (list_lit (sym_lit) (quoting_lit (list_lit (sym_lit) (sym_lit) (list_lit (sym_lit) (sym_lit) (sym_lit))))) (list_lit (source (list_lit (loop_macro (loop_clause (for_clause (sym_lit) (sym_lit))) (loop_clause (for_clause (sym_lit) (list_lit (sym_lit) (quoting_lit (sym_lit)) (quoting_lit (sym_lit)) (quoting_lit (sym_lit))))) (loop_clause (accumulation_clause (accumulation_verb) (list_lit (sym_lit) (list_lit (list_lit (sym_lit) (list_lit (sym_lit) (sym_lit) (sym_lit)))) (syn_quoting_lit (list_lit (unquoting_lit (list_lit (sym_lit) (sym_lit))) (list_lit (sym_lit) (unquoting_lit (list_lit (sym_lit) (sym_lit))) (list_lit (sym_lit) (unquoting_lit (list_lit (sym_lit) (sym_lit))) (unquoting_lit (list_lit (sym_lit) (sym_lit) (list_lit (sym_lit) (quoting_lit (list_lit (sym_lit) (sym_lit) (list_lit (sym_lit) (sym_lit) (sym_lit))))) (list_lit (sym_lit) (quoting_lit (list_lit (sym_lit) (sym_lit) (list_lit (sym_lit) (sym_lit) (sym_lit))))) (list_lit
(sym_lit) (quoting_lit (list_lit (sym_lit) (sym_lit) (list_lit (sym_lit) (sym_lit) (sym_lit))))))))))))))))) (sym_lit) (quoting_lit (list_lit (sym_lit) (sym_lit) (list_lit (sym_lit) (sym_lit) (sym_lit)))))))))))))))))
==========================================
Loop Macro (Accumulation)
==========================================
(loop for i below 10
collect x into a)
---
(source (list_lit (loop_macro (loop_clause (for_clause (sym_lit) (num_lit))) (loop_clause (accumulation_clause (accumulation_verb) (sym_lit) (sym_lit))))))