Skip to content

Commit

Permalink
feat(parser/renderer): support for labeled list
Browse files Browse the repository at this point in the history
Support the `term:: description` syntax

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Jan 28, 2018
1 parent 8457fa5 commit 57ff072
Show file tree
Hide file tree
Showing 14 changed files with 2,083 additions and 1,320 deletions.
62 changes: 48 additions & 14 deletions parser/asciidoc-grammar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DocumentBlocks <- content:(Preamble Section+) / content:(StandaloneBlock*) {
return content, nil
}

StandaloneBlock <- DocumentAttributeDeclaration / DocumentAttributeReset / TableOfContentsMacro / List / BlockImage / LiteralBlock / DelimitedBlock / Paragraph / (ElementAttribute EOL) / BlankLine //TODO: should Paragraph be the last type ?
StandaloneBlock <- DocumentAttributeDeclaration / DocumentAttributeReset / TableOfContentsMacro / BlockImage / List / LiteralBlock / DelimitedBlock / Paragraph / (ElementAttribute EOL) / BlankLine //TODO: should Paragraph be the last type ?

Preamble <- elements:(StandaloneBlock*) {
return types.NewPreamble(elements.([]interface{}))
Expand Down Expand Up @@ -195,21 +195,55 @@ Section5Title <- attributes:(ElementAttribute)* level:("======") WS+ content:Inl
}

// ------------------------------------------
// List Items
// Lists
// ------------------------------------------
List <- attributes:(ElementAttribute)*
List <- UnorderedList / LabeledList

UnorderedList <- attributes:(ElementAttribute)*
// list items can be followed by an optional, single blank line
elements:(ListItem BlankLine?)+ {
return types.NewList(elements.([]interface{}), attributes.([]interface{}))
elements:(UnorderedListItem BlankLine?)+ {
return types.NewUnorderedList(elements.([]interface{}), attributes.([]interface{}))
}

ListItem <- WS* level:("*"+ / "-") WS+ content:(ListItemContent) {
return types.NewListItem(level, content.(*types.ListItemContent), nil)
UnorderedListItem <- WS* level:("*"+ / "-") WS+ content:(UnorderedListItemContent) {
return types.NewUnorderedListItem(level, content.(*types.ListItemContent), nil)
}

ListItemContent <- lines:(!(WS* ("*"+ / "-") WS+) InlineContent EOL)+ {
return types.NewListItemContent(lines.([]interface{}))
UnorderedListItemContent <- lines:(!(WS* ("*"+ / "-") WS+) InlineContent EOL)+ {
return types.NewUnorderedListItemContent(lines.([]interface{}))
}

LabeledList <- attributes:(ElementAttribute)*
// list items can be followed by any number of optional, single blank line
elements:(LabeledListItem+) {
return types.NewLabeledList(elements.([]interface{}), attributes.([]interface{}))
}

LabeledListItem <- LabeledListItemWithDescription / LabeledListItemWithTermAlone

LabeledListItemWithDescription <- term:(LabeledListItemTerm) LabeledListItemSeparator description:(LabeledListItemDescription) {
return types.NewLabeledListItem(term.([]interface{}), description)
}

LabeledListItemWithTermAlone <- term:(LabeledListItemTerm) "::" WS* EOL { // here, WS is optional since there is no description afterwards
return types.NewLabeledListItem(term.([]interface{}), nil)
}

LabeledListItemTerm <- term:(!NEWLINE !"::" .)* {
return term, nil
}

// term separator: ('::') and at least one space or endline
LabeledListItemSeparator <- "::" (WS / NEWLINE)+

LabeledListItemDescription <- lines:(LabeledListItemDescriptionLine EOL)+ {
return types.NewLabeledListItemDescription(lines.([]interface{}))
}

LabeledListItemDescriptionLine <- !(LabeledListItemTerm LabeledListItemSeparator) content:(InlineContent) &EOL {
return content, nil
}

// ------------------------------------------
// Paragraphs
// ------------------------------------------
Expand Down Expand Up @@ -511,14 +545,14 @@ URL_TEXT <- (!NEWLINE !"[" !"]" .)+ {

URL_SCHEME <- "http://" / "https://" / "ftp://" / "irc://" / "mailto:"

DIGIT <- [0-9]
DIGIT <- [0-9]

NEWLINE <- "\r\n" / "\r" / "\n"
NEWLINE <- "\r\n" / "\r" / "\n"

WS <- " " / "\t" {
WS <- " " / "\t" {
return string(c.text), nil
}

EOF <- !.
EOF <- !.

EOL <- NEWLINE / EOF
EOL <- NEWLINE / EOF
Loading

0 comments on commit 57ff072

Please sign in to comment.