Merge remote-tracking branch 'origin/stable-2.0'
[bpt/guile.git] / module / language / ecmascript / parse.scm
index e9d6673..be41e4b 100644 (file)
   #:use-module (language ecmascript tokenize)
   #:export (read-ecmascript read-ecmascript/1 make-parser))
 
-(define (syntax-error message . args)
-  (apply throw 'SyntaxError message args))
+(define* (syntax-error message #:optional token)
+  (if (lexical-token? token)
+      (throw 'syntax-error #f message
+             (and=> (lexical-token-source token)
+                    source-location->source-properties)
+             (or (lexical-token-value token)
+                 (lexical-token-category token))
+             #f)
+      (throw 'syntax-error #f message #f token #f)))
 
 (define (read-ecmascript port)
   (let ((parse (make-parser)))
@@ -78,7 +85,8 @@
                    (SourceElements SourceElement) : (if (and (pair? $1) (eq? (car $1) 'begin))
                                                          `(begin ,@(cdr $1) ,$2)
                                                          `(begin ,$1 ,$2)))
-   (FunctionBody (SourceElements) : $1)
+   (FunctionBody (SourceElements) : $1
+                 () : '(begin))
 
    (Statement (Block) : $1
               (VariableStatement) : $1
                       (StringLiteral) : `(string ,$1)
                       (RegexpLiteral) : `(regexp ,$1)
                       (NumericLiteral) : `(number ,$1)
+                      (dot NumericLiteral) : `(number ,(string->number (string-append "." (number->string $2))))
                       (ArrayLiteral) : $1
                       (ObjectLiteral) : $1
                       (lparen Expression rparen) : $2)