Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse error on new lines when used from CLJS (browser) #12

Open
tdreyno opened this issue Oct 1, 2018 · 2 comments
Open

Parse error on new lines when used from CLJS (browser) #12

tdreyno opened this issue Oct 1, 2018 · 2 comments

Comments

@tdreyno
Copy link

tdreyno commented Oct 1, 2018

I'm loading a template file over HTTP, then attempting to render the template.

Using the following test string:

<div>
  <h1>Hello World</h1>
  
  <h2>Okay</h2>
</div>

Throws the following exception:

Error: Parse error: <div> (1:6)
    at new cljs$core$ExceptionInfo (http://localhost:8080/client/cljs-runtime/cljs.core.js:36934:10)
    at Function.cljs.core.ex_info.cljs$core$IFn$_invoke$arity$3 (http://localhost:8080/client/cljs-runtime/cljs.core.js:36995:9)
    at Function.cljs.core.ex_info.cljs$core$IFn$_invoke$arity$2 (http://localhost:8080/client/cljs-runtime/cljs.core.js:36991:26)
    at Object.wet$impl$parser$parse_and_transform [as parse_and_transform] (http://localhost:8080/client/cljs-runtime/wet.impl.parser.js:423:25)
    at Function.wet.core.parse.cljs$core$IFn$_invoke$arity$2 (http://localhost:8080/client/cljs-runtime/wet.core.js:35:32)
    at Function.wet.core.parse.cljs$core$IFn$_invoke$arity$1 (http://localhost:8080/client/cljs-runtime/wet.core.js:31:23)

The Clojure version of that exception looks like:

(defn parse-and-transform
  [template]
  (let [parsed-template (parse template)]
    (cond
      (insta/failure? parsed-template)
      (let [{:keys [text line column]} parsed-template
            error-message (str "Parse error: " text " (" line ":" column ")")
            error-context {:type :wet/parse-error
                           :wet.error/line line
                           :wet.error/column column
                           :wet.error/text text}]
        (throw (ex-info error-message error-context)))
      :else (transform parsed-template))))

Where the exception is at the throw.

I can "fix" this by removing the new line characters in either the source file or code. I verified I'm using the unix \n character for newlines, not sure what would happen on Windows.

Thanks, let me know if I can provide more information.

@tdreyno
Copy link
Author

tdreyno commented Oct 5, 2018

Confirmed, via the REPL, that this works fine when using the library from CLJ, but CLJS fails.

@tdreyno
Copy link
Author

tdreyno commented Oct 5, 2018

Adding s, the newline/empty space rule, to the template rule as a valid option, seems to fix things. Not sure if there are side-effects to that change, but validated the rules on the Liquid docs with this change and they now parse.

template ::= (s / b / raw-block / object-expr-block / tag-expression)*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant