What are the reasons for using parser combinators?

I am considering the following approach to using parser combinators in Haskell. The author gives the following example of Parser combinators:

windSpeed :: String -> Maybe Int
windSpeed windInfo =
    parseMaybe windSpeedParser windInfo

windSpeedParser :: ReadP Int
windSpeedParser = do
    direction <- numbers 3
    speed <- numbers 2 <|> numbers 3
    unit <- string "KT" <|> string "MPS"
    return speed

The author gives the following reasons for this approach:

  • easy to read (I agree with that)
  • similar specification format, i.e. the analyzer itself is basically a description of what it analyzes (I agree with that)

, . Haskell, , . - DSLs .

: ?

+4
1

:

  • Parser , . , , , .
  • , , . , .
  • - .
+2

Source: https://habr.com/ru/post/1690322/


All Articles