denemo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Denemo-devel] Actions in the parser rules


From: Richard Shann
Subject: [Denemo-devel] Actions in the parser rules
Date: Mon, 09 Aug 2010 11:49:54 +0100

I mentioned, when guesting on irc just now, that I have in mind how to
handle the actions in the rules. I'll outline what I have in mind here.
You don't need to grasp every implication to proceed getting the rules
into the right syntax etc. But FWIW:

While we could build up a structure and then traverse it to generate the
denemo it will take less work to generate the commands to be executed in
the action rules themselves. It will also be rather elegant.
Roughly this will mean that the value of the token NOTENAME_PITCH will
be a string something like
 "(d-C)(d-8)(d-Sharpen)(d-OctaveUp)(d-OctaveUp)"
if the input yytext was cis''8
The final action (the action for the lilypond rule) will be to execute
(eval-string $1)
where $1 is a concatenation of things it breaks down into. (It is not
everything underneath, things like assigment just store their values
into a variable etc. But things like \score actually prepend
"(d-NewMovement)" to the value of the stuff in {} which will be things
like "(d-NewStaff)". And the rule for lilypond itself will prepend
"(d-New)" to everthing before doing the eval-string proc.

There *are* wrinkles to this; but I think I have them covered, and I
think we can get a working parser going that will do at least one simple
musicxml2ly output file in a matter of a day or so, extensible to
everthing in an obvious way.

-------------------------
About the current state of the code: scan_escaped_word returns KEYWORD
if it recognises it. Otherwise it looks up a list of assignments (which
we don't have yet) and returns the value assigned with the token
assignment_id (I think it is).
e.g.

VoiceImusic = {c d e}

\score { \VoiceImusic }

will find get the value of the music (something like "(d-C)(d-D)(d-E)")
when parsing inside the score block.

Just to be clear - the scan_escaped_word procedure (you have changed the
name to lyimport::keywordtoken here, but it should stay the same, or
scan-escaped-word perhaps) is like this at the moment

  30 (define (lyimport::keywordtoken yytext)
  31         (cond
  32                 ((string-ci=? "\\score" yytext) (lyimport::mtoken 'SCORE 
yytext))
  33                 ((string-ci=? "\\nils" yytext) (lyimport::mtoken 'NILS 
yytext))
  34                 
  35                 (else (display (string-append "error: Unknown Keyword: " 
yytext " (Line: "(number->string (lexer-get-line)) " Column: " (number->string 
(lexer-get-column)) ")\n")))

 So this *only* accepts keywords, but will eventually do (essentially)
(defined? yytext) and if it is return assignment_id and the value of the
symbol yytext. I say essentially because we will need to prefix yytext
with something to prevent name clashes. That is, when we see

VoiceImusic = { a b c}

we will define a scheme variable 
(define lyimport-var::VoiceImusic "(d-A)(d-B)(d-C)")
and when we run lyimport::keywordtoken yytext we will check 

(defined? `(string-append "lyimport-var::" yytext))

(roughly).
If it is defined we return assignment_id (or whatever it is called) with
the value stored in lyimport-var::VoiceImusic.

Likewise scan_bare_word will need to return STRING if it fails to match
a notename. So create lyimport::scan-bare-word to do this (and rename
lyimport::keywordtoken to lyimport::scan-escaped-word).


Is this ok?

Richard







reply via email to

[Prev in Thread] Current Thread [Next in Thread]