English 中文(简体)
尾行的解析错误
原标题:Parsec trouble with end of line

我有一个分析分析器,我主要以实用风格写作。在一种情况下(我使用 sepBy 的唯一时间),我对我的 eleol 解析器有问题。 首先,有几个定义:

eol =   try (string "

")
    <|> try (string "
")
    <|> string "
"
    <|> string "
"
    <?> "eol"

betaLine = string "BETA " *> (StrandPair <$> p_int <*> p_int <*> p_int <*> (p_int *> p_direction) <*> p_exposure) <* eol

注: beataLine 工作完美(对于简洁性,我漏掉了 >p_int 的定义,以及:

*HmmPlus> parse betaLine "beta" "BETA 6 11 5 24 -1 oiiio
"
Right (StrandPair {firstStart = 6, secondStart = 11, pairLength = 5, parallel =   Antiparallel, exposure = [Exposed,Buried,Buried,Buried,Exposed]})

问题在于此其它解析器, hmmMatchEmissions :

 hmmMatchEmissions     = spaces *> (V.fromList <$> sepBy p_logProb spaces) <* eol <?> "matchEmissions"

*HmmPlus> parse hmmMatchEmissions "me" "      2.61196  4.43481  2.86148  2.75135  3.26990  2.87580  3.69681
"
Left "me" (line 2, column 1):
unexpected end of input

Now, if I remove the <* eol from the parser definition, and remove the from the line, it does work:

*HmmPlus> parse hmmMatchEmissions "me" "      2.61196  4.43481  2.86148  2.75135  3.26990  2.87580  3.69681"
Right (fromList [NonZero 2.61196,NonZero 4.43481,NonZero 2.86148,NonZero 2.75135,NonZero 3.2699,NonZero 2.8758,NonZero 3.69681])

那么,为什么 eol beetaLine 中起作用,但不能在 hmmmm MatchEmissions 中发挥作用?

我要指出,这是我唯一使用 sepBy 的地方;这是否是一个线索?

最新消息:我做了以下工作,但现在却以不同的方式失败:/

reqSpaces = many1 (oneOf " 	")

optSpaces = many (oneOf " 	")

hmmMatchEmissions = optSpaces *> (V.fromList <$> sepBy1 p_logProb reqSpaces) <* eol <?> "matchEmissions"

失败者如下:

*HmmPlus> parse hmmMatchEmissions "me" "  0.123  0.124
"
Left "me" (line 1, column 10):
unexpected "0"
expecting eol

我将注意到,第10栏中未预料到的 0 0.124 符号的第一个字符。

最佳回答

问题似乎在于您的 p_logProb 分析器会消耗白空格。 因此, 分析过程中会发生这种情况 :

  0.123  0.124

[]               optSpaces
  [-----]        p_logProb
         {       trying reqSpaces
         {       trying eol
                 failure: expecting eol

p_logProb 分析器只应消耗它所分析的东西,即实际数字。 这将导致想要的解析 :

  0.123  0.124

[]               optSpaces
  [---]          p_logProb
       []        reqSpaces
         [---]   p_logProb
              {  trying reqSpaces
              #  eol
问题回答

暂无回答




相关问题
Euler Problem in Haskell -- Can Someone Spot My Error

I m trying my hand at Euler Problem 4 in Haskell. It asks for that largest palindrome formed by multiplying two three-digit numbers. The problem was simple enough, and I thought my Haskell-fu was up ...

How does foldr work?

Can anybody explain how does foldr work? Take these examples: Prelude> foldr (-) 54 [10, 11] 53 Prelude> foldr (x y -> (x+y)/2) 54 [12, 4, 10, 6] 12.0 I am confused about these executions....

Efficient queue in Haskell

How can I efficiently implement a list data structure where I can have 2 views to the head and end of the list, that always point to a head a tail of a list without expensive calls to reverse. i.e: ...

Problem detecting cyclic numbers in Haskell

I am doing problem 61 at project Euler and came up with the following code (to test the case they give): p3 n = n*(n+1) `div` 2 p4 n = n*n p5 n = n*(3*n -1) `div` 2 p6 n = n*(2*n -1) p7 n = n*(5*n -3)...

Ways to get the middle of a list in Haskell?

I ve just started learning about Functional Programming, using Haskel. I m slowly getting through Erik Meijer s lectures on Channel 9 (I ve watched the first 4 so far) and in the 4th video Erik ...

haskell grouping problem

group :: Ord a => [(a, [b])] -> [(a, [b])] I want to look up all pairs that have the same fst, and merge them, by appending all the list of bs together where they have the same a and discarding ...

Closest equivalent to subprocess.communicate in Haskell

I want to do a popen() / python s subprocess.communicate from Haskell - start a program, give it stdin, and get its stdout/stderr. What s the most direct / Haskellish way to do this?

热门标签