1. Bryan O'Sullivan
  2. attoparsec
Issue #4 new

endOfInput should be treated as a token to avoid non-termination

Rehno Lindeque
created an issue

Hi! I've been using attoparsec for a parser and I believe that there could possibly be a better way of handling end-of-input which currently does not prevent the parser from going into an infinite loop.

== Examples ==

Consider the following parser implementations with the type {{{ myparser :: A.Parser [Char] }}}

  1. Terminates with a DONE result {{{ myparser = many $ (AC.char 'c' <* A.endOfInput) }}}

2.1 Returns a PARTIAL result. Terminates when the continuation is supplied an empty string {{{ myparser = (many $ AC.char 'c') <* A.endOfInput }}}

2.2 Returns a PARTIAL result. Terminates when the continuation is supplied an empty string {{{ myparser = many $ AC.char 'c' }}}

3.1 Parsing ends in a PARTIAL result. Does not terminate when continuation is supplied with an empty string. {{{ myparser = many $ (AC.char 'c' <* skipMany AC.skipSpace) }}}

3.2 Parsing ends in a PARTIAL result. Does not terminate when continuation is supplied with an empty string. {{{ myparser = many $ (AC.char 'c' < skipMany AC.skipSpace < A.endOfInput) }}}

3.3 Parsing ends in a PARTIAL result. Does not terminate when continuation is supplied with an empty string. {{{ parseLangLang = (many $ (AC.char 'c' < skipMany AC.skipSpace)) < A.endOfInput }}}

== Discussion ==

Number 1 and 2.2 work more or less as my intuition tells me they should. However, I expected 2.1 return DONE and 3.1 through 3.3 do not terminate.

I think that attoparsec should treat end-of-input conceptually almost as if it is a input token to be consumed. This would at least theoretically cause 2.1, 3.2 and 3.3 to result in DONE.

2.2 and 3.2 are a bit strange because both try to consume end-of-input multiple times so strictly speaking they are incorrect and should return FAIL, however I do not think this is necessary/desirable.

According to my intuition 3.1 should return PARTIAL and then return either DONE or PARTIAL again when the continuation is supplied with empty.

What do you think?

Kind regards, Rehno

Comments (0)

  1. Log in to comment