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

fix(parser): ignore standalone attributes at the end of doc #606

Merged
merged 1 commit into from
Jun 14, 2020
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
11 changes: 6 additions & 5 deletions pkg/parser/document_processing_filter_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
// - all document attribute declaration/substitution/reset
// - empty preambles
// - single line comments and comment blocks
// - standalone attributes
func filter(elements []interface{}, matchers ...filterMatcher) []interface{} {
result := make([]interface{}, 0, len(elements))
elements:
Expand Down Expand Up @@ -70,7 +71,7 @@ elements:
}

// AllMatchers all the matchers needed to remove the unneeded blocks/elements from the final document
var allMatchers = []filterMatcher{emptyPreambleMatcher, documentAttributeMatcher, singleLineCommentMatcher, commentBlockMatcher}
var allMatchers = []filterMatcher{emptyPreambleMatcher, attributeMatcher, singleLineCommentMatcher, commentBlockMatcher}

// filterMatcher returns true if the given element is to be filtered out
type filterMatcher func(element interface{}) bool
Expand All @@ -85,11 +86,11 @@ var emptyPreambleMatcher filterMatcher = func(element interface{}) bool {
return result
}

// documentAttributeMatcher filters the element if it is a AttributeDeclaration,
// a AttributeSubstitution or a AttributeReset
var documentAttributeMatcher filterMatcher = func(element interface{}) bool {
// attributeMatcher filters the element if it is a AttributeDeclaration,
// a AttributeSubstitution, a AttributeReset or a standalone Attribute
var attributeMatcher filterMatcher = func(element interface{}) bool {
switch element.(type) {
case types.AttributeDeclaration, types.AttributeSubstitution, types.AttributeReset:
case types.AttributeDeclaration, types.AttributeSubstitution, types.AttributeReset, types.Attributes:
return true
default:
return false
Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var _ = Describe("documents", func() {

Context("draft document", func() {

It("empty docunment", func() {
It("empty document", func() {
source := ``
expected := types.DraftDocument{
Blocks: []interface{}{},
Expand Down
Loading