This class holds the character classes used by an Engine. More...
#include <elamcharclass.h>
Public Member Functions | |
QString | operatorClass () const |
class of operator characters More... | |
void | setOperatorClass (QString) |
sets the class of operator characters More... | |
QPair< QString, QString > | nameClass () const |
returns the two name sub-classes nameClass().first refers to start characters, nameClass().second refers to all characters that can turn up anywhere in names More... | |
void | setNameClass (QString startchars, QString allchars) |
sets the two sub-classes of names More... | |
void | setNameClass (const QPair< QString, QString > &chars) |
convenience overload: sets the two sub-classes of names More... | |
QString | whitespaceClass () const |
returns all characters that are regarded as whitespace More... | |
void | setWhitespaceClass (QString) |
sets all characters that are regarded as whitespace More... | |
QString | literalStartClass () const |
returns all characters that start a literal, normally digits ' and " More... | |
void | setLiteralStartClass (QString) |
sets characters that can start a literal More... | |
QPair< QChar, QChar > | parenthesesChars () const |
returns the opening (first) and closing (second) character of parentheses More... | |
void | setParentheses (QChar open, QChar close) |
sets the characters used for parentheses More... | |
QPair< QChar, QChar > | assignmentChars () const |
returns the characters that designate an assignment More... | |
void | setAssignmentChars (QChar start, QChar end) |
sets the characters used for assignment operators More... | |
QChar | commaChar () const |
returns the character used as a comma (separator of function arguments) More... | |
void | setCommaChar (QChar) |
sets the character used as comma More... | |
QChar | dotChar () const |
returns the character used as "dot" - separator of struct members More... | |
void | setDotChar (QChar) |
sets the character used as "dot" - separator if struct members More... | |
bool | isConsistent () const |
true if the settings are internally consistent More... | |
Token::Type | charType (QChar ch, Token::Type oldtype) const |
returns the type of token the character belongs to More... | |
bool | isAssignment (QString) const |
returns true if the string contains any assignment operator More... | |
bool | isSimpleAssignment (QString) const |
returns true if the string contains exactly the simple assignment operator More... | |
bool | isName (QString) const |
returns true if the string can be interpreted as name More... | |
bool | isOperator (QString) const |
returns true if the string can be interpreted as operator More... | |
QString | toOperator (QString) const |
removes assignment chars from the token and returns the pure operator or an empty string if it was a pure assignment More... | |
This class holds the character classes used by an Engine.
There are three major classes of chracters:
None of these three classes may overlap. There are several more minor classes:
QPair<QChar,QChar> ELAM::CharacterClassSettings::assignmentChars | ( | ) | const |
returns the characters that designate an assignment
Token::Type ELAM::CharacterClassSettings::charType | ( | QChar | ch, |
Token::Type | oldtype | ||
) | const |
returns the type of token the character belongs to
ch | the character to be checked |
oldtype | the type the previous character belongs to (set to Invalid if this is the first character) |
Compares the character with the known settings for character classes and returns its probable token type. The old type of the previous character is necessary to check for context sensitive rules.
QChar ELAM::CharacterClassSettings::commaChar | ( | ) | const |
returns the character used as a comma (separator of function arguments)
QChar ELAM::CharacterClassSettings::dotChar | ( | ) | const |
returns the character used as "dot" - separator of struct members
bool ELAM::CharacterClassSettings::isAssignment | ( | QString | ) | const |
returns true if the string contains any assignment operator
bool ELAM::CharacterClassSettings::isConsistent | ( | ) | const |
true if the settings are internally consistent
The character class settings are consistent if all constraints of class inclusion and exclusion are fullfilled.
bool ELAM::CharacterClassSettings::isName | ( | QString | ) | const |
returns true if the string can be interpreted as name
bool ELAM::CharacterClassSettings::isOperator | ( | QString | ) | const |
returns true if the string can be interpreted as operator
bool ELAM::CharacterClassSettings::isSimpleAssignment | ( | QString | ) | const |
returns true if the string contains exactly the simple assignment operator
QString ELAM::CharacterClassSettings::literalStartClass | ( | ) | const |
returns all characters that start a literal, normally digits ' and "
QPair<QString,QString> ELAM::CharacterClassSettings::nameClass | ( | ) | const |
returns the two name sub-classes nameClass().first refers to start characters, nameClass().second refers to all characters that can turn up anywhere in names
QString ELAM::CharacterClassSettings::operatorClass | ( | ) | const |
class of operator characters
QPair<QChar,QChar> ELAM::CharacterClassSettings::parenthesesChars | ( | ) | const |
returns the opening (first) and closing (second) character of parentheses
void ELAM::CharacterClassSettings::setAssignmentChars | ( | QChar | start, |
QChar | end | ||
) |
sets the characters used for assignment operators
start | if not '\0' the character that marks the start of an assignment |
end | if not '\0' the character that marks the end of an assignment |
The combination of both characters along (without whitespace) is the direct assignment operator. In automatic assignment operator mode any operator that starts with the start character and ends with end character is regarded as an implicit assignment.
In the default configuration the start character is not set ('\0') and the end character is '=', so "a=1" will assign the value "1" to the variable "a" and "a += 1" is equivalent to "a = a + 1".
You can turn this automatism around by defining a start character only (e.g. start='=' and end='\0'). Then the assignment would still be "a = 1", but the combination of assignment and "+" would become "a =+ 1".
If you define both characters then both must be present in assignments. For example with start=':' and end='=' then assignment becomes "a:=1" and assignment with "+" becomes "a :+= 1".
If set, both characters must be part of the operator class.
If both start and end are '\0' it will be impossible to make assignments
void ELAM::CharacterClassSettings::setCommaChar | ( | QChar | ) |
sets the character used as comma
The character must not be part of any other class.
void ELAM::CharacterClassSettings::setDotChar | ( | QChar | ) |
sets the character used as "dot" - separator if struct members
the character must be part of the name class
void ELAM::CharacterClassSettings::setLiteralStartClass | ( | QString | ) |
sets characters that can start a literal
void ELAM::CharacterClassSettings::setNameClass | ( | QString | startchars, |
QString | allchars | ||
) |
sets the two sub-classes of names
startchars | are characters that can start a name |
allchars | are characters that can turn up anywhere in names, allchars must include all characters from startchars |
|
inline |
convenience overload: sets the two sub-classes of names
chars.first | are characters that can start a name |
chars.second | are characters that can turn up anywhere in names, second must include all characters from first |
void ELAM::CharacterClassSettings::setOperatorClass | ( | QString | ) |
sets the class of operator characters
void ELAM::CharacterClassSettings::setParentheses | ( | QChar | open, |
QChar | close | ||
) |
sets the characters used for parentheses
open | the character that opens/begins a parentheses structure, normally "(" |
close | the character that closes/ends a parentheses structure, normally ")" |
The parentheses characters must not be included in any other class.
void ELAM::CharacterClassSettings::setWhitespaceClass | ( | QString | ) |
sets all characters that are regarded as whitespace
QString ELAM::CharacterClassSettings::toOperator | ( | QString | ) | const |
removes assignment chars from the token and returns the pure operator or an empty string if it was a pure assignment
QString ELAM::CharacterClassSettings::whitespaceClass | ( | ) | const |
returns all characters that are regarded as whitespace