diff options
| author | Arun Isaac | 2025-12-18 01:52:03 +0000 |
|---|---|---|
| committer | Arun Isaac | 2025-12-18 01:52:03 +0000 |
| commit | d68d54c13c09ac2df031398075b089bcaf4348be (patch) | |
| tree | bd4615fcbc74332cbd6b20d20e822a9812f41d25 | |
| parent | ebe0aa95726a623a00a82d4873391402f0cd2dca (diff) | |
| download | ravanan-d68d54c13c09ac2df031398075b089bcaf4348be.tar.gz ravanan-d68d54c13c09ac2df031398075b089bcaf4348be.tar.lz ravanan-d68d54c13c09ac2df031398075b089bcaf4348be.zip | |
javascript: Trim whitespace characters.
| -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") |
