public abstract class Language extends java.lang.Object implements GenericTokens
Language
interface provides methods for providing
basic details of a language, such as the keywords, the comment
delimiters, and the quote delimiters of a language. This is
intended to provide clients with the ability to obtain a simple
lexer implementation for a language without a lot of
language-specific implementation details.
Clients that require more language-specific features or details
will need to implement their own custom Lexer
to
accommodate the unique features of a given language.
The GenericLexer
implementation is a concrete
Lexer
that was written for this Language
API, can be used to instantiate a Lexer
for a given
Language
implementation.
Modifier and Type | Field and Description |
---|---|
protected BraceHelper |
braceHelper |
static java.lang.String[] |
EMPTY_ARRAY
Empty String array, useful when a language feature is not available.
|
protected KeywordTable |
keywordTable
Stores a keyword table, containing all of the keywords of this
language.
|
TK_CLOSE_BRACE, TK_FLOAT, TK_IDENTIFIER, TK_INTEGER, TK_KEYWORD, TK_MULTI_COMMENT, TK_OPEN_BRACE, TK_OPERATOR, TK_QUOTES, TK_SINGLE_COMMENT
Modifier | Constructor and Description |
---|---|
protected |
Language()
Initializes the base
Language abstract
implementation. |
Modifier and Type | Method and Description |
---|---|
BraceHelper |
getBraceHelper()
Fetches a brace helper for this language that has useful routines
for a brace matching implementation.
|
abstract java.lang.String[][] |
getBraces()
Fetches an array of String arrays, each of which represent a pair
of matched braces.
|
abstract java.lang.String[] |
getHexadecimals()
Fetches an array of prefix used to start a hexadecimal integer
literal if the language supports integer literals.
|
abstract java.lang.String[] |
getKeywords()
Fetches an array of the keywords in this language.
|
protected KeywordTable |
getKeywordTable()
Returns a
KeywordTable for this language, based on
the keywords supported, and whether the language is
case-sensitive or not. |
abstract java.lang.String[][] |
getMultiLineComments()
Fetches an array of String arrays, each of which represents a
multi-line comment.
|
abstract java.lang.String[] |
getOctals()
Fetches an array of prefixes used to start an octal integer
literal if the language supports integer literals.
|
java.lang.String[] |
getOperators()
Fetches an array of Strings, each of which represent an operator
in the given language.
|
abstract java.lang.String[][] |
getQuotes()
Fetches an array of String arrays, each of which represents a
type of quote.
|
abstract java.lang.String[] |
getSingleLineComments()
Fetches an array of Strings, each of which can be used to start a
single-lined comment in this language.
|
abstract boolean |
isCaseSensitive()
Fetches whether this language (i.e., keywords) is case sensitive
or not.
|
abstract boolean |
isIdentifierCharacter(char c)
Fetches whether the specified character can be part of an
identifier (or keyword.) Consecutive sequence of characters, all
of which return true for isIdentifierCharacter(), that do not
match a keyword will generate a
TK_IDENTIFIER token
by the GenericLexer (assuming if course that those
characters are not contained in a comment or string literal.) |
abstract boolean |
usesFloats()
Fetches whether this language has floating point literals.
|
abstract boolean |
usesIntegers()
Fetches whether the language has integer literals.
|
protected KeywordTable keywordTable
protected BraceHelper braceHelper
public static final java.lang.String[] EMPTY_ARRAY
protected Language()
Language
abstract
implementation.public abstract boolean isCaseSensitive()
public abstract boolean isIdentifierCharacter(char c)
TK_IDENTIFIER
token
by the GenericLexer
(assuming if course that those
characters are not contained in a comment or string literal.)c
- the character to checkpublic abstract java.lang.String[] getKeywords()
protected KeywordTable getKeywordTable()
KeywordTable
for this language, based on
the keywords supported, and whether the language is
case-sensitive or not.KeywordTable
for this languagepublic abstract java.lang.String[] getSingleLineComments()
public abstract java.lang.String[][] getMultiLineComments()
public abstract java.lang.String[][] getQuotes()
public abstract java.lang.String[][] getBraces()
public java.lang.String[] getOperators()
public abstract boolean usesIntegers()
public abstract boolean usesFloats()
public abstract java.lang.String[] getOctals()
public abstract java.lang.String[] getHexadecimals()
public BraceHelper getBraceHelper()