Module: Musicality::Parsing::Key

Includes:
Pitch, Treetop::Runtime
Included in:
KeyParser
Defined in:
lib/musicality/notation/parsing/key_parsing.rb

Defined Under Namespace

Modules: Key0, Key1

Instance Method Summary collapse

Methods included from Pitch

#_nt_cent, #_nt_letter_a, #_nt_letter_b, #_nt_letter_c, #_nt_letter_d, #_nt_letter_e, #_nt_letter_f, #_nt_letter_g, #_nt_octave, #_nt_pitch, #_nt_pitch_letter

Methods included from NonnegativeInteger

#_nt_nonnegative_integer

Instance Method Details

#_nt_keyObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/musicality/notation/parsing/key_parsing.rb', line 51

def _nt_key
  start_index = index
  if node_cache[:key].has_key?(index)
    cached = node_cache[:key][index]
    if cached
      node_cache[:key][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0, s0 = index, []
  r1 = _nt_pitch_letter
  s0 << r1
  if r1
    if has_terminal?(@regexps[gr = '\A[#b]'] ||= Regexp.new(gr), :regexp, index)
      r3 = true
      @index += 1
    else
      terminal_parse_failure('[#b]')
      r3 = nil
    end
    if r3
      r2 = r3
    else
      r2 = instantiate_node(SyntaxNode,input, index...index)
    end
    s0 << r2
    if r2
      r4 = _nt_major_minor
      s0 << r4
    end
  end
  if s0.last
    r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
    r0.extend(Key0)
    r0.extend(Key1)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:key][start_index] = r0

  r0
end

#_nt_major_minorObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/musicality/notation/parsing/key_parsing.rb', line 98

def _nt_major_minor
  start_index = index
  if node_cache[:major_minor].has_key?(index)
    cached = node_cache[:major_minor][index]
    if cached
      node_cache[:major_minor][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0 = index
  if (match_len = has_terminal?("maj", false, index))
    r1 = instantiate_node(SyntaxNode,input, index...(index + match_len))
    @index += match_len
  else
    terminal_parse_failure('"maj"')
    r1 = nil
  end
  if r1
    r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
    r0 = r1
  else
    if (match_len = has_terminal?("min", false, index))
      r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
      @index += match_len
    else
      terminal_parse_failure('"min"')
      r2 = nil
    end
    if r2
      r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
      r0 = r2
    else
      @index = i0
      r0 = nil
    end
  end

  node_cache[:major_minor][start_index] = r0

  r0
end

#rootObject



10
11
12
# File 'lib/musicality/notation/parsing/key_parsing.rb', line 10

def root
  @root ||= :key
end