代码之家  ›  专栏  ›  技术社区  ›  levant pied

阿托帕塞克切片

  •  0
  • levant pied  · 技术社区  · 6 年前

    我在看 this example

    simpleComment   = string "<!--" *> manyTill anyChar (string "-->")
    

    这将建立一个 [Char] 而不是 ByteString 切片。评论太多太不好了,对吧?

    另一种选择, takeWhile

    takeWhile :: (Word8 -> Bool) -> Parser ByteString
    

    无法接受解析器(即不能匹配 ByteString公司 Word8 ).

    ByteString公司 [字符]

    1 回复  |  直到 6 年前
        1
  •  2
  •   Daniel Wagner    6 年前

    你可以用 scan :

    scan :: s -> (s -> Word8 -> Maybe s) -> Parser ByteString
    

    它看起来像这样:

    transitions :: [((Int, Char), Int)]
    transitions = [((0, '-'), 1), ((1, '-'), 2), ((2, '-'), 2), ((2, '>'), 3)]
    
    dfa :: Int -> Word8 -> Maybe Int
    dfa 3 w = Nothing
    dfa s w = lookup (s, toEnum (fromEnum w)) transitions <|> Just 0
    

    scan 0 dfa 将字节数增加到并包括final "-->" “-->” 到目前为止我们已经看到了。一旦我们看到他们,我们就通知他们 扫描 *Enum 调用查找表,甚至考虑直接编写函数。

    推荐文章