]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/lily-lexer.hh
Issue 5145/1: Lexer: factor out push_markup_predicates
[lilypond.git] / lily / include / lily-lexer.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef MY_LILY_LEXER_HH
21 #define MY_LILY_LEXER_HH
22
23 #include "includable-lexer.hh"
24
25 #include "input.hh"
26 #include "duration.hh"
27 #include "pitch.hh"
28 #include "parser.hh"
29
30 bool busy_parsing ();
31 void kill_lexer ();
32 void set_lexer ();
33
34 class Lily_lexer : public Smob<Lily_lexer>, public Includable_lexer
35 {
36 public:
37   int print_smob (SCM, scm_print_state *) const;
38   SCM mark_smob () const;
39   static const char * const type_p_name_;
40   virtual ~Lily_lexer ();
41   int scan_word (SCM & output, SCM sym);
42 private:
43   int lookup_keyword (const string&);
44   int scan_bare_word (const string&);
45   int scan_escaped_word (const string&);
46   int scan_shorthand (const string&);
47   int scan_scm_id (SCM);
48   int identifier_type (SCM);
49   void push_markup_predicates (SCM sig);
50   char escaped_char (char) const;
51   const char *YYText_utf8 ();
52
53   Lily_parser *parser_;
54   Keyword_table *keytable_;
55   SCM scopes_;
56   SCM start_module_;
57   Input override_input_;
58   SCM eval_scm (SCM, Input, char extra_token = 0);
59 public:
60   SCM eval_scm_token (SCM sval, Input w)
61   {
62     w.step_forward ();
63     return eval_scm (sval, w, '#');
64   }
65   SCM extra_tokens_;
66   SCM *lexval_;
67   Input *lexloc_;
68   bool is_main_input_;
69   vsize main_input_level_;
70
71   Sources *sources_;
72
73   /* Scheme hash tables with (oct name acc)  values, and symbol keys.  */
74   SCM chordmodifier_tab_;
75   SCM pitchname_tab_stack_;
76
77   int error_level_;
78   Input last_input_;
79
80   Lily_lexer (Sources *, Lily_parser *);
81   Lily_lexer (Lily_lexer const &, Lily_parser *, SCM);
82   int yylex ();
83
84   void add_lexed_char (int);
85
86   void prepare_for_next_token ();
87   int try_special_identifiers (SCM *, SCM);
88   Input here_input () const;
89   Input const &override_input (Input const &) const;
90
91   void add_scope (SCM);
92   SCM set_current_scope ();
93   bool has_scope () const;
94   SCM remove_scope ();
95
96   void start_main_input ();
97
98   virtual void new_input (const string &s, Sources *);
99   virtual void new_input (const string &s, string d, Sources *);
100
101   bool top_input () { return include_stack_.size () < 2; }
102   SCM keyword_list () const;
103   SCM lookup_identifier (const string &s);
104   SCM lookup_identifier_symbol (SCM s);
105   void push_extra_token (Input const &where,
106                          int token_type, SCM scm = SCM_UNSPECIFIED);
107   int pop_extra_token ();
108   void push_chord_state (SCM alist);
109   void push_figuredbass_state ();
110   void push_lyric_state ();
111   void push_initial_state ();
112   void push_markup_state ();
113   void push_note_state (SCM alist);
114   void pop_state ();
115   void LexerError (char const *);
116   void LexerWarning (char const *);
117   void set_identifier (SCM path, SCM val);
118   int get_state () const;
119   bool is_note_state () const;
120   bool is_chord_state () const;
121   bool is_lyric_state () const;
122   bool is_figure_state () const;
123   bool is_clean () const;
124 };
125
126 #endif /* MY_LILY_LEXER_HH */