diff --git a/src/flisp/iostream.c b/src/flisp/iostream.c index 2419f8c7985ae..489672d605cef 100644 --- a/src/flisp/iostream.c +++ b/src/flisp/iostream.c @@ -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); @@ -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 }, diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 73ec08f822a77..b0ba0f52d3f5e 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -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) @@ -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) @@ -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 @@ -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) diff --git a/test/tests.j b/test/tests.j index 51c139659c6ab..18c8a968e758c 100644 --- a/test/tests.j +++ b/test/tests.j @@ -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