Hello,

While trying to write a protocol for parsing portions of LilyPond text,
typically for more interactive editing (a quick insert mode that
really works), I encoutered few problems wrt input locations. For
instance:

  guile> (lyp:print-parse-tree (lyp:parse-line "c8.\\f d16 e8 f g2"))
  [0-17] SequentialMusic "c8.\\f d16 e8 f g2"
      [0-5] EventChord "c8.\\f"
          [0-3] NoteEvent "c8."
          [3-5] AbsoluteDynamicEvent "\\f"
      [5-9] EventChord " d16"
          [5-9] NoteEvent " d16"
      [9-12] EventChord " e8"
          [9-12] NoteEvent " e8"
      [12-14] EventChord " f"
          [12-14] NoteEvent " f"
      [14-17] EventChord " g2"
          [14-17] NoteEvent " g2"

This works for basic examples like this one, but fails when markups,
or chords are encountered. Input locations are not accurate in the
following example:

  guile> (lyp:print-parse-tree (lyp:parse-line "c8.^\\markup foo d16"))
  [0-19] SequentialMusic "c8.^\\markup foo d16"
      [0-15] EventChord "c8.^\\markup foo"
          [0-13] NoteEvent "c8.^\\markup f"
          [13-15] TextScriptEvent "oo"
      [15-19] EventChord " d16"
          [15-19] NoteEvent " d16"
  guile> (mus:display (lyp:parse-string "c8.^\\markup foo d16"))
  (make-music 'SequentialMusic
    'origin #<location <string>:1:1>
    'elements (list
               (make-music 'EventChord
                 'origin #<location <string>:1:1>
                 'elements (list
                            (make-music 'NoteEvent
                              'origin #<location <string>:1:1>
                              'duration (ly:make-duration 3 1 1 1)
                              'pitch (ly:make-pitch -1 0 0))
                            (make-music 'TextScriptEvent
                              'direction 1
                              'origin #<location <string>:1:14>
                              'text (list
                                         simple-markup
                                         "foo"))))
               (make-music 'EventChord
                 'origin #<location <string>:1:16>
                 'elements (list
                            (make-music 'NoteEvent
                              'origin #<location <string>:1:16>
                              'duration (ly:make-duration 4 0 1 1)
                              'pitch (ly:make-pitch -1 1 0))))))

The 'origin property of chords (eg. <c e>) is not given at all:

  guile> (mus:display (lyp:parse-string "<c e>"))
  (make-music 'SequentialMusic
    'origin #<location <string>:1:1>
    'elements (list
               (make-music 'EventChord
                 'elements (list
                            (make-music 'NoteEvent
                              'duration (ly:make-duration 2 0 1 1)
                              'pitch (ly:make-pitch -1 0 0))
                            (make-music 'NoteEvent
                              'duration (ly:make-duration 2 0 1 1)
                              'pitch (ly:make-pitch -1 2 0))))))

Moreover, when parsing multi-line strings using
`ly:parser-parse-string', the line numbers in locations are always 1.

I would like to (try to) improve the way that locations are stored in
music expression (and maybe, if some switch is on, storing not only
the input beginning but also input end or the input string). Are there
things I should know about these problems? Maybe this is not really
doable?

I know you are busy with more important stuff, it's OK if you don't
have time to answer.

nicolas



_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to