public class Parser extends AbstractParser
Expression
which
can be interpreted using Interpreter
.
Each expression is parsed in context of NamespaceModel
which provides variables,
functions, etc.Modifier and Type | Field and Description |
---|---|
static String |
DEBUG
A debug expression keyword.
|
static String |
DEBUG_ELEMENT_ID
A debug expression element id attribute key.
|
static String |
DEBUG_PROPERTY
A debug expression property attribute key.
|
Constructor and Description |
---|
Parser()
Creates a new parser.
|
Parser(NamespaceModel namespace)
Creates a new parser.
|
Parser(NamespaceModel namespace,
Collection<String> freeTypes)
Creates a new parser with a collection of free type names that can be used in the expression.
|
Parser(NamespaceModel namespace,
Collection<String> freeTypes,
FreeTypeMapping freeTypeMapping)
Creates a new parser with a collection of free type names that can be used in the expression.
|
Modifier and Type | Method and Description |
---|---|
void |
addVariableListener(ParserVariableListener listener)
Adds a variable listener.
|
protected void |
checkNamespace() |
static String |
createDateLiteral(Date date)
Creates a date literal.
|
protected TypeParser |
createTypeParser() |
protected int |
debugLine(org.antlr.runtime.tree.Tree tree) |
protected ValidationException |
error(String message,
org.antlr.runtime.tree.Tree tree) |
protected Visibility |
getAccessiblePropertyVisibility(Expression primaryExpression,
RecordType declarationType) |
protected Set<String> |
getFreeTypes() |
protected com.whitestein.lsps.lang.parser.ParserVariableFactory |
getVariableFactory() |
protected String |
intern(String str) |
protected boolean |
isPropertyReadonly(PropertyExpression pe) |
Expression |
parse(AntlrExpressionTree expressionTree,
Type expectedType)
Parses an expression from a pre-parsed antlr tree for the given expected type.
|
Expression |
parse(String source,
Type expectedType)
Parses an expression from a string source for the given expected type.
|
static Date |
parseDateLiteral(String text)
Parses a given date literal.
|
ParsedExpression |
parseLax(AntlrExpressionTree expressionTree,
Type expectedType)
Parses an expression from a pre-parsed antlr tree for the given expected type.
|
protected ParsedExpression |
parseNoCheck(org.antlr.runtime.tree.Tree tree,
Type expectedType)
Parse expression.
|
protected Type |
parseType(org.antlr.runtime.tree.Tree tree) |
void |
removeVariableListener(ParserVariableListener listener)
Removes a variable listener.
|
void |
setDebugLineOffset(int debugLineOffset)
Sets the debug line offset that will be applied to parsed
expressions.
|
protected void |
setFreeTypes(Set<String> freeTypes) |
void |
setIntern(boolean intern)
Sets the intern flag.
|
protected Errors |
validateControlExpressions(Expression expression) |
protected ParsedExpression |
validateOrConvert(ParsedExpression expr,
Type expectedType)
Provides some validation and conversion
|
checkTreeType, createConstant, createConstant, getAstInfo, getNamespace, parse, parseInNamespace, parseInNewNamespace, parseInNewNamespace
begin, end, getASTNode, getFullText, getText, line, parseIdentifierAst, parseQIDAst, setFullText
public static final String DEBUG
public static final String DEBUG_ELEMENT_ID
public static final String DEBUG_PROPERTY
public Parser()
public Parser(NamespaceModel namespace)
namespace
- public Parser(NamespaceModel namespace, Collection<String> freeTypes)
namespace
- freeTypes
- public Parser(NamespaceModel namespace, Collection<String> freeTypes, FreeTypeMapping freeTypeMapping)
namespace
- freeTypes
- freeTypeMapping
- public void setIntern(boolean intern)
true
,
the parser interns some strings, e.g. record field names,
local variable names etc.intern
- protected TypeParser createTypeParser()
public void addVariableListener(ParserVariableListener listener)
listener
- public void removeVariableListener(ParserVariableListener listener)
listener
- protected com.whitestein.lsps.lang.parser.ParserVariableFactory getVariableFactory()
protected ValidationException error(String message, org.antlr.runtime.tree.Tree tree)
public Expression parse(String source, Type expectedType) throws ValidationException
Returns null
if the source string is null or empty or contains
only whitespaces or comments.
source
- expectedType
- NullPointerException
- if expectedType
is nullValidationException
- if the source
is not a valid expression or it is not of the
expectedType
public Expression parse(AntlrExpressionTree expressionTree, Type expectedType) throws ValidationException
Returns null
if the source string is null or empty or contains
only whitespaces or comments.
expressionTree
- expectedType
- NullPointerException
- if expectedType
is nullValidationException
- if the source
is not a valid expression or it is not of the
expectedType
public ParsedExpression parseLax(AntlrExpressionTree expressionTree, Type expectedType)
Returns null
if the source string is null or empty or contains
only whitespaces or comments.
expressionTree
- expectedType
- NullPointerException
- if expectedType
is nullprotected final void checkNamespace()
protected Type parseType(org.antlr.runtime.tree.Tree tree) throws ValidationException
ValidationException
protected ParsedExpression parseNoCheck(org.antlr.runtime.tree.Tree tree, Type expectedType)
AbstractParser
parseNoCheck
in class AbstractParser
public void setDebugLineOffset(int debugLineOffset)
debugLineOffset
- protected int debugLine(org.antlr.runtime.tree.Tree tree)
debugLine
in class AbstractParser
protected Visibility getAccessiblePropertyVisibility(Expression primaryExpression, RecordType declarationType)
protected ParsedExpression validateOrConvert(ParsedExpression expr, Type expectedType)
AbstractParser
validateOrConvert
in class AbstractParser
protected boolean isPropertyReadonly(PropertyExpression pe)
public static Date parseDateLiteral(String text) throws ValidationException
text
- ValidationException
public static String createDateLiteral(Date date)
date
- protected Errors validateControlExpressions(Expression expression)
Copyright © 2007-2020 Whitestein Technologies. All Rights Reserved.