From a4cc26c32b822769ce54c72d94a93936195d3eb9 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Mon, 5 Sep 2011 11:48:25 +0200 Subject: [PATCH] lexer.ll: Allow push_extra_token to take a Scheme value as well. --- lily/include/lily-lexer.hh | 4 ++-- lily/lexer.ll | 20 +++++++++++--------- lily/lily-lexer.cc | 3 +++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lily/include/lily-lexer.hh b/lily/include/lily-lexer.hh index 9729ca7016..54e068ee7a 100644 --- a/lily/include/lily-lexer.hh +++ b/lily/include/lily-lexer.hh @@ -62,7 +62,7 @@ private: SCM start_module_; int hidden_state_; public: - vector extra_token_types_; + SCM extra_tokens_; void *lexval_; Input *lexloc_; bool is_main_input_; @@ -101,7 +101,7 @@ public: SCM keyword_list () const; SCM lookup_identifier (string s); SCM lookup_identifier_symbol (SCM s); - void push_extra_token (int token_type); + void push_extra_token (int token_type, SCM scm = SCM_UNDEFINED); void push_chord_state (SCM tab); void push_figuredbass_state (); void push_lyric_state (); diff --git a/lily/lexer.ll b/lily/lexer.ll index 6b19c8f67d..8a07f1b2c0 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -173,9 +173,10 @@ BOM_UTF8 \357\273\277 yyless (0); /* produce requested token */ - int type = extra_token_types_.back (); - extra_token_types_.pop_back (); - if (extra_token_types_.empty ()) + int type = scm_to_int (scm_caar (extra_tokens_)); + yylval.scm = scm_cdar (extra_tokens_); + extra_tokens_ = scm_cdr (extra_tokens_); + if (scm_is_null (extra_tokens_)) yy_pop_state (); return type; @@ -185,9 +186,10 @@ BOM_UTF8 \357\273\277 /* Generate a token without swallowing anything */ /* produce requested token */ - int type = extra_token_types_.back (); - extra_token_types_.pop_back (); - if (extra_token_types_.empty ()) + int type = scm_to_int (scm_caar (extra_tokens_)); + yylval.scm = scm_cdar (extra_tokens_); + extra_tokens_ = scm_cdr (extra_tokens_); + if (scm_is_null (extra_tokens_)) yy_pop_state (); return type; @@ -721,15 +723,15 @@ BOM_UTF8 \357\273\277 /* Make the lexer generate a token of the given type as the next token. TODO: make it possible to define a value for the token as well */ void -Lily_lexer::push_extra_token (int token_type) +Lily_lexer::push_extra_token (int token_type, SCM scm) { - if (extra_token_types_.empty ()) + if (scm_is_null (extra_tokens_)) { if (YY_START != extratoken) hidden_state_ = YY_START; yy_push_state (extratoken); } - extra_token_types_.push_back (token_type); + extra_tokens_ = scm_acons (scm_from_int (token_type), scm, extra_tokens_); } void diff --git a/lily/lily-lexer.cc b/lily/lily-lexer.cc index 4bba139d3f..f80ea67703 100644 --- a/lily/lily-lexer.cc +++ b/lily/lily-lexer.cc @@ -105,6 +105,7 @@ Lily_lexer::Lily_lexer (Sources *sources, Lily_parser *parser) is_main_input_ = false; start_module_ = SCM_EOL; chord_repetition_ = Chord_repetition (); + extra_tokens_ = SCM_EOL; smobify_self (); add_scope (ly_make_module (false)); @@ -127,6 +128,7 @@ Lily_lexer::Lily_lexer (Lily_lexer const &src, Lily_parser *parser) is_main_input_ = src.is_main_input_; scopes_ = SCM_EOL; + extra_tokens_ = SCM_EOL; smobify_self (); @@ -388,6 +390,7 @@ Lily_lexer::mark_smob (SCM s) scm_gc_mark (lexer->parser_->self_scm ()); scm_gc_mark (lexer->pitchname_tab_stack_); scm_gc_mark (lexer->start_module_); + scm_gc_mark (lexer->extra_tokens_); return lexer->scopes_; } -- 2.39.5