libcsdbg  1.28
C++ exception (and generic) stack trace debug library
parser.hpp
Go to the documentation of this file.
1 #ifndef _CSDBG_PARSER
2 #define _CSDBG_PARSER 1
3 
10 #include "./dictionary.hpp"
11 #include "./style.hpp"
12 
13 namespace csdbg {
14 
29 class parser: virtual public string
30 {
31 protected:
32 
33  /* Protected static variables */
34 
35  static parser *m_default;
37  static style *m_fallback;
40  /* Protected variables */
41 
47  /* Protected static methods */
48 
49  static void on_lib_load() __attribute((constructor));
50 
51  static void on_lib_unload() __attribute((destructor));
52 
53 public:
54 
55  /* Friend classes and functions */
56 
57  friend std::ostream& operator<<(std::ostream&, const parser&);
58 
59 
60  /* Constructors, copy constructors and destructor */
61 
62  parser();
63 
64  parser(const parser&);
65 
66  virtual ~parser();
67 
68  virtual parser* clone() const;
69 
70 
71  /* Accessor methods */
72 
73  static parser* get_default();
74 
75  static style* get_fallback_style();
76 
77 
78  /* Operator overloading methods */
79 
80  virtual parser& operator=(const parser&);
81 
82 
83  /* Generic methods */
84 
85  /* Dictionary handling methods */
86 
87  virtual dictionary* add_dictionary(const i8*, const i8*, bool);
88 
89  virtual parser& add_dictionary(dictionary*);
90 
91  virtual parser& remove_dictionary(const i8*);
92 
93  virtual parser& remove_all_dictionaries();
94 
95  virtual dictionary* get_dictionary(const i8*) const;
96 
97  virtual chain<string>* get_dictionary_names() const;
98 
99 
100  /* Style handling methods */
101 
102  virtual style* add_style(const i8*, color_t, color_t, attrset_t);
103 
104  virtual parser& add_style(style*);
105 
106  virtual parser& remove_style(const i8*);
107 
108  virtual parser& remove_all_styles();
109 
110  virtual style* get_style(const i8*) const;
111 
112  virtual chain<string>* get_style_names() const;
113 
114 
115  /* Parse/highlight/lookup methods */
116 
117  virtual chain<string>* parse(const i8* = NULL, bool = false) const;
118 
119  virtual string* highlight(const i8* = NULL, bool = false) const;
120 
121  virtual bool lookup(const string&, const i8*, bool = false) const;
122 
123  virtual const i8* lookup(const string&, bool = false) const;
124 };
125 
126 }
127 
128 #endif
129 
static style * get_fallback_style()
Get the shared fallback style.
Definition: parser.cpp:255
virtual chain< string > * get_style_names() const
Get all the registered style names.
Definition: parser.cpp:537
virtual parser & remove_dictionary(const i8 *)
Remove a dictionary, indexed by name.
Definition: parser.cpp:338
chain< dictionary > * m_dictionaries
Dictionary collection.
Definition: parser.hpp:42
Lightweight, templated, doubly-linked list (using XOR linking)
Definition: chain.hpp:33
A named collection of words (for syntax highlighters)
Definition: dictionary.hpp:32
char i8
8-bit signed integer
Definition: config.hpp:72
static parser * get_default()
Get the default (stack trace) parser.
Definition: parser.cpp:244
virtual chain< string > * get_dictionary_names() const
Get all the registered dictionary names.
Definition: parser.cpp:398
virtual parser * clone() const
Object virtual copy constructor.
Definition: parser.cpp:233
virtual string * highlight(const i8 *=NULL, bool=false) const
Highlight (escape) the current buffer using a custom syntax.
Definition: parser.cpp:593
Class csdbg::style definition.
virtual chain< string > * parse(const i8 *=NULL, bool=false) const
Parse the current buffer using a custom syntax.
Definition: parser.cpp:572
static parser * m_default
Default parser.
Definition: parser.hpp:35
Stack trace parser and syntax highlighter for VT100 terminals.
Definition: parser.hpp:29
virtual parser & remove_style(const i8 *)
Remove a style, indexed by name.
Definition: parser.cpp:477
A set of formatting attributes for VT100 (and compatible) terminals.
Definition: style.hpp:20
u8 color_t
VT100 terminal color.
Definition: config.hpp:162
virtual style * add_style(const i8 *, color_t, color_t, attrset_t)
Add a style to the parser/highlighter.
Definition: parser.cpp:437
Class csdbg::dictionary definition.
static void on_lib_unload() __attribute((destructor))
Library destructor.
Definition: parser.cpp:108
static void on_lib_load() __attribute((constructor))
Library constructor.
Definition: parser.cpp:26
Lightweight string buffer class (for ISO-8859-1 text)
Definition: string.hpp:36
virtual style * get_style(const i8 *) const
Get a style, indexed by name.
Definition: parser.cpp:514
virtual dictionary * add_dictionary(const i8 *, const i8 *, bool)
Add a dictionary to the parser.
Definition: parser.cpp:298
virtual dictionary * get_dictionary(const i8 *) const
Get a dictionary, indexed by name.
Definition: parser.cpp:375
virtual parser & remove_all_styles()
Remove all styles.
Definition: parser.cpp:500
virtual bool lookup(const string &, const i8 *, bool=false) const
Lookup an expression in one of the parser dictionaries.
Definition: parser.cpp:673
u16 attrset_t
VT100 attribute bitmask.
Definition: config.hpp:170
virtual parser & remove_all_dictionaries()
Remove all dictionaries.
Definition: parser.cpp:361
static style * m_fallback
Shared fallback style.
Definition: parser.hpp:37
chain< style > * m_styles
VT100 style collection.
Definition: parser.hpp:44