From: Jan Nieuwenhuizen Date: Wed, 20 Oct 1999 15:15:07 +0000 (+0200) Subject: patch::: 1.2.15.jcn4 X-Git-Tag: release/1.2.16~1 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=ccbdd4aa99225a649a9fe8290f6e0c1d28e955c7;p=lilypond.git patch::: 1.2.15.jcn4 pl 15.jcn4 - direct #... to scm parser (Tanks to Gary Houston) --- diff --git a/CHANGES b/CHANGES index fd5211f724..3c38ef3ad1 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +pl 15.jcn4 + - direct #... to scm parser (Tanks to Gary Houston) + pl 15.jcn3 - bf: smob fix? - mutopia/doc target 'local-web': diff --git a/VERSION b/VERSION index 2898e1d987..bac0e1065b 100644 --- a/VERSION +++ b/VERSION @@ -2,7 +2,7 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=1 MINOR_VERSION=2 PATCH_LEVEL=15 -MY_PATCH_LEVEL=jcn3 +MY_PATCH_LEVEL=jcn4 # use the above to send patches: MY_PATCH_LEVEL is always empty for a # released version. diff --git a/input/test/embedded-scm.ly b/input/test/embedded-scm.ly new file mode 100644 index 0000000000..d530c85965 --- /dev/null +++ b/input/test/embedded-scm.ly @@ -0,0 +1,4 @@ +#(begin (newline)(display "hello world")(newline))\score{ + \notes\relative c'{ c } +} + diff --git a/lily/include/lily-guile.hh b/lily/include/lily-guile.hh index 90773ac8d1..55719cb91b 100644 --- a/lily/include/lily-guile.hh +++ b/lily/include/lily-guile.hh @@ -24,6 +24,7 @@ SCM ly_set_scm (String name , SCM val); SCM ly_append (SCM a, SCM b); SCM ly_eval (SCM a); SCM ly_func_o (char const* name); +SCM ly_parse_scm (char const* s, int* n); SCM ly_quote_scm (SCM s); void ly_display_scm (SCM s); String ly_scm2string (SCM s); diff --git a/lily/lexer.ll b/lily/lexer.ll index 42e4996c58..a59d10de16 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -4,7 +4,8 @@ source file of the LilyPond music typesetter - (c) 1996,1997 Han-Wen Nienhuys + (c) 1996--1999 Han-Wen Nienhuys + Jan Nieuwenhuizen */ @@ -29,6 +30,7 @@ #include "my-lily-lexer.hh" #include "array.hh" #include "interval.hh" +#include "lily-guile.hh" #include "parser.hh" #include "debug.hh" #include "main.hh" @@ -231,6 +233,33 @@ HYPHEN -- cerr << _ ("white expected") << endl; exit (1); } +# { //embedded scm + //char const* s = YYText () + 1; + char* s = (char*)YYText () + 1; + int n = 0; + if (!main_input_b_ && safe_global_b) { + error (_ ("Can't evaluate Scheme in safe mode")); + return SCM_EOL; + } + /* + urg: replace 0 char with original value + */ + *s = (char)yyinput (); + yylval.scm = ly_parse_scm (s, &n); + + if (!n) + unput (*s); + else + n--; + /* + urg, this + yyin->seekg (n, ios::cur); + doesn't work, is there no other way? + */ + for (int i=0; i < n; i++) + yyinput (); + return SCM_T; +} { {ALPHAWORD} { return scan_bare_word (YYText ()); diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index 311397cdd8..ded411da83 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -33,6 +33,41 @@ ly_ch_C_eval_scm (char const*c) return gh_eval_str ((char*)c); } + +/* + Pass string to scm parser, evaluate one expression. + Return result value and #chars read. + + Thanks to Gary Houston + + Need guile-1.3.4 (>1.3 anyway) for ftell on str ports -- jcn +*/ +SCM +ly_parse_scm (char const* s, int* n) +{ + SCM str = gh_str02scm ((char*)s); + SCM port = scm_mkstrport (SCM_INUM0, str, SCM_OPN | SCM_RDNG, + "scm_eval_0str"); + SCM from = scm_ftell (port); + + SCM form; + SCM answer = SCM_UNSPECIFIED; + + /* Read expression from port */ + if (!SCM_EOF_OBJECT_P (form = scm_read (port))) + answer = scm_eval_x (form); + + SCM to = scm_ftell (port); + *n = gh_scm2int (to) - gh_scm2int (from); + + /* Don't close the port here; if we re-enter this function via a + continuation, then the next time we enter it, we'll get an error. + It's a string port anyway, so there's no advantage to closing it + early. */ + + return answer; +} + /* scm_m_quote doesn't use any env, but needs one for a good signature in GUILE. */ diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index 49d84d6335..d58d5a49b7 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -11,6 +11,7 @@ #include "notename-table.hh" #include "interval.hh" #include "identifier.hh" +#include "lily-guile.hh" #include "parser.hh" #include "keyword.hh" #include "my-lily-lexer.hh" @@ -64,8 +65,6 @@ static Keyword_ent the_key_tab[]={ {"repeat", REPEAT}, {"repetitions", REPETITIONS}, {"addlyrics", ADDLYRICS}, - {"scm", SCM_T}, - {"scmfile", SCMFILE}, {"score", SCORE}, {"script", SCRIPT}, {"shape", SHAPE}, diff --git a/lily/my-lily-parser.cc b/lily/my-lily-parser.cc index aaae6a6d94..11ae2eeda4 100644 --- a/lily/my-lily-parser.cc +++ b/lily/my-lily-parser.cc @@ -14,6 +14,7 @@ #include "music-list.hh" #include "musical-request.hh" #include "command-request.hh" +#include "lily-guile.hh" #include "parser.hh" #include "scope.hh" #include "file-results.hh" diff --git a/lily/parser.yy b/lily/parser.yy index 4d84041f38..c57599860d 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -5,7 +5,7 @@ source file of the GNU LilyPond music typesetter - (c) 1997 Han-Wen Nienhuys + (c) 1997--1999 Han-Wen Nienhuys Jan Nieuwenhuizen */ @@ -99,6 +99,7 @@ print_mudela_versions (ostream &os) Real real; Request * request; Scalar *scalar; + SCM scm; String *string; Tempo_req *tempo; @@ -170,7 +171,6 @@ yylex (YYSTYPE *s, void * v_l) %token REPETITIONS %token ADDLYRICS %token SCM_T -%token SCMFILE %token SCORE %token SCRIPT %token SHAPE @@ -208,6 +208,7 @@ yylex (YYSTYPE *s, void * v_l) %token REAL %token DURATION RESTNAME %token STRING +%token SCM_T %token UNSIGNED @@ -239,6 +240,7 @@ yylex (YYSTYPE *s, void * v_l) %type duration_length %type scalar +%type embedded_scm %type Music Sequential_music Simultaneous_music Music_sequence %type relative_music re_rhythmed_music %type property_def translator_change @@ -300,21 +302,14 @@ toplevel_expression: Midi_def_identifier ($1, MIDI_IDENTIFIER); THIS->lexer_p_->set_identifier ("$defaultmidi", id) } - | embedded_scm { - } + | embedded_scm { + // junk value + } ; embedded_scm: - SCMFILE STRING semicolon { - read_lily_scm_file (*$2); - delete $2; - } - | SCM_T STRING semicolon { - if (THIS->lexer_p_->main_input_b_ && safe_global_b) - error (_("Can't evaluate Scheme in safe mode")); - gh_eval_str ($2->ch_l ()); - delete $2; - }; + SCM_T + ; chordmodifiers_block: diff --git a/ly/accordion-defs.ly b/ly/accordion-defs.ly index b4051d111a..1c90a9c16f 100644 --- a/ly/accordion-defs.ly +++ b/ly/accordion-defs.ly @@ -6,7 +6,7 @@ % 16' = S % -\scmfile "accordion-script.scm"; +#(primitive-load-path "accordion-script.scm") accDiscant = \script "accDiscant" accDiscantF = \script "accDiscantF" diff --git a/ly/script.ly b/ly/script.ly index 38f89853d2..430f31d9ed 100644 --- a/ly/script.ly +++ b/ly/script.ly @@ -1,5 +1,5 @@ -\scmfile "script.scm"; +#(primitive-load-path "script.scm") "dash-hat" = "marcato" "dash-plus" = "stopped" @@ -44,4 +44,4 @@ prallmordent = \script "prallmordent" upprall = \script "upprall" downprall = \script "downprall" segno = \script "segno" -coda = \script "coda" \ No newline at end of file +coda = \script "coda"