libdrmconf 0.12.1
A library to program DMR radios.
Loading...
Searching...
No Matches
CSVLexer Class Reference

The lexer class divides a text stream into tokens. More...

#include <csvreader.hh>

Inheritance diagram for CSVLexer:
Collaboration diagram for CSVLexer:

Classes

struct  State
 Current state of lexer. More...
 
struct  Token
 The token. More...
 

Public Member Functions

 CSVLexer (QTextStream &stream, QObject *parent=nullptr)
 Constructs a lexer for the given stream.
 
void push ()
 Saves the current lexer state.
 
void pop ()
 Restores the last lexer state.
 
Token next ()
 Reads the next token from the stream.
 
const QString & errorMessage () const
 Returns the last error message.
 

Protected Member Functions

Token lex ()
 Internal used function to get the next token.
 

Protected Attributes

QString _errorMessage
 The error message.
 
QTextStream & _stream
 The text stream to read from.
 
QVector< State_stack
 The stack of saved lexer states.
 
QString _currentLine
 The current line count.
 

Static Protected Attributes

static QVector< QPair< QRegExp, Token::TokenType > > _pattern
 The list of patterns to match.
 

Detailed Description

The lexer class divides a text stream into tokens.

Member Function Documentation

◆ lex()

CSVLexer::Token CSVLexer::lex ( )
protected

Internal used function to get the next token.

Also returns ignored tokens like whitespace and comment.

Member Data Documentation

◆ _pattern

QVector< QPair< QRegExp, CSVLexer::Token::TokenType > > CSVLexer::_pattern
staticprotected
Initial value:
= {
{ QRegExp("^n([0-9]{3})"), CSVLexer::Token::T_DCS_N },
{ QRegExp("^i([0-9]{3})"), CSVLexer::Token::T_DCS_I },
{ QRegExp("^([a-zA-Z0-9]{1,6}-[0-9]{1,2})"), CSVLexer::Token::T_APRSCALL },
{ QRegExp("^([a-zA-Z_][a-zA-Z0-9_]*)"), CSVLexer::Token::T_KEYWORD },
{ QRegExp("^\"([^\"\r\n]*)\""), CSVLexer::Token::T_STRING },
{ QRegExp("^([+-]?[0-9]+(\\.[0-9]*)?)"), CSVLexer::Token::T_NUMBER },
{ QRegExp("^(:)"), CSVLexer::Token::T_COLON },
{ QRegExp("^(-)"), CSVLexer::Token::T_NOT_SET },
{ QRegExp("^(\\+)"), CSVLexer::Token::T_ENABLED },
{ QRegExp("^(,)"), CSVLexer::Token::T_COMMA },
{ QRegExp("^([ \t]+)"), CSVLexer::Token::T_WHITESPACE },
{ QRegExp("^(\r?\n)"), CSVLexer::Token::T_NEWLINE},
{ QRegExp("^(#[^\n\r]*)"), CSVLexer::Token::T_COMMENT},
}
@ T_APRSCALL
A APRS call of form CALL-SSID.
Definition csvreader.hh:33
@ T_STRING
A quoted string.
Definition csvreader.hh:34
@ T_COMMA
A comma.
Definition csvreader.hh:41
@ T_DCS_N
A normal DCS code number.
Definition csvreader.hh:36
@ T_COLON
A colon.
Definition csvreader.hh:38
@ T_NEWLINE
A new line.
Definition csvreader.hh:44
@ T_WHITESPACE
Any whitespace character excluding newline.
Definition csvreader.hh:43
@ T_ENABLED
A plus sign, being used as "enabled".
Definition csvreader.hh:40
@ T_DCS_I
An inverted DCS code number.
Definition csvreader.hh:37
@ T_NOT_SET
A dash, being used as "not-set".
Definition csvreader.hh:39
@ T_COMMENT
A comment starts with # end ends at the line-end.
Definition csvreader.hh:45
@ T_KEYWORD
A Keyword/Identifier.
Definition csvreader.hh:32
@ T_NUMBER
An integer or floating point number.
Definition csvreader.hh:35

The list of patterns to match.


The documentation for this class was generated from the following files: