haskell - Make Text.Parsec.Indent parsing fail if unindent does not match any outer indentation level -


I am trying to parse a string in Haskell which represents a tree. Each node is on one line, where indentation determines nesting (eg Python or Haskell's syntax).

The result of "tree" "tree" "tree" Tree "F" []]]

And with the help of that, I could parse such an example.

The problem is that my current implementation successfully parses the string

  as ABCD  

< The tree "d" [tree "one" [tree "B" [tree "C"]], tree "D" []]

node D D is unrelated to C , but it does not match indentation level of A Or b .

My implementation is as follows (Simplification: tree labels are ineligible and are alphanumeric characters, not all types of Unicode newline supported).

  Import the Eligible Control. Apply as an importable control. M Monad as importable text. Import imported text as P import. Persec.Indent As I Pars :: String - & gt; Either p. Parasier [tree] pars = IrunIndent "". P. Runeparcer forest () "forest" = p. Mama tree A and LT; * PF tree = spacing a. * & Gt; I.withBlock Tree Node Tree Vacancy = PMM P.Newline A. * & Gt; Indented indentation = PMAAA $ P.Ker "node = label A and LT; * Spacing label = p. MAI1p. LFANM A & LT; * Lineand Lineind = M. Owed P. Anviline p. & Lt; | & Gt; P.E.f  

How can this parser be changed to accept Assentments, which matches some external indentation level? thank you in advanced.

instead of the definition of one >

  forest = I.block tree A & lt; * P.eof  

seems to do the trick. I.block here ensures that the roots of the source string are indented at the same level.

Example

  ABCD  

now with

  (line 4, column 7) failed Lives: The problem with unexpected 'D' or end of input does not match indent or indentation. The problem with  

P.many tree is that one trees can be indented arbitrarily, as soon as any of the trees is any indentation level (eg D ) Does not match, parser one Top-tier number two increases the tree (root) forest instead of fail.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -