~ubuntu-branches/ubuntu/wily/julia/wily

« back to all changes in this revision

Viewing changes to src/julia-parser.scm

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot
  • Date: 2013-02-06 17:54:29 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130206175429-13br5kqpkfjqdmre
Tags: 0.0.0+20130206.git32ff5759-1
* New upstream snapshot.
* debian/copyright: reflect upstream changes
* debian/rules: update get-orig-source to reflect upstream changes
   + Don't ship nginx
   + Adapt for new configure-random target in deps/Makefile
* Enable build of Tk wrapper.
   + debian/control: add build dependency on tk-dev
   + debian/rules: add tk rule to build-arch
* debian/julia.install: install VERSION and COMMIT files
* no-webrepl.patch: new patch
* Refresh other patches
* Add source override for config.status file under deps/random/

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
; operators that are special forms, not function names
83
83
(define syntactic-operators
84
84
  '(= := += -= *= /= //= .//= .*= ./= |\\=| |.\\=| ^= .^= %= |\|=| &= $= =>
85
 
      <<= >>= >>>= -> --> |\|\|| && |::| |.|))
 
85
      <<= >>= >>>= -> --> |\|\|| && |::| |.| ...))
86
86
(define syntactic-unary-operators '($ &))
87
87
 
88
88
(define reserved-words '(begin while if for try return break continue
413
413
 
414
414
(define (parse-cond s)
415
415
  (let ((ex (parse-or s)))
416
 
    (if (not (eq? (peek-token s) '?))
417
 
        ex
418
 
        (begin (take-token s)
419
 
               (let ((then (without-range-colon (parse-eq* s))))
420
 
                 (if (not (eq? (take-token s) ':))
421
 
                     (error "colon expected in ? expression")
422
 
                     (list 'if ex then (parse-cond s))))))))
 
416
    (cond ((eq? (peek-token s) '?)
 
417
           (begin (take-token s)
 
418
                  (let ((then (without-range-colon (parse-eq* s))))
 
419
                    (if (not (eq? (take-token s) ':))
 
420
                        (error "colon expected in ? expression")
 
421
                        (list 'if ex then (parse-cond s))))))
 
422
          #;((string? ex)
 
423
           (let loop ((args (list ex)))
 
424
             (let ((next (peek-token s)))
 
425
               (if (or (eof-object? next) (closing-token? next)
 
426
                       (newline? next))
 
427
                   `(call (top string) ,@(reverse args))
 
428
                   (loop (cons (parse-or s) args))))))
 
429
          (else ex))))
423
430
 
424
431
(define (invalid-initial-token? tok)
425
432
  (or (eof-object? tok)
581
588
 
582
589
(define (parse-shift s) (parse-LtoR s parse-term (prec-ops 8)))
583
590
 
584
 
; given an expression and the next token, is there a juxtaposition
585
 
; operator between them?
586
 
(define (juxtapose? expr t)
587
 
  (and (not (operator? t))
588
 
       (not (operator? expr))
589
 
       (not (memq t reserved-words))
590
 
       (not (closing-token? t))
591
 
       (not (newline? t))
592
 
       (or (number? expr)
593
 
           (not (memv t '(#\( #\[ #\{))))))
594
 
 
595
591
(define (parse-term s)
596
592
  (let ((ops (prec-ops 9)))
597
593
    (let loop ((ex       (parse-rational s))
636
632
(define (maybe-negate op num)
637
633
  (if (eq? op '-) (- num) num))
638
634
 
 
635
; given an expression and the next token, is there a juxtaposition
 
636
; operator between them?
 
637
(define (juxtapose? expr t)
 
638
  (and (not (operator? t))
 
639
       (not (operator? expr))
 
640
       (not (memq t reserved-words))
 
641
       (not (closing-token? t))
 
642
       (not (newline? t))
 
643
       (or (number? expr)
 
644
           (not (memv t '(#\( #\[ #\{))))))
 
645
 
639
646
(define (parse-juxtapose ex s)
640
647
  (let ((next (peek-token s)))
641
648
    ;; numeric literal juxtaposition is a unary operator
642
 
    (if (and (juxtapose? ex next)
643
 
             (not (ts:space? s)))
644
 
        (begin
645
 
          #;(if (and (number? ex) (= ex 0))
646
 
              (error "juxtaposition with literal 0"))
647
 
          `(call * ,ex ,(parse-unary s)))
648
 
        ex)))
 
649
    (cond ((and (juxtapose? ex next)
 
650
                (not (ts:space? s)))
 
651
           (begin
 
652
             #;(if (and (number? ex) (= ex 0))
 
653
                 (error "juxtaposition with literal 0"))
 
654
             `(call * ,ex ,(parse-unary s))))
 
655
          (else ex))))
649
656
 
650
657
(define (parse-unary s)
651
658
  (let ((t (require-token s)))
714
721
        ((->)   (take-token s)
715
722
         ;; -> is unusual: it binds tightly on the left and
716
723
         ;; loosely on the right.
717
 
         (list '-> ex (parse-eq* s)))
 
724
         (let ((lno (line-number-filename-node s)))
 
725
           `(-> ,ex (block ,lno ,(parse-eq* s)))))
718
726
        (else
719
727
         ex)))))
720
728
 
989
997
                 body))))
990
998
    ((export)
991
999
     (let ((es (map macrocall-to-atsym
992
 
                    (parse-comma-separated-assignments s))))
 
1000
                    (parse-comma-separated s parse-atom))))
993
1001
       (if (not (every symbol? es))
994
1002
           (error "invalid export statement"))
995
1003
       `(export ,@es)))
996
 
    ((import using)
 
1004
    ((import using importall)
997
1005
     (let ((imports (parse-comma-separated s (lambda (s)
998
1006
                                               (parse-import s word)))))
999
1007
       (if (length= imports 1)
1090
1098
             ((#\newline)   (reverse! (cons e exprs)))
1091
1099
             (else          (loop (cons e exprs)))))))))
1092
1100
 
 
1101
(define (separate-keywords argl)
 
1102
  (receive
 
1103
   (kws args) (separate (lambda (x)
 
1104
                          (and (pair? x) (eq? (car x) '=)))
 
1105
                        argl)
 
1106
   (if (null? kws)
 
1107
       args
 
1108
       `(,@args (keywords ,@kws)))))
 
1109
 
1093
1110
; handle function call argument list, or any comma-delimited list.
1094
1111
; . an extra comma at the end is allowed
1095
1112
; . expressions after a ; are enclosed in (parameters ...)
1103
1120
    (let ((t (require-token s)))
1104
1121
      (if (equal? t closer)
1105
1122
          (begin (take-token s)
1106
 
                 (reverse lst))
 
1123
                 (let ((lst (reverse lst)))
 
1124
                   (if (eqv? closer #\) )
 
1125
                       (separate-keywords lst)
 
1126
                       lst)))
1107
1127
          (if (equal? t #\;)
1108
1128
              (begin (take-token s)
1109
1129
                     (if (equal? (peek-token s) closer)
1114
1134
                                        lst))))
1115
1135
              (let* ((nxt (parse-eq* s))
1116
1136
                     (c (require-token s)))
1117
 
                (if (assignment? nxt)
1118
 
                    (error "assignment in argument list not allowed"))
1119
1137
                (cond ((eqv? c #\,)
1120
1138
                       (begin (take-token s) (loop (cons nxt lst))))
1121
1139
                      ((eqv? c #\;)          (loop (cons nxt lst)))