639955e3c374386613e3abe29dce904c599d44a0
[software/python-on-guile.git] / modules / language / python / parser.scm
1 (define-module (language python parser)
2 #:use-module (logic guile-log)
3 #:use-module (ice-9 match)
4 #:use-module (ice-9 pretty-print)
5 #:use-module (language python parser-tool)
6 #:export (p))
7
8 (define do-print #t)
9 (define pp
10 (case-lambda
11 ((s x)
12 (when do-print
13 (pretty-print `(,s ,(syntax->datum x))))
14 x)
15 ((x)
16 (when do-print
17 (pretty-print (syntax->datum x)))
18 x)))
19
20
21 (define divide truncate/)
22 ;; +++++++++++++++++++++++++++++++++++++ SCANNER SUBSECTION
23 (define com (f-seq "#" (f* (f-not f-nl)) f-nl))
24 (define w (f-reg "[\t\r| ]"))
25 (define ws+ (f+ (f-or (f-reg "[\t\r| ]") com)))
26 (define ws* (f+ (f-or (f-reg "[\t\r| ]") com)))
27 (define ws ws*)
28 (define nl f-nl)
29
30 (define (wn_ n i)
31 (<p-lambda> (c)
32 (cond
33 ((> i n) <fail>)
34 ((= i n)
35 (.. ((f-not w) c)))
36 ((< i n)
37 (<or>
38 (<and>
39 (.. (c) ((f-tag " ") c))
40 (.. ((wn_ n (+ i 1)) c)))
41 (<and>
42 (.. (c) ((f-tag "\t") c))
43 (.. ((wn_ n (divide (+ i 8) 8)) c)))
44 (<and>
45 (.. (c) ((f-tag "\r") c))
46 (.. ((wn_ n i) c))))))))
47
48 (define (wn+_ n i)
49 (<p-lambda> (c)
50 (cond
51 ((> i n)
52 (<let> ((Inew (cons i INDENT)))
53 (<syntax-parameterize> ((INDENT (lambda x #'Inew)))
54 (<p-cc> c))))
55 ((< i n)
56 (<or>
57 (<and>
58 (.. (c) ((f-tag " ") c))
59 (.. ((wn+_ n (+ i 1)) c)))
60 (<and>
61 (.. (c) ((f-tag "\t") c))
62 (.. ((wn+_ n (divide (+ i 8) 8)) c)))
63 (<and>
64 (.. (c) ((f-tag "\r") c))
65 (.. ((wn+_ n i) c))))))))
66
67 (define (wn+ n) (wn+_ n 0))
68 (define (wn n) (wn_ n 0))
69
70 (define indent= wn)
71 (define indent+ wn+)
72 (define indent-
73 (<p-lambda> (c)
74 (<let> ((i (cdr INDENT)))
75 (<syntax-parameterize> ((INDENT (lambda x #'i)))
76 (<p-cc> c)))))
77
78
79 (define ih (f-reg! "a-zA-Z_"))
80 (define i.. (f-or ih (f-reg! "0-9")))
81 (define identifier_ (f-seq ih (f* i..)))
82
83 (define keyw (make-hash-table))
84 (for-each
85 (lambda (x) (hash-set! keyw x #t))
86 '(False None True and as assert break class continue def
87 del elif else except finally for from global if import
88 in is lambda nonlocal not or pass raise return try
89 while with yield))
90
91 (define decimal (mk-token (f-seq (f-reg! "[1-9]") (f* (f-reg! "[0-9]")))))
92 (define oct (mk-token
93 (mk-token
94 (f-seq "0" (f-reg "[oO]") (f+ (f-reg! "[0-7]"))))))
95 (define hex (mk-token
96 (f-seq "0" (f-reg "[xX]") (f+ (f-reg! "[0-7a-fA-F]")))))
97 (define bin (mk-token
98 (f-seq "0" (f-reg "[bB]") (f+ (f-reg! "[01]")))))
99
100 (define integer
101 (<p-lambda> (c)
102 (<and!>
103 (<or>
104 (<and>
105 (.. (c) (decimal c))
106 (<p-cc> (string->number c 10)))
107 (<and>
108 (.. (c) (oct c))
109 (<p-cc> (string->number c 8)))
110 (<and>
111 (.. (c) (hex c))
112 (<p-cc> (string->number c 16)))
113 (<and>
114 (.. (c) (bin c))
115 (<p-cc> (string->number c 2)))))))
116
117 (define intpart (f+ (f-reg! "[0-9]")))
118 (define fraction (f-seq (f-tag! ".") intpart))
119 (define exponent (f-seq (f-reg! "[eE]") (f? (f-reg! "[+-]")) intpart))
120 (define pointfloat (f-or! (f-seq (f? intpart) fraction)
121 (f-seq intpart (f-tag! "."))))
122 (define exponentfloat (f-seq (f-or intpart pointfloat) exponent))
123
124 (define floatnumber (mk-token (f-or! exponentfloat pointfloat)))
125 (define float
126 (<p-lambda> (c)
127 (.. (c) (floatnumber c))
128 (<p-cc> (string->number c))))
129
130 (define imagnumber (mk-token (f-seq (f-or floatnumber integer) (f-reg "[jJ]"))))
131 (define imag
132 (<p-lambda> (c)
133 (.. (c) (imagnumber c))
134 (<p-cc> (string->number (string-append "0+" c "i")))))
135
136 (define (mk-id S c cc) cc)
137
138 (define number
139 (p-freeze 'number
140 (f-or! imag float integer)
141 mk-id))
142
143 (define symbol
144 (let ()
145 (define (__*__ i)
146 (match (string->list i)
147 ((#\_ #\_ . l)
148 (match (reverse l)
149 ((#\_ #\_ . l) #t)
150 (_ #f)))
151 (_ #f)))
152
153 (define (__* i)
154 (match (string->list i)
155 ((#\_ #\_ . l)
156 #t)
157 (_ #f)))
158
159 (define (_* i)
160 (match (string->list i)
161 ((#\_ . l)
162 #t)
163 (_ #f)))
164
165 (<p-lambda> (c)
166 (.. (i) (identifier_ c))
167 (cond
168 ((__*__ i)
169 (#:identifier i #:system))
170 ((__* i)
171 (#:identifier i #:private))
172 ((_* i)
173 (#:identifier i #:local))
174 ((eq? i '_)
175 (#:_))
176 ((hash-ref keyw i)
177 (#:keyword i))
178 (else
179 (#:identifier i))))))
180
181 (define identifier
182 (<p-lambda> (c)
183 (.. (i) (identifier_ c))
184 (when (not (eq? (car i) #:keyword))
185 (<p-cc> c))))
186
187 ;;;; +++++++++++++++++++++++++++++++++++++++++++++++ STRING +++++++++++++++
188 (define string-prefix (mk-token (f-reg! "[ruRU]")))
189 (define short-string-char (f-not! (f-reg "[\n\"']")))
190 (define long-string-char (f-not! "\n"))
191 (define string-esc (f-seq (f-tag "\\") (f-reg! ".")))
192 (define short-string-item (f-or short-string-char string-esc))
193 (define long-string-item (f-or long-string-char string-esc))
194
195 (define long-string
196 (mk-token
197 (f-or
198 (f-seq! "'''" (f* long-string-item) "'''")
199 (f-seq! "\"\"\"" (f* long-string-item) "\"\"\""))))
200
201 (define short-string
202 (mk-token
203 (f-or
204 (f-seq! "'" (f* short-string-item) "'")
205 (f-seq! "\"" (f* short-string-item) "\""))))
206
207 (define string-literal
208 (p-freeze 'string-literal
209 (<p-lambda> (c)
210 (xx (pre) (<or>
211 (.. (string-prefix c))
212 (<p-cc> #f)))
213 (.. (str) (f-or! long-string short-string))
214 (<p-cc> (#:string pre str)))
215 mk-id))
216
217 ;; ++++++++++++++++++++++++++++++++++++++++++ BYTE ++++++++++++++++++++++++++
218
219 (define bytes-prefix
220 (mk-token
221 (f-or!
222 (f-seq! (f-tag! "b") (f-or f-true (f-reg! "[rR]")))
223 (f-seq! (f-tag! "B") (f-or f-true (f-reg! "[rR]")))
224 (f-seq! (f-tag! "r") (f-or f-true (f-reg! "[bB]")))
225 (f-seq! (f-tag! "R") (f-or f-true (f-reg! "[bB]"))))))
226
227 (define bytes-esc (f-seq "\\" (f-reg ".")))
228
229 (define short-bytes-char (f-not! (f-reg "[\\\n'\"]")))
230 (define long-bytes-char (f-not! (f-reg "[\\]")))
231
232 (define short-bytes-item
233 (f-or short-bytes-char bytes-esc))
234
235 (define long-bytes-item
236 (f-or long-bytes-char bytes-esc))
237
238 (define short-bytes
239 (mk-token
240 (f-or! (f-seq! "'" (f* short-bytes-item) "'")
241 (f-seq! "\"" (f* short-bytes-item) " \""))))
242
243 (define long-bytes
244 (mk-token
245 (f-or! (f-seq! "'''" (f* long-bytes-item) "'''")
246 (f-seq! "\"\"\"" (f* long-bytes-item) "\"\"\""))))
247
248 (define bytes-literal
249 (p-freeze 'string-literal
250 (<p-lambda> (c)
251 (.. (pre) (bytes-prefix c))
252 (.. (str) ((f-or! long-bytes short-bytes) pre))
253 (<p-cc> (#:bytes pre str)))
254 mk-id))
255
256
257 ; +++++++++++++++++++++++++++++++++++ PARSER SUBSECTION +++++++++++++++++
258 (define stmt #f)
259 (define testlist #f)
260 (define dotted_name #f)
261 (define arglist #f)
262 (define classdef #f)
263 (define funcdef #f)
264 (define test #f)
265 (define small_stmt #f)
266
267
268 (define expr_stmt #f)
269 (define del_stmt #f)
270 (define pass_stmt #f)
271 (define flow_stmt #f)
272 (define import_stmt #f)
273 (define global_stmt #f)
274 (define nonlocal_stmt #f)
275 (define assert_stmt #f)
276 (define testlist_star_expr #f)
277 (define augassign #f)
278 (define yield_expr #f)
279 (define star_expr #f)
280 (define exprlist #f)
281 (define import_name #f)
282 (define import_from #f)
283 (define dotted_as_names #f)
284 (define import_as_names #f)
285 (define if_stmt #f)
286 (define while_stmt #f)
287 (define for_stmt #f)
288 (define try_stmt #f)
289 (define with_stmt #f)
290 (define suite #f)
291 (define except_clause #f)
292 (define with_item #f)
293 (define expr #f)
294 (define or_test #f)
295 (define lambdef #f)
296 (define lambdef_nocond #f)
297 (define and_test #f)
298 (define not_test #f)
299 (define comparison #f)
300 (define comp_op #f)
301 (define xor_expr #f)
302 (define and_expr #f)
303 (define or_expr #f)
304 (define arith_expr #f)
305 (define shift_expr #f)
306 (define term #f)
307 (define factor #f)
308 (define power #f)
309 (define atom #f)
310 (define trailer #f)
311 (define subscriptlist #f)
312 (define testlist_comp #f)
313 (define dictorsetmaker #f)
314 (define comp_for #f)
315 (define subscript #f)
316 (define sliceop #f)
317 (define argument #f)
318 (define comp_if #f)
319 (define yield_arg #f)
320
321
322 (define file-input (f-seq (f* (f-or nl (f-seq indent= stmt))) f-eof))
323
324 (define eval-input (f-seq testlist (f* nl) f-eof))
325
326 (define decorator (f-cons (f-seq ws "@" ws dotted_name ws)
327 (f-seq (ff? (f-seq "(" ws (ff? arglist) ws ")" ws))
328 f-nl)))
329
330 (define decorators (ff+ decorator))
331
332 (define decorated (f-list #:decorated
333 decorators
334 (f-or classdef funcdef)))
335
336 (define FALSE (f-out #f))
337 (define tfpdef
338 (f-cons (f-seq ws identifier ws) (f-or
339 (f-seq ":" ws test ws)
340 FALSE)))
341
342 (define vfpdef identifier)
343 (define mk-py-list
344 (lambda (targlist tfpdef)
345 (let* ((t (f-or (f-seq "=" ws test ws) FALSE))
346 (arg (f-list ws tfpdef ws t ws))
347 (arg.. (ff* (f-seq ws "," arg)))
348 (args (f-cons arg arg..))
349 (arg* (f-seq ws "*" ws (f-list tfpdef ws arg..)))
350 (arg** (f-seq ws "**" tfpdef)))
351 (f-cons
352 (f-out targlist)
353 (f-or
354 (f-cons args
355 (f-or (f-list arg* (f-or arg** FALSE))
356 (f-list FALSE FALSE)))
357 (f-list FALSE arg* (f-or arg** FALSE))
358 (f-list FALSE FALSE arg**))))))
359
360 (define typedargslist (mk-py-list #:types-args-list tfpdef))
361 (define varargslist (mk-py-list #:var-args-list vfpdef))
362
363 (define parameters (f-seq! (f-tag "(") (f-or typedargslist
364 (f-out (list #f #f #f)))
365 (f-tag ")")))
366
367 (set! funcdef
368 (p-freeze 'funcdef
369 (<p-lambda> (c)
370 (.. (c) ((f-tag "def") c))
371 (.. (c) (ws c))
372 (.. (id) (identifier c))
373 (.. (c) (ws id))
374 (.. (pa) (parameters c))
375 (.. (c) (ws pa))
376 (.. (te) ((ff? (f-seq! ws "->" ws test)) c))
377 (.. (su) (f-seq! ":" ws suite))
378 (<p-cc> (list #:funcdef id pa te su)))
379 mk-id))
380
381 (define simple_stmt (f-list #:stmt
382 (f-seq
383 (f-cons small_stmt
384 (ff* (f-seq ";" small_stmt)))
385 ws (f? ";") ws nl)))
386 (set! small_stmt
387 (f-or expr_stmt del_stmt pass_stmt flow_stmt import_stmt global_stmt
388 nonlocal_stmt assert_stmt))
389
390 (set! expr_stmt
391 (f-seq testlist_star_expr
392 (f-or
393 (f-seq augassign
394 (f-or (f-or yield_expr testlist)
395 (f* (f-seq "="
396 (f-or yield_expr
397 testlist_star_expr))))))))
398
399 (set! testlist_star_expr
400 (f-cons (f-or test star_expr)
401 (f-seq
402 (ff* (f-seq "," (f-or test star_expr)))
403 (f? ","))))
404
405
406 (set! augassign
407 (mk-token
408 (f-seq
409 ws
410 (apply f-or!
411 (map f-tag
412 '("+=" "-=" "*=" "/=" "%=" "&=" "|=" "^="
413 "<<=" ">>=" "**=" "//=")))
414 ws)))
415
416 (set! del_stmt (f-cons #:del (f-seq "del" exprlist)))
417
418 (set! pass_stmt (f-seq "pass" #:pass))
419
420 (set! flow_stmt
421 (f-or
422 (f-seq "break" #:break)
423 (f-seq "coninue" #:continue)
424 (f-cons #:return (f-seq "return" (ff? testlist)))
425 yield_expr
426 (f-cons #:raise (f-seq "raise"
427 (f-or (f-cons test
428 (ff?
429 (f-seq "from" test)))
430 (f-cons FALSE FALSE))))))
431
432 (set! import_stmt (f-or import_name import_from))
433
434 (set! import_name (f-seq "import" dotted_as_names))
435
436 (define dottir (mk-token (f-or! (f-tag! "...") (f-tag! "."))))
437 (define dots* (ff* dottir))
438 (define dots+ (ff+ dottir))
439
440 (set! import_from
441 (f-seq "from"
442 (f-cons
443 (f-or (f-cons dots* dotted_name) dots+)
444 (f-seq "import" (f-or "*"
445 (f-seq "(" import_as_names ")")
446 import_as_names)))))
447
448 (define import_as_name
449 (f-cons identifier (ff? (f-seq "as" identifier))))
450
451 (define dotted_as_name
452 (f-cons dotted_name (ff? (f-seq "as" identifier))))
453
454 (set! import_as_names
455 (f-seq
456 (f-cons import_as_name (ff* (f-seq "," import_as_name)))
457 (f? ",")))
458
459 (set! dotted_as_names
460 (f-cons dotted_as_name (ff* (f-seq "," dotted_as_name))))
461
462 (set! dotted_name
463 (f-cons identifier (ff* (f-seq "." identifier))))
464
465 (define comma_name
466 (f-cons identifier (ff* (f-seq "," identifier))))
467
468 (set! global_stmt
469 (f-cons #:global (f-seq "global" comma_name)))
470
471 (set! nonlocal_stmt
472 (f-cons #:nonlocal (f-seq "nonlocal" comma_name)))
473
474 (set! assert_stmt
475 (f-cons #:assert
476 (f-seq "assert" (f-cons test (ff* (f-seq "," test))))))
477
478
479 (define compound_stmt
480 (f-or! if_stmt while_stmt for_stmt try_stmt with_stmt funcdef classdef
481 decorated))
482
483 (define single_input (f-or (f-seq (f-pk 0) nl)
484 (f-seq (f-pk 1) indent= simple_stmt)
485 (f-seq (f-pk 2) indent= compound_stmt nl)))
486
487 (set! stmt (f-or simple_stmt compound_stmt))
488
489 (set! if_stmt
490 (f-cons
491 #:if
492 (f-seq
493 "if"
494 (f-cons test
495 (f-seq ":"
496 (f-cons suite
497 (f-cons
498 (ff+ (f-seq "elif"
499 (f-cons test
500 (f-seq ":" suite))))
501 (ff? (f-seq "else" ":" suite)))))))))
502
503 (set! while_stmt
504 (f-cons
505 #:while
506 (f-seq "while"
507 (f-cons test
508 (f-seq ":"
509 (f-cons suite
510 (ff? (f-seq "else" ":" suite))))))))
511
512 (set! for_stmt
513 (f-cons
514 #:for
515 (f-seq "for"
516 (f-cons exprlist
517 (f-seq "in"
518 (f-cons testlist
519 (f-cons (f-seq ":" suite)
520 (ff? (f-seq "else" ":" suite)))))))))
521
522 (set! try_stmt
523 (f-cons
524 #:try
525 (f-seq ws "try" ":"
526 (f-cons suite
527 (f-or
528 (f-cons
529 (ff+ (f-seq except_clause ":" suite))
530 (f-cons
531 (ff? (f-seq "else" ":" suite))
532 (ff? (f-seq "finally" ":" ws suite))))
533 (f-cons
534 FALSE
535 (f-cons
536 FALSE
537 (f-seq "finally" ":" suite))))))))
538
539 (set! with_stmt
540 (f-cons
541 #:with
542 (f-seq "with"
543 (f-cons
544 (f-cons with_item
545 (ff* (f-seq "," with_item)))
546 (f-seq ":" suite)))))
547
548 (set! with_item
549 (f-cons test (f-seq "as" expr)))
550
551 (set! except_clause
552 (f-seq "except"
553 (ff? (f-cons test (ff? (f-seq "as" identifier))))))
554
555 (set! suite
556 (f-cons #:suite
557 (f-or (f-list simple_stmt)
558 (f-seq nl indent+
559 (f-cons stmt
560 (ff* (f-seq indent= stmt)))
561 indent-))))
562
563 (set! test
564 (f-or
565 (f-cons #:if
566 (f-cons (f-seq "if" or_test)
567 (f-seq "else" test)))
568 lambdef
569 (f-cons (f-out #f)
570 (f-cons or_test FALSE))))
571
572
573 (define test_nocond
574 (f-or or_test lambdef_nocond))
575
576 (set! lambdef
577 (f-cons
578 #:lambdef
579 (f-cons (f-seq "lambda" (ff? varargslist '()))
580 (f-seq ":" test))))
581 (set! lambdef_nocond
582 (f-cons
583 #:lambdef
584 (f-cons (f-seq "lambda" (ff? varargslist '()))
585 (f-seq ":" test_nocond))))
586
587 (set! or_test
588 (f-or! (f-cons #:or (f-cons and_test (ff+ (f-seq "or" and_test))))
589 and_test))
590
591 (set! and_test
592 (f-or! (f-cons #:and (f-cons not_test (ff* (f-seq "and" not_test))))
593 not_test))
594
595 (set! not_test
596 (f-or!
597 (f-cons #:not (f-seq "not" not_test))
598 comparison))
599
600 (set! comparison
601 (f-or!
602 (f-cons #:comp
603 (f-cons expr
604 (ff+ (f-cons comp_op expr))))
605 expr))
606
607 (set! comp_op
608 (f-or!
609 (f-seq (f-seq "not" "in" ) (f-out "notin"))
610 (f-seq (f-seq "is" "not") (f-out "isnot"))
611 (apply f-or!
612 (map (lambda (x) (f-seq x (f-out x)))
613 '("<" ">" "==" ">=" "<=" "<>" "!=" "in" "is")))))
614
615
616 (set! star_expr (f-cons #:starexpr (f-seq "*" expr)))
617 (set! expr
618 (f-or!
619 (f-cons #:bxor (f-cons xor_expr (ff+ (f-seq "|" xor_expr))))
620 xor_expr))
621 (set! xor_expr
622 (f-or!
623 (f-cons #:band (f-cons and_expr (ff+ (f-seq "^" and_expr))))
624 and_expr))
625
626 (set! and_expr
627 (f-or!
628 (f-cons #:band (f-cons shift_expr (ff+ (f-seq "&" shift_expr))))
629 shift_expr))
630
631 (set! shift_expr
632 (f-or!
633 (f-cons #:<< (f-cons arith_expr (ff+ (f-seq "<<" arith_expr))))
634 (f-cons #:>> (f-cons arith_expr (ff+ (f-seq ">>" arith_expr))))
635 arith_expr))
636
637 (set! arith_expr
638 (f-or!
639 (f-cons #:+ (f-cons term (ff+ (f-seq "+" term))))
640 (f-cons #:- (f-cons term (ff+ (f-seq "-" term))))
641 term))
642
643 (set! term
644 (f-or!
645 (f-cons #:* (f-cons factor (ff+ (f-seq "*" factor))))
646 (f-cons #:// (f-cons factor (ff+ (f-seq "//" factor))))
647 (f-cons #:/ (f-cons factor (ff+ (f-seq "/" factor))))
648 (f-cons #:% (f-cons factor (ff+ (f-seq "%" factor))))
649 factor))
650
651
652 (set! factor
653 (f-or!
654 (f-cons #:u+ (f-seq "+" factor))
655 (f-cons #:u- (f-seq "-" factor))
656 (f-cons #:u~ (f-seq "~" factor))
657 power))
658
659 (set! power
660 (f-cons #:power
661 (f-cons atom
662 (f-cons (ff* trailer)
663 (f-or! (f-seq "**" factor)
664 FALSE)))))
665
666 (set! trailer
667 (f-or!
668 (f-seq "(" (ff? arglist) ")")
669 (f-seq "[" subscriptlist "]")
670 (f-seq "." identifier)))
671
672 (set! atom
673 (f-or!
674 (f-cons
675 #:subexpr
676 (f-seq "(" ff? (f-or! yield_expr testlist_comp) ")"))
677 (f-cons
678 #:list
679 (f-seq "[" (ff? testlist_comp) ")"))
680 (f-cons
681 #:dict
682 (f-seq "{" (ff? dictorsetmaker) "}"))
683 identifier
684 number
685 (f-cons #:string (ff+ string))
686 (f-cons #:... "...")
687 (f-cons #:None "None")
688 (f-cons #:True "True")
689 (f-cons #:false "False")))
690
691 (set! testlist_comp
692 (f-cons
693 (f-or! star_expr test)
694 (f-or!
695 comp_for
696 (f-seq (ff* (f-seq "," (f-or! star_expr test)))
697 (f? ",")))))
698
699 (set! subscriptlist
700 (f-cons
701 subscript
702 (f-seq (ff* (f-seq "," subscript)) (f? ","))))
703
704 (set! subscript
705 (f-or!
706 (f-list (ff? test) ":" (ff? test) (ff? sliceop))
707 (f-list test FALSE FALSE)))
708
709 (set! sliceop
710 (f-seq ":" (ff? test)))
711
712 (define exprlist
713 (let ((f (f-or expr star_expr)))
714 (f-cons f (f-seq (ff* (f-seq "," f)) (f? ",")))))
715
716 (set! testlist
717 (f-cons
718 test
719 (f-seq (ff* "," test) (f? ","))))
720
721 (set! dictorsetmaker
722 (let ((f (f-cons test (f-seq ":" test))))
723 (f-or!
724 (f-cons* f (f-seq (ff* (f-seq "," f)) (f? ",")))
725 (f-cons f comp_for)
726 (f-cons test comp_for)
727 (f-cons test (f-seq (ff* (f-seq "," test)) (f? ","))))))
728
729 (set! classdef
730 (f-list
731 #:classdef
732 (f-seq "class" identifier)
733 (ff? (f-seq "(" (ff? arglist '()) ")"))
734 (f-seq ":" suite)))
735
736 (set! arglist
737 (f-or!
738 (f-list (f-seq (ff+ (f-seq argument ",")) (f? ","))
739 FALSE FALSE)
740 (f-list (f-seq (ff* (f-seq argument ",")))
741 FALSE
742 (ff? (f-seq "**" test)))
743 (f-list (f-seq (ff* (f-seq argument ",")))
744 (f-seq "*" (f-cons test (ff* (f-seq "," argument))))
745 (ff? (f-seq "," "**" test)))))
746
747 (set! argument
748 (f-or!
749 (f-list #:= test (f-seq "=" test))
750 (f-list #:comp test (ff? comp_for))))
751
752 (define comp_iter (f-or! comp_for comp_if))
753 (define comp_for (f-list (f-seq "for" exprlist)
754 (f-seq "in" or_test)
755 (ff? comp_iter)))
756 (set! comp_if (f-list (f-seq "if" test_nocond)
757 (ff? comp_iter)))
758
759 (set! yield_expr
760 (f-list #:yield (f-seq "yield" (ff? yield_arg))))
761
762 (set! yield_arg
763 (f-or!
764 (f-list #:from (f-seq "from" test))
765 (f-list #:list testlist)))
766
767
768 (define (p str)
769 (pp (parse str single_input))
770 (if #f #f))