From 1ae6f5710e714f13da1bfbfbd840835316618d1f Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Thu, 14 Dec 2006 14:10:56 +0100 Subject: [PATCH] add ly:lexer-keywords to make keyword extraction easier and exact. --- lily/include/lily-lexer.hh | 1 + lily/lily-lexer-scheme.cc | 20 ++++++++++++++++++++ lily/lily-lexer.cc | 20 ++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 lily/lily-lexer-scheme.cc diff --git a/lily/include/lily-lexer.hh b/lily/include/lily-lexer.hh index 543178ca25..994d185f6f 100644 --- a/lily/include/lily-lexer.hh +++ b/lily/include/lily-lexer.hh @@ -69,6 +69,7 @@ public: void start_main_input (); + SCM keyword_list () const; SCM lookup_identifier (string s); SCM lookup_identifier_symbol (SCM s); void push_extra_token (int token_type); diff --git a/lily/lily-lexer-scheme.cc b/lily/lily-lexer-scheme.cc new file mode 100644 index 0000000000..66e47d3d6b --- /dev/null +++ b/lily/lily-lexer-scheme.cc @@ -0,0 +1,20 @@ +/* + lily-lexer-scheme.cc -- implement Lily_lexer bindings. + + source file of the GNU LilyPond music typesetter + + (c) 2006 Han-Wen Nienhuys + +*/ + +#include "lily-lexer.hh" + +LY_DEFINE(ly_lexer_keywords, "ly:lexer-keywords", + 1,0,0, (SCM lexer), + "Return a list of (KEY . CODE) pairs, signifying the lilypond reserved words list.") +{ + Lily_lexer * lex = Lily_lexer::unsmob (lexer); + SCM_ASSERT_TYPE(lex, lexer, SCM_ARG1, __FUNCTION__, "lily lexer"); + return lex->keyword_list (); +} + diff --git a/lily/lily-lexer.cc b/lily/lily-lexer.cc index 394e20089b..8d70783cb5 100644 --- a/lily/lily-lexer.cc +++ b/lily/lily-lexer.cc @@ -183,6 +183,26 @@ Lily_lexer::lookup_keyword (string s) return keytable_->lookup (s.c_str ()); } +SCM +Lily_lexer::keyword_list () const +{ + if (!keytable_) + return SCM_EOL; + + SCM l = SCM_EOL; + SCM *tail = &l; + for (vsize i = 0; i < keytable_->table_.size (); i++) + { + *tail = scm_acons (scm_makfrom0str (keytable_->table_[i].name_), + scm_from_int (keytable_->table_[i].tokcode_), + SCM_EOL); + + tail = SCM_CDRLOC(*tail); + } + + return l; +} + SCM Lily_lexer::lookup_identifier_symbol (SCM sym) { -- 2.39.5