]> git.donarmstrong.com Git - lilypond.git/commitdiff
add ly:lexer-keywords to make keyword extraction easier and exact.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 14 Dec 2006 13:10:56 +0000 (14:10 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 14 Dec 2006 13:10:56 +0000 (14:10 +0100)
lily/include/lily-lexer.hh
lily/lily-lexer-scheme.cc [new file with mode: 0644]
lily/lily-lexer.cc

index 543178ca257be56136b83d8dbdf8c03c4b69a5c0..994d185f6f36a9b9ff07239e4912443054a44bd4 100644 (file)
@@ -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 (file)
index 0000000..66e47d3
--- /dev/null
@@ -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 <hanwen@lilypond.org>
+  
+*/
+
+#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 ();
+}
+         
index 394e20089b9586676e6e40048d6196e14d76feee..8d70783cb5989da22c5eede795ac94bcf6f72cc3 100644 (file)
@@ -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)
 {