From: Jan Nieuwenhuizen Date: Sun, 25 Apr 2004 09:55:27 +0000 (+0000) Subject: * lily/my-lily-parser.cc: X-Git-Tag: release/2.3.1~51 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e5059486b5084c26490ade11125aa1c5810657d9;p=lilypond.git * lily/my-lily-parser.cc: * lily/my-lily-lexer.cc: Another step towards parsing ly code from SCM string (foo.ly/toto.scm support). --- diff --git a/ChangeLog b/ChangeLog index c4bb553538..1361b594f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-04-25 Jan Nieuwenhuizen + + * lily/my-lily-parser.cc: + * lily/my-lily-lexer.cc: Another step towards parsing ly code from + SCM string (foo.ly/toto.scm support). + 2004-04-24 Jan Nieuwenhuizen * lily/my-lily-parser.cc (ly:parser-parse-string): New function. diff --git a/lily/include/my-lily-lexer.hh b/lily/include/my-lily-lexer.hh index 62f7693bb8..44f3966fc0 100644 --- a/lily/include/my-lily-lexer.hh +++ b/lily/include/my-lily-lexer.hh @@ -6,8 +6,8 @@ (c) 1997--2004 Han-Wen Nienhuys */ -#ifndef LEXER_HH -#define LEXER_HH +#ifndef MY_LILY_LEXER_HH +#define MY_LILY_LEXER_HH #include "includable-lexer.hh" @@ -26,29 +26,39 @@ void set_lexer (); class My_lily_lexer : public Includable_lexer { +public: Protected_scm scopes_; Protected_scm encoding_; + +private: + int lookup_keyword (String); + int scan_bare_word (String); + SCM scan_markup_word (String); + int scan_escaped_word (String); + int identifier_type (SCM); + char escaped_char (char) const; + public: String main_input_name_; void *lexval; bool main_input_b_; - Sources * sources_; + Sources *sources_; - /* - Scheme hash tables with (oct name acc) values, and symbol keys - */ + /* Scheme hash tables with (oct name acc) values, and symbol keys. */ Protected_scm chordmodifier_tab_; Protected_scm pitchname_tab_stack_; - Keyword_table * keytable_; + Keyword_table *keytable_; int error_level_; + Input last_input_; My_lily_lexer (Sources*); + My_lily_lexer (My_lily_lexer const&); ~My_lily_lexer (); + int yylex (); - Input last_input_; void prepare_for_next_token (); int try_special_identifiers (SCM* ,SCM); Input here_input () const; @@ -74,13 +84,6 @@ public: bool is_chord_state () const; bool is_lyric_state () const; bool is_figure_state () const; -private: - int lookup_keyword (String); - int scan_bare_word (String); - SCM scan_markup_word (String); - int scan_escaped_word (String); - int identifier_type (SCM); - char escaped_char (char) const; }; -#endif +#endif /* MY_LILY_LEXER_HH */ diff --git a/lily/include/my-lily-parser.hh b/lily/include/my-lily-parser.hh index 58afacb257..2742ec7530 100644 --- a/lily/include/my-lily-parser.hh +++ b/lily/include/my-lily-parser.hh @@ -53,6 +53,7 @@ public: SCM last_beam_start_; My_lily_parser (Sources *sources); + My_lily_parser (My_lily_parser const&); DECLARE_SCHEME_CALLBACK (paper_description, ()); diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index 44ab32fcd3..51fda8586a 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -93,19 +93,33 @@ static Keyword_ent the_key_tab[] = { }; -My_lily_lexer::My_lily_lexer (Sources *srcs) +My_lily_lexer::My_lily_lexer (Sources *sources) + { keytable_ = new Keyword_table (the_key_tab); encoding_ = SCM_EOL; chordmodifier_tab_ = scm_make_vector (scm_int2num (1), SCM_EOL); pitchname_tab_stack_ = SCM_EOL; - sources_ = srcs; + sources_ = sources; scopes_ = SCM_EOL; + error_level_ = 0; + main_input_b_ = false; add_scope (ly_make_anonymous_module ()); - error_level_ = 0; +} - main_input_b_ = false; +My_lily_lexer::My_lily_lexer (My_lily_lexer const &src) + : Includable_lexer () +{ + keytable_ = src.keytable_; + encoding_ = src.encoding_; + chordmodifier_tab_ = src.chordmodifier_tab_; + pitchname_tab_stack_ = src.pitchname_tab_stack_; + sources_ = src.sources_; + scopes_ = src.scopes_; + error_level_ = src.error_level_; + // main_input_b_ = false; + main_input_b_ = src.main_input_b_; } SCM diff --git a/lily/my-lily-parser.cc b/lily/my-lily-parser.cc index 5148a238d1..c34351f65d 100644 --- a/lily/my-lily-parser.cc +++ b/lily/my-lily-parser.cc @@ -39,6 +39,20 @@ My_lily_parser::My_lily_parser (Sources *sources) smobify_self (); } +My_lily_parser::My_lily_parser (My_lily_parser const &src) +{ + book_count_ = src.book_count_; + score_count_ = src.score_count_; + lexer_ = src.lexer_; + sources_ = src.sources_; + default_duration_ = src.default_duration_; + error_level_ = src.error_level_; + last_beam_start_ = src.last_beam_start_; + header_ = src.header_; + + smobify_self (); +} + My_lily_parser::~My_lily_parser () { delete lexer_; @@ -97,7 +111,10 @@ My_lily_parser::parse_file (String init, String name, String out_name) void My_lily_parser::parse_string (String ly_code) { - lexer_ = new My_lily_lexer (sources_); + My_lily_lexer *parent = lexer_; + lexer_ = (parent == 0 ? new My_lily_lexer (sources_) + : new My_lily_lexer (*parent)); + lexer_->main_input_name_ = ""; lexer_->main_input_b_ = true; @@ -112,6 +129,18 @@ My_lily_parser::parse_string (String ly_code) } error_level_ = error_level_ | lexer_->error_level_; + + if (parent != 0) + { + parent->keytable_ = lexer_->keytable_; + parent->encoding_ = lexer_->encoding_; + parent->chordmodifier_tab_ = lexer_->chordmodifier_tab_; + parent->pitchname_tab_stack_ = lexer_->pitchname_tab_stack_; + parent->sources_ = lexer_->sources_; + parent->scopes_ = lexer_->scopes_; + parent->error_level_ = lexer_->error_level_; + parent->main_input_b_ = lexer_->main_input_b_; + } } void @@ -133,8 +162,6 @@ My_lily_parser::parser_error (String s) error_level_ = 1; } - - Input My_lily_parser::pop_spot () { @@ -323,12 +350,15 @@ LY_DEFINE (ly_parser_parse_string, "ly:parser-parse-string", #endif SCM_ASSERT_TYPE (ly_c_string_p (ly_code), ly_code, SCM_ARG1, __FUNCTION__, "string"); -#if 1 +#if 0 My_lily_parser *parser = unsmob_my_lily_parser (parser_smob); + parser->parse_string (ly_scm2string (ly_code)); #else - /* New parser, copy vars but no state? */ + My_lily_parser *parser = unsmob_my_lily_parser (parser_smob); + My_lily_parser *clone = new My_lily_parser (*parser); + clone->parse_string (ly_scm2string (ly_code)); + clone = 0; #endif - parser->parse_string (ly_scm2string (ly_code)); return SCM_UNSPECIFIED; }