Skip to content

Commit

Permalink
fixed priority of markup parsing
Browse files Browse the repository at this point in the history
markup, even in the "inline form" (as opposed to "block form")
is always a top-level entity and closes any preceding block
  • Loading branch information
igneus committed Mar 6, 2016
1 parent ecd6aa8 commit 42c984b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 12 deletions.
3 changes: 2 additions & 1 deletion lib/gly/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def []=(key, value)
@pairs << [key, value]
end

def_delegator :@headers, :[]
def_delegators :@headers, :[], :size, :keys, :values,
:has_key?, :includes?, :include?
def_delegator :@pairs, :empty?

# some header fields may appear more than once;
Expand Down
16 changes: 9 additions & 7 deletions lib/gly/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ def parse_io(io)
parse_lyrics line
elsif explicit_music? line
parse_music line
elsif explicit_markup? line
push_score
parse_markup line
# line in a typed block
elsif @current_block != :score
parse_default line
# content type autodetection
elsif markup_line? line
push_score
parse_markup line
elsif header_line? line
parse_header line
elsif lyrics_line? line
Expand Down Expand Up @@ -119,12 +119,14 @@ def explicit_music?(str)
str =~ EXPLICIT_MUSIC_RE
end

def lyrics_line?(str)
!contains_square_brackets?(str) && (str.include?(@syllable_separator) || contains_unmusical_letters?(str))
EXPLICIT_MARKUP_RE = /\A\\markup\s*/

def explicit_markup?(str)
str =~ EXPLICIT_MARKUP_RE
end

def markup_line?(str)
str.start_with? '\markup'
def lyrics_line?(str)
!contains_square_brackets?(str) && (str.include?(@syllable_separator) || contains_unmusical_letters?(str))
end

def contains_unmusical_letters?(str)
Expand Down
8 changes: 4 additions & 4 deletions tests/examples.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# test-suite dynamically created from examples in subfolders

require_relative 'test_helper'

# Each test case is defined by a pair of files
# in directories examples/given and examples/expected
# Examples are medium-level tests (not unittests, not end-to-end tests)
# testing parser and convertor at the same time.
# Each test case is defined by a pair of a gly and gabc file
# in directories examples/*/given and examples/*/expected.
class TestExamples < GlyTest
def self.example_test_case(given_file, expected_file)
# filename without extension
Expand Down
4 changes: 4 additions & 0 deletions tests/examples/parser/markup_after_header.gly
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
\header
title: Psalmodia complementaris

\markup\section{series I (ad Tertiam)}
12 changes: 12 additions & 0 deletions tests/parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require_relative 'test_helper'

class TestParser < GlyTest
def test_markup_after_header
doc = nil
File.open expand_test_path('examples/parser/markup_after_header.gly') do |fr|
doc = Gly::Parser.new.parse(fr)
end
assert_equal 1, doc.header.size
assert doc.header.has_key?('titl')
end
end
1 change: 1 addition & 0 deletions tests/run.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require_relative 'examples'
require_relative 'no_crash'
require_relative 'string_helpers_test'
require_relative 'parser'
4 changes: 4 additions & 0 deletions tests/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ def glyfy_process(gabc_io)
score = parsing_result.create_score
Gly::GlyConvertor.new.convert score
end

def expand_test_path(relative)
File.expand_path(relative, File.dirname(__FILE__))
end
end

0 comments on commit 42c984b

Please sign in to comment.