1 #include "../include/parser.hpp"
2 #include "../include/util.hpp"
89 util::dbg_info(
"default C++ stack trace parser/highlighter initialized");
97 catch (std::exception &x) {
115 util::dbg_info(
"default C++ stack trace parser/highlighter finalized");
143 catch (std::exception &x) {
160 m_dictionaries(NULL),
177 m_dictionaries = NULL;
192 m_dictionaries(NULL),
209 m_dictionaries = NULL;
439 style *retval = NULL;
441 retval =
new style(nm, fg, bg, set);
574 if (
likely(syntax == NULL) )
577 return split(syntax,
false, icase);
595 const i8 *num =
"^0x[0-9a-f]+$|^[0-9]+$";
597 string *retval =
new string;
603 tokens =
parse(syntax, icase);
607 string *token = tokens->
at(i);
628 else if (
likely(i < sz - 1) ) {
629 string *delim = tokens->
at(i + 1);
630 i8 ch = delim->
at(0);
635 else if (
unlikely(ch ==
'(' || ch ==
'<' || ch ==
'\r') )
679 return dict->
lookup(exp, icase) != NULL;
static style * get_fallback_style()
Get the shared fallback style.
#define HLT_NUMBER_FG
Highlighter color for numbers (any base)
#define HLT_KEYWORD_FG
Highlighter color for C++ keywords.
virtual style & set_attr_enabled(attrset_t, bool)
Enable/disable a set of text formatting attributes.
virtual string & append(const string &)
Append a string.
virtual chain< string > * get_style_names() const
Get all the registered style names.
virtual parser & remove_dictionary(const i8 *)
Remove a dictionary, indexed by name.
chain< dictionary > * m_dictionaries
Dictionary collection.
virtual style * clone() const
Object virtual copy constructor.
virtual string & set(const i8 *,...)
Fill with a printf-style format C-string expanded with the values of a variable argument list...
virtual T * at(u32) const
Get the node data pointer at a chain offset.
static const i8 g_trace_syntax[]
C++ stack trace syntax.
virtual style & set_fgcolor(color_t)
Set the foreground color.
#define HLT_FILE_FG
Highlighter color for C++ files.
virtual u32 size() const
Get the chain size (node count)
Lightweight, templated, doubly-linked list (using XOR linking)
A named collection of words (for syntax highlighters)
char i8
8-bit signed integer
std::ostream & operator<<(std::ostream &, const std::exception &)
Stream insertion operator for std::exception objects.
static parser * get_default()
Get the default (stack trace) parser.
virtual chain< string > * get_dictionary_names() const
Get all the registered dictionary names.
virtual parser * clone() const
Object virtual copy constructor.
virtual string * highlight(const i8 *=NULL, bool=false) const
Highlight (escape) the current buffer using a custom syntax.
virtual chain< string > * parse(const i8 *=NULL, bool=false) const
Parse the current buffer using a custom syntax.
static parser * m_default
Default parser.
Stack trace parser and syntax highlighter for VT100 terminals.
virtual parser & remove_style(const i8 *)
Remove a style, indexed by name.
virtual string & operator=(const string &)
Assignment operator.
virtual style & apply(string &) const
Apply the style to some text.
A set of formatting attributes for VT100 (and compatible) terminals.
#define HLT_TYPE_FG
Highlighter color for C++ intrinsic types.
virtual const i8 * name() const
Get the style name.
string(u32=0)
Object constructor.
u8 color_t
VT100 terminal color.
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
virtual style & set_name(const i8 *)
Set the style name.
virtual ~parser()
Object destructor.
virtual style * add_style(const i8 *, color_t, color_t, attrset_t)
Add a style to the parser/highlighter.
static const i8 * prefix()
Get the library installation prefix.
#define HLT_SCOPE_FG
Highlighter color for C++ ABI scopes.
virtual const i8 * name() const
Get the dictionary name.
static void lock()
Lock the global access mutex.
static void unlock()
Unlock the global access mutex.
virtual parser & operator=(const parser &)
Assignment operator.
#define HLT_FUNCTION_FG
Highlighter color for C++ function names.
virtual i32 cmp(const string &, bool=false) const
Compare to another string.
virtual i8 & at(u32)
Get/set the character at an offset.
virtual const i8 * cstr() const
Get the C-string equivalent.
virtual chain & add(T *)
Add a node to the chain.
static void on_lib_unload() __attribute((destructor))
Library destructor.
static void on_lib_load() __attribute((constructor))
Library constructor.
Lightweight string buffer class (for ISO-8859-1 text)
virtual bool match(const string &, bool=false) const
Match against a POSIX extended regular expression.
virtual style * get_style(const i8 *) const
Get a style, indexed by name.
virtual dictionary * add_dictionary(const i8 *, const i8 *, bool)
Add a dictionary to the parser.
virtual dictionary * get_dictionary(const i8 *) const
Get a dictionary, indexed by name.
unsigned int u32
32-bit unsigned integer
parser()
Object default constructor.
virtual parser & remove_all_styles()
Remove all styles.
virtual bool lookup(const string &, const i8 *, bool=false) const
Lookup an expression in one of the parser dictionaries.
u16 attrset_t
VT100 attribute bitmask.
virtual parser & remove_all_dictionaries()
Remove all dictionaries.
This class is a throwable with a textual description of an error.
virtual chain< string > * split(const string &, bool=true, bool=false) const
Tokenize using a POSIX extended regular expression.
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
static void dbg_info(const i8 *,...)
Print an informational debug message on the standard error stream.
virtual const string * lookup(const string &, bool=false) const
Dictionary lookup.
static style * m_fallback
Shared fallback style.
#define __D_ASSERT(x)
Assertion macro.
chain< style > * m_styles
VT100 style collection.