Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parser/renderer): support single line and block comments #146

Merged
merged 1 commit into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 50 additions & 26 deletions pkg/parser/asciidoc-grammar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -305,17 +305,20 @@ List <- attributes:(ElementAttribute)*

ListItems <- (OrderedListItem / UnorderedListItem / LabeledListItem)+

ListParagraph <- lines:(
!(OrderedListItemPrefix)
!(UnorderedListItemPrefix)
!(LabeledListItemTerm LabeledListItemSeparator)
!(ListItemContinuation)
!(ElementAttribute)
!(BlockDelimiter)
InlineElements EOL)+ {
ListParagraph <- lines:(ListParagraphLine)+ {
return types.NewParagraph(lines.([]interface{}), nil)
}

ListParagraphLine <- !(OrderedListItemPrefix)
!(UnorderedListItemPrefix)
!(LabeledListItemTerm LabeledListItemSeparator)
!(ListItemContinuation)
!(ElementAttribute)
!(BlockDelimiter)
line:(InlineElements) {
return line, nil
}

ListItemContinuation <- "+" WS* EOL {
return types.NewListItemContinuation()
}
Expand Down Expand Up @@ -437,21 +440,21 @@ AdmonitionKind <- "TIP" {
// a paragraph cannot start with the `section` sequence (`= `, `== `, etc.)
Paragraph <-
// admonition paragraph
attributes:(ElementAttribute)* !("="+ WS+ !NEWLINE) t:(AdmonitionKind) ": " lines:(InlineElements EOL)+ {
attributes:(ElementAttribute)* !("="+ WS+ !NEWLINE) t:(AdmonitionKind) ": " lines:(InlineElements)+ {
return types.NewAdmonitionParagraph(lines.([]interface{}), t.(types.AdmonitionKind), attributes.([]interface{}))
} /
// regular paragraph
attributes:(ElementAttribute)* !("="+ WS+ !NEWLINE) lines:(InlineElements EOL)+ {
attributes:(ElementAttribute)* !("="+ WS+ !NEWLINE) lines:(InlineElements)+ {
return types.NewParagraph(lines.([]interface{}), attributes.([]interface{}))
}

InlineElements <- !EOF !BlockDelimiter elements:(!EOL WS* !InlineElementID InlineElement WS*)+ { // absorbs heading and trailing spaces
// fmt.Printf("matching inline elements: %v\n", elements)
InlineElements <- comment:(SingleLineComment) {
return types.NewInlineElements([]interface{}{comment})
} / !EOF !BlockDelimiter elements:(!EOL WS* !InlineElementID InlineElement WS*)+ EOL { // absorbs heading and trailing spaces
return types.NewInlineElements(elements.([]interface{}))
}

InlineElement <- element:(CrossReference / Passthrough / InlineImage / QuotedText / Link / DocumentAttributeSubstitution / Word) {
// fmt.Printf("matching inline element: %v\n", element)
return element, nil
}

Expand Down Expand Up @@ -635,39 +638,60 @@ ImageHeightAttribute <- "," value:(!"," !"]" .)+ {
// ------------------------------------------------------------------------------------
// Delimited Blocks (http://asciidoctor.org/docs/user-manual/#built-in-blocks-summary)
// ------------------------------------------------------------------------------------
DelimitedBlock <- FencedBlock / ListingBlock / ExampleBlock
DelimitedBlock <- FencedBlock / ListingBlock / ExampleBlock / CommentBlock

BlockDelimiter <- LiteralBlockDelimiter / FencedBlockDelimiter / ListingBlockDelimiter / ExampleBlockDelimiter
BlockDelimiter <- LiteralBlockDelimiter / FencedBlockDelimiter / ListingBlockDelimiter / ExampleBlockDelimiter / CommentBlockDelimiter

FencedBlockDelimiter <- "```"

FencedBlock <- attributes:(ElementAttribute)* FencedBlockDelimiter WS* NEWLINE content:(List / BlockParagraph / BlankLine)* ((FencedBlockDelimiter WS* EOL) / EOF) {
return types.NewDelimitedBlock(types.FencedBlock, content.([]interface{}), attributes.([]interface{}))
return types.NewDelimitedBlock(types.FencedBlock, content.([]interface{}), attributes.([]interface{}), types.None)
}

ListingBlockDelimiter <- "----"

ListingBlock <- attributes:(ElementAttribute)* ListingBlockDelimiter WS* NEWLINE content:(List / BlockParagraph / BlankLine)* ((ListingBlockDelimiter WS* EOL) / EOF) {
return types.NewDelimitedBlock(types.ListingBlock, content.([]interface{}), attributes.([]interface{}))
return types.NewDelimitedBlock(types.ListingBlock, content.([]interface{}), attributes.([]interface{}), types.None)
}

ExampleBlockDelimiter <- "===="

ExampleBlock <- attributes:(ElementAttribute)* ExampleBlockDelimiter WS* NEWLINE content:(List / BlockParagraph / BlankLine)* ((ExampleBlockDelimiter WS* EOL) / EOF) {
return types.NewDelimitedBlock(types.ExampleBlock, content.([]interface{}), attributes.([]interface{}))
return types.NewDelimitedBlock(types.ExampleBlock, content.([]interface{}), attributes.([]interface{}), types.None)
}

BlockParagraph <- lines:(
!(OrderedListItemPrefix)
!(UnorderedListItemPrefix)
!(LabeledListItemTerm LabeledListItemSeparator)
!(ListItemContinuation)
//!(ElementAttribute)
!(BlockDelimiter)
InlineElements EOL)+ {
BlockParagraph <- lines:(BlockParagraphLine)+ {
return types.NewParagraph(lines.([]interface{}), nil)
}

BlockParagraphLine <- !(OrderedListItemPrefix)
!(UnorderedListItemPrefix)
!(LabeledListItemTerm LabeledListItemSeparator)
!(ListItemContinuation)
!(BlockDelimiter)
line:(InlineElements) {
return line, nil
}

// -------------------------------------------------------------------------------------
// Comments
// -------------------------------------------------------------------------------------

CommentBlockDelimiter <- "////"

CommentBlock <- attributes:(ElementAttribute)* CommentBlockDelimiter WS* NEWLINE content:(CommentBlockLine)* ((CommentBlockDelimiter WS* EOL) / EOF) {
return types.NewDelimitedBlock(types.CommentBlock, content.([]interface{}), attributes.([]interface{}), types.Verbatim)
}

CommentBlockLine <- content:(!CommentBlockDelimiter !EOL .)* EOL {
return content, nil
}

SingleLineComment <- !CommentBlockDelimiter "//" content:(!EOL .)* EOL {
return types.NewSingleLineComment(content.([]interface{}))
}


// -------------------------------------------------------------------------------------
// Literal Blocks (see http://asciidoctor.org/docs/user-manual/#literal-text-and-blocks)
// -------------------------------------------------------------------------------------
Expand Down
Loading