| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
KDL.Parser.Internal
Contents
- (1) Compatibility
- (3.1) Document
- (3.2) Node
- (3.3) Line Continuation
- (3.4) Property
- (3.5) Argument
- (3.6) Children Block
- (3.7) Value
- (3.8) Type Annotation
- (3.9) String
- (3.10) Identifier String
- (3.11) Quoted String
- (3.12) Multi-line String
- (3.13) Raw String
- (3.14) Number
- (3.15) Boolean
- (3.17) Whitespace
- (3.18) Newline
- (3.19) Disallowed Literal Code Points
- Unicode
Description
Implement the v2 parser specified at: https://kdl.dev/spec/#name-full-grammar
Synopsis
- type Parser = ParsecT Void Text (Reader ParseConfig)
- data ParseConfig = ParseConfig {
- filepath :: FilePath
- includeSpans :: Bool
- runParser :: ParseConfig -> Parser a -> Text -> Either (ParseErrorBundle Text Void) a
- p_bom :: Parser ()
- p_version :: Parser ()
- p_document :: Parser Document
- p_nodes :: Parser NodeList
- p_line_space :: Parser ()
- p_node_space :: Parser ()
- p_node :: Parser (SlashdashResult, Parser (Node, Bool))
- p_base_node :: Parser (SlashdashResult, Parser Node)
- p_node_prop_or_arg :: Parser Entry
- p_node_terminator :: Parser Text
- p_escline :: Parser ()
- p_prop :: Parser Entry
- p_value'Entry :: Parser Entry
- p_node_children :: Parser NodeList
- p_value :: Parser (Value, Text)
- p_keyword :: Parser ValueData
- p_type :: Parser Ann
- p_string'Identifier :: Parser Identifier
- p_string :: Parser Text
- p_identifier_string :: Parser Text
- isValidUnquotedString :: Text -> Bool
- p_unambiguous_ident :: Parser Text
- p_signed_ident :: Parser Text
- disallowed_keyword_identifiers :: Set Text
- p_dotted_ident :: Parser Text
- p_identifier_char :: Parser Char
- p_quoted_string :: Parser Text
- p_single_line_string_body :: Parser Text
- p_string_character :: Maybe (Parser invalid) -> Parser Text
- p_hex_unicode :: Parser Int
- p_ws_escape :: Parser ()
- p_multi_line_string_body :: Parser end -> Parser MultilineChars
- p_raw_string :: Parser Text
- p_raw_string_quotes :: Parser end -> Parser Text
- p_single_line_raw_string_body :: Parser end -> Parser ()
- p_single_line_raw_string_char :: Parser Char
- p_multi_line_raw_string_body :: Parser end -> Parser MultilineChars
- p_number :: Parser ValueData
- p_hex :: Parser Scientific
- p_hex_digit :: Parser Int
- p_octal :: Parser Scientific
- p_binary :: Parser Scientific
- p_decimal :: Parser Scientific
- p_integer :: Parser (Integer, Int)
- p_digits :: Integer -> (Char -> Bool) -> Parser (Integer, Int)
- p_exponent :: Parser Int
- p_sign :: Parser Char
- p_keyword_number :: Parser ValueData
- p_boolean :: Parser Bool
- p_ws :: Parser Text
- p_unicode_space :: Parser Char
- p_single_line_comment :: Parser Text
- p_multi_line_comment :: Parser Text
- p_slashdash :: Parser SlashdashResult
- p_newline :: Parser Text
- is_disallowed_literal_code_points :: Char -> Bool
- p_unicode :: Parser Char
- is_unicode_scalar_value :: Int -> Bool
Documentation
data ParseConfig Source #
Constructors
| ParseConfig | |
Fields
| |
Instances
| Default ParseConfig Source # | |
Defined in KDL.Parser.Internal Methods def :: ParseConfig # | |
runParser :: ParseConfig -> Parser a -> Text -> Either (ParseErrorBundle Text Void) a Source #
(1) Compatibility
p_version :: Parser () Source #
ref: (1)
version :=
/- unicode-space* 'kdl-version' unicode-space+ ('1' | '2')
unicode-space* newline
(3.1) Document
p_document :: Parser Document Source #
ref: (3.1) document := bom? version? nodes
p_line_space :: Parser () Source #
ref: (3.1) + (3.17) // Whitespace where newlines are allowed. line-space := node-space | newline | single-line-comment
p_node_space :: Parser () Source #
ref: (3.1) + (3.17) // Whitespace within nodes, // where newline-ish things must be esclined. node-space := ws* escline ws* | ws+
(3.2) Node
p_node :: Parser (SlashdashResult, Parser (Node, Bool)) Source #
ref: (3.2) node := base-node node-terminator final-node := base-node node-terminator?
p_base_node :: Parser (SlashdashResult, Parser Node) Source #
ref: (3.2) base-node := slashdash? type? node-space* string (node-space* (node-space | slashdash) node-prop-or-arg)* // slashdashed node-children must always be after props and args. (node-space* slashdash node-children)* (node-space* node-children)? (node-space* slashdash node-children)* node-space*
p_node_prop_or_arg :: Parser Entry Source #
ref: (3.2) node-prop-or-arg := prop | value
p_node_terminator :: Parser Text Source #
ref: (3.2) node-terminator := single-line-comment | newline | ';' | eof
(3.3) Line Continuation
(3.4) Property
(3.5) Argument
p_value'Entry :: Parser Entry Source #
ref: (3.5)
(3.6) Children Block
p_node_children :: Parser NodeList Source #
ref: (3.6) node-children := '{' nodes final-node? '}'
(3.7) Value
p_value :: Parser (Value, Text) Source #
ref: (3.7) value := type? node-space* (string | number | keyword)
(3.8) Type Annotation
(3.9) String
p_string'Identifier :: Parser Identifier Source #
ref: (3.9)
p_string :: Parser Text Source #
ref: (3.9) string := identifier-string | quoted-string | raw-string ¶
(3.10) Identifier String
p_identifier_string :: Parser Text Source #
ref: (3.10) identifier-string := unambiguous-ident | signed-ident | dotted-ident
isValidUnquotedString :: Text -> Bool Source #
p_unambiguous_ident :: Parser Text Source #
ref: (3.10)
unambiguous-ident :=
((identifier-char - digit - sign - .) identifier-char*)
- disallowed-keyword-identifiers
p_signed_ident :: Parser Text Source #
ref: (3.10)
signed-ident :=
sign ((identifier-char - digit - .) identifier-char*)?
disallowed_keyword_identifiers :: Set Text Source #
ref: (3.10)
disallowed-keyword-identifiers :=
true | false | null | inf | '-inf' | nan
p_dotted_ident :: Parser Text Source #
ref: (3.10)
dotted-ident :=
sign? . ((identifier-char - digit) identifier-char*)?
p_identifier_char :: Parser Char Source #
ref: (3.10.2) identifier-char := unicode - unicode-space - newline - [\/(){};[]"#=] - disallowed-literal-code-points
(3.11) Quoted String
p_quoted_string :: Parser Text Source #
ref: (3.11) + (3.12) quoted-string := '"' single-line-string-body '"' | '"""' newline (multi-line-string-body newline)? (unicode-space | ws-escape)* '"""'
p_single_line_string_body :: Parser Text Source #
ref: (3.11) single-line-string-body := (string-character - newline)*
p_string_character :: Maybe (Parser invalid) -> Parser Text Source #
ref: (3.11)
string-character :=
\\ (["\bfnrts] |
'u{' hex-unicode '}') |
ws-escape |
[^\"] - disallowed-literal-code-points
p_hex_unicode :: Parser Int Source #
ref: (3.11.1) hex-unicode := hex-digit{1, 6} - surrogate - above-max-scalar surrogate := [0]{0, 2} [dD] [8-9a-fA-F] hex-digit{2} // U+D800-DFFF: D 8 00 // D F FF above-max-scalar = [2-9a-fA-F] hex-digit{5} | [1] [1-9a-fA-F] hex-digit{4}
p_ws_escape :: Parser () Source #
ref: (3.11.1.1)
ws-escape := \\ (unicode-space | newline)+
(3.12) Multi-line String
p_multi_line_string_body :: Parser end -> Parser MultilineChars Source #
ref: (3.12) multi-line-string-body := (('"' | '""')? string-character)*
Requires some changes to the grammar: https://github.com/kdl-org/kdl/pull/552
(3.13) Raw String
p_raw_string :: Parser Text Source #
ref: (3.13)
raw-string := # raw-string-quotes # | # raw-string #
p_raw_string_quotes :: Parser end -> Parser Text Source #
ref: (3.13) raw-string-quotes := '"' single-line-raw-string-body '"' | '"""' newline (multi-line-raw-string-body newline)? unicode-space* '"""'
p_single_line_raw_string_body :: Parser end -> Parser () Source #
ref: (3.13) single-line-raw-string-body := '' | (single-line-raw-string-char - '"') single-line-raw-string-char*? | '"' (single-line-raw-string-char - '"') single-line-raw-string-char*?
p_single_line_raw_string_char :: Parser Char Source #
ref: (3.13) single-line-raw-string-char := unicode - newline - disallowed-literal-code-points
p_multi_line_raw_string_body :: Parser end -> Parser MultilineChars Source #
ref: (3.13) multi-line-raw-string-body := (unicode - disallowed-literal-code-points)*?
(3.14) Number
p_number :: Parser ValueData Source #
ref: (3.14) number := keyword-number | hex | octal | binary | decimal
p_hex :: Parser Scientific Source #
ref: (3.14) hex := sign? '0x' hex-digit (hex-digit | '_')*
p_hex_digit :: Parser Int Source #
ref: (3.14) hex-digit := [0-9a-fA-F]
p_octal :: Parser Scientific Source #
ref: (3.14) octal := sign? '0o' [0-7] [0-7_]*
p_binary :: Parser Scientific Source #
ref: (3.14) binary := sign? '0b' ('0' | '1') ('0' | '1' | '_')*
p_exponent :: Parser Int Source #
ref: (3.14)
exponent := (e | E) sign? integer
p_keyword_number :: Parser ValueData Source #
ref: (3.14.1) keyword-number := '#inf' | '#-inf' | '#nan'
(3.15) Boolean
(3.17) Whitespace
p_unicode_space :: Parser Char Source #
ref: (3.17)
unicode-space := See Table
(All White_Space unicode characters which are not newline)
p_single_line_comment :: Parser Text Source #
ref: (3.17.1)
single-line-comment := // ^newline* (newline | eof)
p_multi_line_comment :: Parser Text Source #
ref: (3.17.2)
multi-line-comment := /* commented-block
p_slashdash :: Parser SlashdashResult Source #
ref: (3.17.3)
slashdash := /- line-space*
(3.18) Newline
(3.19) Disallowed Literal Code Points
is_disallowed_literal_code_points :: Char -> Bool Source #
ref: (3.19) disallowed-literal-code-points := See Table (Disallowed Literal Code Points)