wex  v20.04.0
Public Member Functions | List of all members
wex::lexer Class Reference

This class defines a lexer using file extensions, syntax colouring and comment definitions. More...

#include <wex/lexer.h>

Inheritance diagram for wex::lexer:
Inheritance graph
[legend]

Public Member Functions

 lexer (const std::string &lexer=std::string())
 Default constructor.
 
 lexer (stc *stc)
 Constructor using stc.
 
 lexer (const pugi::xml_node *node)
 Constructor using xml node.
 
lexeroperator= (const lexer &l)
 Assignment operator. More...
 
bool add_keywords (const std::string &text, int setno=0)
 Adds keywords (public for testing only).
 
bool apply () const
 Applies this lexer to stc component (and colours the component).
 
int attrib (const std::string &name) const
 Returns specified config attrib. More...
 
const auto & attribs () const
 Returns all the attribs.
 
void clear ()
 Clears lexer and applies it to stc if available. More...
 
const std::string comment_complete (const std::string &comment) const
 Returns a string that completes specified comment, by adding spaces and a comment end at the end. More...
 
const auto & comment_begin () const
 Returns the comment begin.
 
const auto & comment_begin2 () const
 Returns the comment begin 2.
 
const auto & comment_end () const
 Returns the comment end.
 
const auto & comment_end2 () const
 Returns the comment end 2.
 
const auto & display_lexer () const
 Returns the display lexer (as shown in dialog).
 
const auto & extensions () const
 Returns the extensions.
 
bool is_keyword (const std::string &word) const
 Is this word a keyword (allways all keywords), case sensitive.
 
bool is_ok () const
 Is this lexer valid.
 
bool keyword_starts_with (const std::string &word) const
 Does any keyword (allways all keywords) start with this word, case insensitive.
 
const auto & keywords () const
 Returns the keywords.
 
const std::string keywords_string (int keyword_set=-1, size_t min_size=0, const std::string &prefix=std::string()) const
 Returns the keywords as one large string,. More...
 
const auto & language () const
 Returns the language.
 
size_t line_size () const
 Returns the line size.
 
std::stringstream log () const
 Logs info about this class.
 
const std::string make_comment (const std::string &text, bool fill_out_with_space=true, bool fill_out=true) const
 Returns a lexer comment string with text formatted.
 
const std::string make_comment (const std::string &prefix, const std::string &text) const
 Returns a lexer comment string with prefix.
 
const std::string make_single_line_comment (const std::string_view &text, bool fill_out_with_space=true, bool fill_out=true) const
 Returns a lexer comment string filled out over one line.
 
bool previewable () const
 Returns true if the stc component associated with this lexer can be previewed.
 
const auto & properties () const
 Returns the properties.
 
const auto & scintilla_lexer () const
 Returns the scintilla lexer.
 
bool set (const std::string &lexer, bool fold=false)
 Sets lexer to specified lexer (finds by name from lexers), Shows error message when lexer could not be set.
 
bool set (const lexer &lexer, bool fold=false)
 Sets lexer to specified lexer, and applies it to stc if present. More...
 
void set_property (const std::string &name, const std::string &value)
 Overrides a local property.
 
const auto & styles () const
 Returns the styles.
 
size_t usable_chars_per_line () const
 Returns number of chars that fit on a line, skipping comment chars.
 

Detailed Description

This class defines a lexer using file extensions, syntax colouring and comment definitions.

This lexer is one of the Scintilla lexers. The lexers are read by and kept in the wex::lexers class.

Member Function Documentation

◆ attrib()

int wex::lexer::attrib ( const std::string &  name) const

Returns specified config attrib.

The value depends on attrib, but is -1 if not present.

◆ clear()

void wex::lexer::clear ( )

Clears lexer and applies it to stc if available.

The is ok member is set to false.

◆ comment_complete()

const std::string wex::lexer::comment_complete ( const std::string &  comment) const

Returns a string that completes specified comment, by adding spaces and a comment end at the end.

If the comment end string is empty, it returns empty string.

◆ keywords_string()

const std::string wex::lexer::keywords_string ( int  keyword_set = -1,
size_t  min_size = 0,
const std::string &  prefix = std::string() 
) const

Returns the keywords as one large string,.

Parameters
keyword_setif keyword_set -1 take all the sets, otherwise take the specified set.
min_sizeif min_size 0, use all keywords, otherwise use keywords with minimim size
prefixprefix keyword should start with

◆ operator=()

lexer& wex::lexer::operator= ( const lexer l)

Assignment operator.

The stc component is assigned only if it is nullptr.

◆ set()

bool wex::lexer::set ( const lexer lexer,
bool  fold = false 
)

Sets lexer to specified lexer, and applies it to stc if present.

Returns true if a scintilla lexer has been set.