Skip to content

Commit

Permalink
parsing 2.*3 as 2 .* 3
Browse files Browse the repository at this point in the history
closes #18
  • Loading branch information
JeffBezanson committed May 14, 2011
1 parent fa0f18d commit a23a0aa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/flisp/iostream.c
Expand Up @@ -160,6 +160,19 @@ value_t fl_ioputc(value_t *args, u_int32_t nargs)
return fixnum(ios_pututf8(s, wc));
}

value_t fl_ioungetc(value_t *args, u_int32_t nargs)
{
argcount("io.ungetc", nargs, 2);
ios_t *s = toiostream(args[0], "io.ungetc");
if (!iscprim(args[1]) || ((cprim_t*)ptr(args[1]))->type != wchartype)
type_error("io.ungetc", "wchar", args[1]);
uint32_t wc = *(uint32_t*)cp_data((cprim_t*)ptr(args[1]));
if (wc >= 0x80) {
lerror(ArgError, "io_ungetc: unicode not yet supported");
}
return fixnum(ios_ungetc((int)wc,s));
}

value_t fl_ioflush(value_t *args, u_int32_t nargs)
{
argcount("io.flush", nargs, 1);
Expand Down Expand Up @@ -419,6 +432,7 @@ static builtinspec_t iostreamfunc_info[] = {
{ "io.seek" , fl_ioseek },
{ "io.pos", fl_iopos },
{ "io.getc" , fl_iogetc },
{ "io.ungetc", fl_ioungetc },
{ "io.putc" , fl_ioputc },
{ "io.peekc" , fl_iopeekc },
{ "io.discardbuffer", fl_iopurge },
Expand Down
21 changes: 14 additions & 7 deletions src/julia-parser.scm
Expand Up @@ -99,7 +99,10 @@
(char<=? c #\9))
(char>=? c #\uA1)
(eqv? c #\_)))
;; characters that can be in an operator
(define (opchar? c) (string.find op-chars c))
;; characters that can follow . in an operator
(define (dot-opchar? c) (and (char? c) (string.find "*^/\\" c)))
(define (operator? c) (memq c operators))

(define (skip-to-eol port)
Expand Down Expand Up @@ -159,9 +162,13 @@
(and (>= c #\A) (<= c #\F)))))))
(allow #\.)))
(read-digs)
(allow #\.)
(read-digs)
(disallow #\.)
(if (eqv? (peek-char port) #\.)
(begin (read-char port)
(if (dot-opchar? (peek-char port))
(io.ungetc port #\.)
(begin (write-char #\. str)
(read-digs)
(disallow #\.)))))
(if (or (allow #\e) (allow #\E))
(begin (or (allow #\+) (allow #\-))
(read-digs)
Expand All @@ -183,12 +190,10 @@
(let ((c (peek-char port)))
(cond ((or (eof-object? c) (newline? c)) (read-char port))

((char-numeric? c) (read-number port))

((identifier-char? c) (accum-julia-symbol c port))

((special-char? c) (read-char port))

((char-numeric? c) (read-number port))

((eqv? c #\#) (skip-to-eol port) (next-token port s))

; . is difficult to handle; it could start a number or operator
Expand All @@ -206,6 +211,8 @@

((opchar? c) (read-operator port c))

((identifier-char? c) (accum-julia-symbol c port))

#;((eqv? c #\")
(with-exception-catcher
(lambda (e)
Expand Down
1 change: 1 addition & 0 deletions test/tests.j
Expand Up @@ -76,6 +76,7 @@ nttest1{n}(x::NTuple{n,Int32}) = n
@assert 2+3 == 5
@assert 2.+3. == 5.
@assert 2*3 == 6
@assert 2.*3 == 6
@assert 2. * 3. == 6.
@assert min(1.0,1) == 1

Expand Down

0 comments on commit a23a0aa

Please sign in to comment.