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

line-comment parser consumes newlines even with :trim-newline false #16

Open
Trildar opened this issue Dec 21, 2017 · 1 comment
Open

Comments

@Trildar
Copy link

Trildar commented Dec 21, 2017

This causes inconsistent behaviour between parsing lines with trailing comments and lines without comments.

@blancas
Copy link
Owner

blancas commented May 5, 2018

@Trildar Was unable to reproduce; I think line comment should consume one newline. Will be interested in seeing a failing sample. Added these test cases though:

(deftest test-0880
  (let [rec (lex/make-parsers (assoc lex/haskell-style :trim-newline false))]
    (lex/with-parsers rec
      (let [in "foo bar -- this is a line comment\n\n\nbaz"
	    s1 (parse (many1 lex/identifier) in)]
        (fact "line comment consumes until the end of the line"
	      (:input s1)  =>  (seq "\n\nbaz")
	      (:value s1)  =>  ["foo" "bar"]
	      (:ok    s1)  =>  true
	      (:empty s1)  =>  false)))))


(deftest test-0885
  (let [rec (lex/make-parsers (assoc lex/haskell-style :trim-newline false))]
    (lex/with-parsers rec
      (let [in "foo bar -- this is a line comment\n\n\nbaz"
	    s1 (parse (<*> (many1 lex/identifier)
                           (skip-many white-space)
                           (many1 lex/identifier)) in)]
        (fact "explicit whitespace removal with :trim-newline false"
	      (:input s1)  =>  empty?
	      (:value s1)  =>  [["foo" "bar"] nil ["baz"]]
	      (:ok    s1)  =>  true
	      (:empty s1)  =>  false)))))


(deftest test-0890
  (let [rec (lex/make-parsers lex/haskell-style)]
    (lex/with-parsers rec
      (let [in "foo bar -- this is a line comment\n\n\nbaz\nfoobar"
	    s1 (parse (many1 lex/identifier) in)]
        (fact "line comment is treated as whitespace"
	      (:input s1)  =>  empty?
	      (:value s1)  =>  ["foo" "bar" "baz" "foobar"]
	      (:ok    s1)  =>  true
	      (:empty s1)  =>  false)))))

blancas added a commit that referenced this issue May 5, 2018
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

2 participants