Skip to content

Commit

Permalink
sketched out all the node/line space stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Apr 4, 2024
1 parent 9d33b47 commit 540bd0a
Showing 1 changed file with 56 additions and 6 deletions.
62 changes: 56 additions & 6 deletions src/v2_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,56 @@ fn lbl(label: &'static str) -> StrContext {
StrContext::Label(label)
}

/// `plain-line-space := newline | ws | single-line-comment`
fn plain_line_space<'s>(input: &mut Input<'s>) -> PResult<()> {
alt((newline, ws, single_line_comment)).parse_next(input)
}

/// `plain-node-space := ws* escline ws* | ws+`
fn plain_node_space<'s>(input: &mut Input<'s>) -> PResult<()> {
alt((escline, wsp)).parse_next(input)
}

/// `line-space := plain-line-space+ | '/-' plain-node-space* node`
fn line_space<'s>(input: &mut Input<'s>) -> PResult<()> {
alt((
repeat(1.., plain_line_space).map(|_: ()| ()),
("/-", repeat(0.., plain_node_space).map(|_: ()| ()), node),
))
.parse_next(input)
}

/// `node-space := plain-node-space+ ('/-' plain-node-space* (node-prop-or-arg | node-children))?`
fn node_space<'s>(input: &mut Input<'s>) -> PResult<()> {
repeat(1.., plain_node_space)
.map(|_: ()| ())
.parse_next(input)?;
opt((
"/-",
repeat(0.., plain_node_space).map(|_: ()| ()),
alt((node_or_prop_arg, node_children)),
))
.void()
.parse_next(input)
}

/// `required-node-space := node-space* plain-node-space+`
fn required_node_space<'s>(input: &mut Input<'s>) -> PResult<()> {
repeat(0.., node_space).map(|_: ()| ()).parse_next(input)?;
repeat(1.., plain_node_space).parse_next(input)
}

/// `optional-node-space := node-space*`
fn optional_node_space<'s>(input: &mut Input<'s>) -> PResult<()> {
repeat(0.., node_space).parse_next(input)
}

/// `string := identifier-string | quoted-string | raw-string`
fn string<'s>(input: &mut Input<'s>) -> PResult<Option<KdlValue>> {
alt((identifier_string, quoted_string, raw_string)).parse_next(input)
}
/// ```text
/// identifier-string := unambiguous-ident | signed-ident | dotted-ident
/// ```

/// `identifier-string := unambiguous-ident | signed-ident | dotted-ident`
fn identifier_string<'s>(input: &mut Input<'s>) -> PResult<Option<KdlValue>> {
alt((
unambiguous_ident.recognize(),
Expand All @@ -58,7 +101,7 @@ fn identifier_string<'s>(input: &mut Input<'s>) -> PResult<Option<KdlValue>> {
.parse_next(input)
}

/// unambiguous-ident := ((identifier-char - digit - sign - '.') identifier-char*) - 'true' - 'false' - 'null' - 'inf' - '-inf' - 'nan'
/// `unambiguous-ident := ((identifier-char - digit - sign - '.') identifier-char*) - 'true' - 'false' - 'null' - 'inf' - '-inf' - 'nan'`
fn unambiguous_ident<'s>(input: &mut Input<'s>) -> PResult<()> {
not(alt((digit1.void(), sign.void(), ".".void()))).parse_next(input)?;
repeat(1.., identifier_char)
Expand All @@ -74,14 +117,14 @@ fn unambiguous_ident<'s>(input: &mut Input<'s>) -> PResult<()> {
.parse_next(input)
}

/// signed-ident := sign ((identifier-char - digit - '.') identifier-char*)?
/// `signed-ident := sign ((identifier-char - digit - '.') identifier-char*)?`
fn signed_ident<'s>(input: &mut Input<'s>) -> PResult<()> {
sign.parse_next(input)?;
not(alt((digit1.void(), ".".void()))).parse_next(input)?;
repeat(0.., identifier_char).parse_next(input)
}

/// dotted-ident := sign? '.' ((identifier-char - digit) identifier-char*)?
/// `dotted-ident := sign? '.' ((identifier-char - digit) identifier-char*)?`
fn dotted_ident<'s>(input: &mut Input<'s>) -> PResult<()> {
(
opt(sign),
Expand Down Expand Up @@ -317,6 +360,13 @@ fn disallowed_unicode<'s>(input: &mut Input<'s>) -> PResult<()> {
.parse_next(input)
}

/// `escline := '\\' ws* (single-line-comment | newline | eof)`
fn escline<'s>(input: &mut Input<'s>) -> PResult<()> {
"\\".parse_next(input)?;
repeat(0.., ws).map(|_: ()| ()).parse_next(input)?;
alt((single_line_comment, newline, eof.void())).parse_next(input)
}

/// `newline := <See Table>`
fn newline<'s>(input: &mut Input<'s>) -> PResult<()> {
repeat_till(
Expand Down

0 comments on commit 540bd0a

Please sign in to comment.