+2004-04-25 Jan Nieuwenhuizen <janneke@gnu.org>
+
+ * 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 <janneke@gnu.org>
* lily/my-lily-parser.cc (ly:parser-parse-string): New function.
(c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
-#ifndef LEXER_HH
-#define LEXER_HH
+#ifndef MY_LILY_LEXER_HH
+#define MY_LILY_LEXER_HH
#include "includable-lexer.hh"
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;
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 */
SCM last_beam_start_;
My_lily_parser (Sources *sources);
+ My_lily_parser (My_lily_parser const&);
DECLARE_SCHEME_CALLBACK (paper_description, ());
};
-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
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_;
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_ = "<string>";
lexer_->main_input_b_ = true;
}
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
error_level_ = 1;
}
-
-
Input
My_lily_parser::pop_spot ()
{
#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;
}