-
Notifications
You must be signed in to change notification settings - Fork 8
/
Parser.hs
35 lines (29 loc) · 1.03 KB
/
Parser.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
-- | Parse puppet source code from text.
module Puppet.Parser
( -- * Runner
runPuppetParser,
-- * Parsers
puppetParser,
prettyParseError,
-- * Pretty Print
module Puppet.Parser.PrettyPrinter,
module Puppet.Parser.Types,
module Puppet.Parser.Lens,
)
where
import Puppet.Parser.Internal
import Puppet.Parser.Lens
import Puppet.Parser.PrettyPrinter
import Puppet.Parser.Types
import Text.Megaparsec
import XPrelude
-- | Build a 'PrettyError' from a 'ParseError' given the text source.
-- The source is used to display the line on which the error occurs.
prettyParseError :: ParseErrorBundle Text Void -> PrettyError
prettyParseError err = PrettyError $ "cannot parse" <+> pretty (errorBundlePretty err)
-- | Run a puppet parser against some 'Text' input.
runPuppetParser :: String -> Text -> Either (ParseErrorBundle Text Void) (Vector Statement)
runPuppetParser = parse puppetParser
-- | Parse a collection of puppet 'Statement'.
puppetParser :: Parser (Vector Statement)
puppetParser = optional sc >> statementList