diff options
| -rw-r--r-- | ravanan/javascript.scm | 16 | ||||
| -rw-r--r-- | tests/javascript.scm | 5 |
2 files changed, 16 insertions, 5 deletions
diff --git a/ravanan/javascript.scm b/ravanan/javascript.scm index 4a7199b..474c01c 100644 --- a/ravanan/javascript.scm +++ b/ravanan/javascript.scm @@ -95,15 +95,21 @@ (define-peg-pattern javascript-function-body all (and (ignore "$") javascript-function-body-subexpression)) +(define-peg-pattern whitespace body + (or "\t" "\n" "\r" " ")) + (define-peg-pattern string-literal body - (* (and (not-followed-by "$(") + (+ (and (not-followed-by (or "$(" whitespace)) peg-any))) (define-peg-pattern javascript all - (* (or parameter-reference - javascript-expression - javascript-function-body - string-literal))) + (and (ignore (* whitespace)) + (* (and (* whitespace) + (or parameter-reference + javascript-expression + javascript-function-body + string-literal))) + (ignore (* whitespace)))) (define (javascript-expression? str) "Return true value if @var{str} contains inline javascript or parameter diff --git a/tests/javascript.scm b/tests/javascript.scm index b0c6de0..eb70373 100644 --- a/tests/javascript.scm +++ b/tests/javascript.scm @@ -209,4 +209,9 @@ '(("inputs" . ())) '())) +(test-equal "trim whitespace characters in javascript expressions" + 2 + (evaluate-javascript-expression " $(1 + 1)\n" + '())) + (test-end "javascript") |
