Lexer (module)
- Added `LS` alias - Added `isOperator(char c)`, `isSplitter(char c)`, `isNumericalEncoder_Size(char character)`, `isNumericalEncoder_Signage(char character)` and `isValidEscape_String(char character)`
This commit is contained in:
parent
e3f6b9b9e1
commit
2049dc6d08
|
@ -4,6 +4,7 @@
|
|||
module tlang.compiler.lexer.core.lexer;
|
||||
|
||||
import tlang.compiler.lexer.core.tokens : Token;
|
||||
import std.ascii : isDigit, isAlpha, isWhite;
|
||||
|
||||
/**
|
||||
* Defines the interface a lexer must provide
|
||||
|
@ -125,4 +126,82 @@ public enum LexerSymbols : char
|
|||
ENC_WORD = 'W' ,
|
||||
ENC_UNSIGNED = 'U' ,
|
||||
ENC_SIGNED = 'S' ,
|
||||
}
|
||||
|
||||
private alias LS = LexerSymbols;
|
||||
|
||||
/**
|
||||
* Checks if the provided character is an operator
|
||||
*
|
||||
* Params:
|
||||
* c = the character to check
|
||||
* Returns: `true` if it is a character, `false`
|
||||
* otherwise
|
||||
*/
|
||||
public bool isOperator(char c)
|
||||
{
|
||||
return c == LS.PLUS || c == LS.TILDE || c == LS.MINUS ||
|
||||
c == LS.STAR || c == LS.FORWARD_SLASH || c == LS.AMPERSAND ||
|
||||
c == LS.CARET || c == LS.EXCLAMATION || c == LS.SHEFFER_STROKE ||
|
||||
c == LS.LESS_THAN || c == LS.BIGGER_THAN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the provided character is a splitter
|
||||
*
|
||||
* Params:
|
||||
* c = the character to check
|
||||
* Returns: `true` if it is a splitter, `false`
|
||||
* otherwise
|
||||
*/
|
||||
public bool isSplitter(char c)
|
||||
{
|
||||
return c == LS.SEMI_COLON || c == LS.COMMA || c == LS.L_PAREN ||
|
||||
c == LS.R_PAREN || c == LS.L_BRACK || c == LS.R_BRACK ||
|
||||
c == LS.PERCENT || c == LS.L_BRACE || c == LS.R_BRACE ||
|
||||
c == LS.EQUALS || c == LS.DOT || c == LS.COLON ||
|
||||
isOperator(c) || isWhite(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the provided character is a
|
||||
* numerical size encoder
|
||||
*
|
||||
* Params:
|
||||
* character = the character to check
|
||||
* Returns: `true` if so, `false` otheriwse
|
||||
*/
|
||||
public bool isNumericalEncoder_Size(char character)
|
||||
{
|
||||
return character == LS.ENC_BYTE || character == LS.ENC_WORD ||
|
||||
character == LS.ENC_INT || character == LS.ENC_LONG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the provided character is a
|
||||
* numerical signage encoder
|
||||
*
|
||||
* Params:
|
||||
* character = the character to check
|
||||
* Returns: `true` if so, `false` otherwise
|
||||
*/
|
||||
public bool isNumericalEncoder_Signage(char character)
|
||||
{
|
||||
return character == LS.ENC_SIGNED || character == LS.ENC_UNSIGNED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given character is a valid
|
||||
* escape character (something which would
|
||||
* have followed a `\`)
|
||||
*
|
||||
* Params:
|
||||
* character = the character to check
|
||||
* Returns: `true` if so, `false` otherwise
|
||||
*/
|
||||
public bool isValidEscape_String(char character)
|
||||
{
|
||||
return character == LS.BACKSLASH || character == LS.DOUBLE_QUOTE || character == LS.SINGLE_QUOTE ||
|
||||
character == LS.ESC_NOTHING || character == LS.ESC_NEWLINE || character == LS.ESC_CARRIAGE_RETURN ||
|
||||
character == LS.TAB || character == LS.ESC_BELL;
|
||||
}
|
Loading…
Reference in New Issue