Skip to content

Commit

Permalink
feat(parser): support front-matter in YAML format (bytesparadise#28)
Browse files Browse the repository at this point in the history
Front-matter tokens must be `---`.
Front-matter content is parsed using the `gopkg.in/yaml.v2`
library: no need to recreate the YAML grammar here !

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Oct 10, 2017
1 parent 4a9a376 commit b69fe01
Show file tree
Hide file tree
Showing 9 changed files with 946 additions and 730 deletions.
8 changes: 4 additions & 4 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ import:
- package: github.com/onsi/ginkgo
version: ^1.4.0
- package: github.com/onsi/gomega
version: ^1.2.0
version: ^1.2.0
- package: gopkg.in/yaml.v2
24 changes: 20 additions & 4 deletions parser/asciidoc-grammar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,33 @@ import "github.com/bytesparadise/libasciidoc/types"

}

Document <- blocks:DocumentBlock* EOF {
return types.NewDocument(blocks.([]interface{}))
Document <- frontmatter:(FrontMatter?) blocks:(DocumentBlock*) EOF {
if frontmatter != nil {
return types.NewDocument(frontmatter.(*types.FrontMatter), blocks.([]interface{}))
}
return types.NewDocument(nil, blocks.([]interface{}))
}

DocumentBlock <- !EOF content:(Section / StandaloneBlock) {
DocumentBlock <- content:(Section / StandaloneBlock) {
return content.(types.DocElement), nil
}

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

// ------------------------------------------
// Front Matter
// ------------------------------------------
FrontMatter <- YamlFrontMatter

FrontMatter <- YamlFrontMatterToken content:(!YamlFrontMatterToken .)* YamlFrontMatterToken {
return types.NewYamlFrontMatter(content.([]interface{}))
}

YamlFrontMatterToken <- "---" EOL

// ------------------------------------------
// Sections
// ------------------------------------------
Section <- Section1 / Section2 / Section3 / Section4 / Section5 / Section6

Section1 <- heading:(Heading1) elements:(Section1Block*) {
Expand Down Expand Up @@ -69,7 +86,6 @@ Section6Block <- !Section1 !Section2 !Section3 !Section4 !Section5 !Section6 con
return content.(types.DocElement), nil
}


// ------------------------------------------
// Headings
// ------------------------------------------
Expand Down
Loading

0 comments on commit b69fe01

Please sign in to comment.