public abstract class AbstractParser extends Object
AbstractParser supports syntactic analysis of a tokens
produced by an AbstractLexer to create a corresponding CST, that
may in turn be exploited by an AbstractAnalyzer to create an
AST.
Derived classes should extend the abstract support for AST from CST from
tokens from text parsing and analysis to support the AST and CST classes
appropriate to a particular language.| Constructor and Description |
|---|
AbstractParser(AbstractLexer lexer) |
AbstractParser(BasicEnvironment environment) |
| Modifier and Type | Method and Description |
|---|---|
String |
computeInputString(int left,
int right)
Returns a single line string representation of the input chars for the
given range.
|
protected char |
decodeEscapeSequence(StringCharacterIterator i)
Decodes an escape sequence in accordance with the Issue 14357
proposals for Concrete Syntaxes.
|
protected int |
decodeHexCharacter(char c)
Return the value of the next character if it is a hexadecimal character.
|
protected int |
decodeOctalCharacter(StringCharacterIterator i)
Return the value of the next character if it is an octal character.
|
protected String |
decodeString(IToken token,
String string)
Returns a string with any escape sequences decoded by
decodeEscapeSequence(java.text.StringCharacterIterator). |
int |
getDefaultRepairCount() |
BasicEnvironment |
getEnvironment() |
abstract DerivedPrsStream |
getIPrsStream() |
protected abstract IToken |
getLeftIToken() |
protected abstract int |
getLeftSpan() |
AbstractLexer |
getLexer() |
abstract ParseTable |
getParseTable() |
protected abstract ErrorToken |
getRhsErrorIToken(int i) |
protected abstract int |
getRhsErrorTokenIndex(int i) |
protected abstract IToken |
getRhsFirstIToken(int i) |
protected abstract int |
getRhsFirstTokenIndex(int i) |
protected abstract IToken |
getRhsIToken(int i) |
protected abstract IToken |
getRhsLastIToken(int i) |
protected abstract int |
getRhsLastTokenIndex(int i) |
protected abstract Object |
getRhsSym(int i) |
protected abstract int |
getRhsTokenIndex(int i) |
protected abstract IToken |
getRightIToken() |
protected abstract int |
getRightSpan() |
abstract int |
numTokenKinds() |
abstract String[] |
orderedTerminalSymbols() |
abstract CSTNode |
parser()
Runs the parser with the current
lex and parse streams |
abstract CSTNode |
parser(Monitor monitor)
Runs the parser with the current
lex and parse streams
using the given Monitor |
abstract CSTNode |
parser(Monitor monitor,
int error_repair_count)
Runs the parser with the current
lex and parse streams
using the given Monitor and error_repair_count (useful for a backtracking parser) |
CSTNode |
parseTokensToCST()
Deprecated.
clients should invoke
parser() |
abstract void |
reset(ILexStream lexStream)
Resets the parser's
lexStream |
void |
resetLexStream(LexStream lexStream)
Deprecated.
To set/reset the lex stream use
reset(ILexStream) |
void |
setDefaultRepairCount(int defaultRepairCount)
Sets the number of repairs to be performed by a parser capable of
performing repairs (the BacktrackingParser) unless overridden on the
specific parser invocation method.
|
void |
setLexStream(AbstractLexer lexer)
Deprecated.
To set/reset the lex stream use
reset(ILexStream) |
protected void |
setOffsets(CSTNode cstNode)
Initializes a concrete-syntax node's start and end offsets from the
current token in the parser stream.
|
protected void |
setOffsets(CSTNode cstNode,
CSTNode start,
CSTNode end)
Sets the start and end offsets of the given
CSTNode to the
start offset of the 2nd given CSTNode and the end offset of
the 3rd given CSTNode |
protected void |
setOffsets(CSTNode cstNode,
CSTNode start,
IToken end)
Sets the start and end offsets of the given
CSTNode to the
start offset of the 2nd given CSTNode and the end offset of
the given IToken |
protected void |
setOffsets(CSTNode cstNode,
IToken startEnd)
Sets the start and end offsets of the given
CSTNode to the
start and end offsets of the given IToken |
protected void |
setOffsets(CSTNode cstNode,
IToken start,
CSTNode end)
Sets the start and end offsets of the given
CSTNode to the
start offset of the given IToken and the end offset of the
2nd given CSTNode |
protected void |
setOffsets(CSTNode cstNode,
IToken start,
IToken end)
Sets the start and end offsets of the given
CSTNode to the
start offset of the 1std given IToken and the end offset of
the 2nd given IToken |
protected abstract void |
setResult(Object object) |
protected String |
unDoubleQuote(IToken token)
Deprecated.
double quotes form no part of the OCL specification
|
protected String |
unquote(String quoted)
Deprecated.
Use unDoubleQuote
|
protected String |
unSingleQuote(IToken token)
Removes any quotes surrounding the string value of a token
using
#unSingleQuote(String,int) and optionally decode any
escape sequences within it using decodeEscapeSequence(java.text.StringCharacterIterator). |
public AbstractParser(BasicEnvironment environment)
public AbstractParser(AbstractLexer lexer)
public String computeInputString(int left, int right)
left - left most char indexright - right most char indexpublic BasicEnvironment getEnvironment()
public int getDefaultRepairCount()
public AbstractLexer getLexer()
@Deprecated public CSTNode parseTokensToCST()
parser()@Deprecated public void resetLexStream(LexStream lexStream)
reset(ILexStream)lexStream - public void setDefaultRepairCount(int defaultRepairCount)
defaultRepairCount - the default repair count@Deprecated public void setLexStream(AbstractLexer lexer)
reset(ILexStream)lexer - protected void setOffsets(CSTNode cstNode, IToken startEnd)
CSTNode to the
start and end offsets of the given ITokencstNode - CSTNode to set offsetsstartEnd - IToken to retrieve offsets fromprotected void setOffsets(CSTNode cstNode, CSTNode start, CSTNode end)
CSTNode to the
start offset of the 2nd given CSTNode and the end offset of
the 3rd given CSTNodecstNode - CSTNode to set offsetsstart - CSTNode to retrieve start offset fromend - CSTNode to retrieve end offset fromprotected void setOffsets(CSTNode cstNode, CSTNode start, IToken end)
CSTNode to the
start offset of the 2nd given CSTNode and the end offset of
the given ITokencstNode - CSTNode to set offsetsstart - CSTNode to retrieve start offset fromend - IToken to retrieve end offset fromprotected void setOffsets(CSTNode cstNode, IToken start, CSTNode end)
CSTNode to the
start offset of the given IToken and the end offset of the
2nd given CSTNodecstNode - CSTNode to set offsetsstart - IToken to retrieve start offset fromend - CSTNode to retrieve end offset fromprotected void setOffsets(CSTNode cstNode, IToken start, IToken end)
CSTNode to the
start offset of the 1std given IToken and the end offset of
the 2nd given ITokencstNode - CSTNode to set offsetsstart - IToken to retrieve start offset fromend - IToken to retrieve end offset fromprotected void setOffsets(CSTNode cstNode)
Initializes a concrete-syntax node's start and end offsets from the current token in the parser stream.
Note: this method resided in the OCLEssential.g template since 1.2 It has been incorporated in the abstract parser since 3.0
cstNode - a concrete-syntax node@Deprecated protected String unquote(String quoted)
quoted - a possibly quoted stringquoted without the surrounding quotes, or just
quoted verbatim if there were none@Deprecated protected String unDoubleQuote(IToken token)
decodeEscapeSequence(java.text.StringCharacterIterator).
For MDT/OCL 1.3.0 compatibility, a problem is reported if double
quotes are present and the #ProblemOption.ELEMENT_NAME_QUOTE_ESCAPE
severity is not #ProblemHandler.Severity.OK.
token - containing string to be decodedtoken with escapes replacedprotected String unSingleQuote(IToken token)
#unSingleQuote(String,int) and optionally decode any
escape sequences within it using decodeEscapeSequence(java.text.StringCharacterIterator).
For MDT/OCL 1.3.0 compatibility, escape sequences conversion can be disabled
by resetting #ParsingOption.USE_BACKSLASH_ESCAPE_PROCESSING.
token - containing string to be decodedtoken with escapes replacedprotected String decodeString(IToken token, String string)
decodeEscapeSequence(java.text.StringCharacterIterator).token - the token from which the string originatedstring - to be decodedstring without any escapes replacedprotected char decodeEscapeSequence(StringCharacterIterator i)
| \b | : backspace BS |
| \t | : horizontal tab HT |
| \n | : line feed LF |
| \f | : form feed FF |
| \r | : carriage return CR |
| \" | ": double quote " |
| \' | ': single quote ' |
| \\ | \: backslash \ |
| \xhh | \u00hh: hex byte |
| \uhhhh | \uhhhh: hex code point |
| \7$ | \u000o: octal byte |
| \77 | \u00ff: octal byte |
| \37$ | \u00ff: octal byte |
| \377 | \u00ff: octal byte |
| h | hex digit (0-9, a-f, A-F) |
| 7 | octal digit (0-7) |
| 3 | octal prefix digit (0-3) |
| $ | end of string or non-octal digit next letter |
i - character iterator pointing at first character after the introducerprotected int decodeHexCharacter(char c)
c - potentially hex characterprotected int decodeOctalCharacter(StringCharacterIterator i)
c - potentially octal characterpublic abstract String[] orderedTerminalSymbols()
public abstract int numTokenKinds()
public abstract DerivedPrsStream getIPrsStream()
parseStreampublic abstract void reset(ILexStream lexStream)
lexStreamlexStream - public abstract CSTNode parser()
lex and parse streamsCSTNode which results from the parsing processpublic abstract CSTNode parser(Monitor monitor)
lex and parse streams
using the given MonitorCSTNode which results from the parsing processpublic abstract CSTNode parser(Monitor monitor, int error_repair_count)
lex and parse streams
using the given Monitor and error_repair_count (useful for a backtracking parser)CSTNode which results from the parsing processpublic abstract ParseTable getParseTable()
ParseTable used by the parserprotected abstract Object getRhsSym(int i)
protected abstract int getRhsTokenIndex(int i)
protected abstract IToken getRhsIToken(int i)
protected abstract int getRhsFirstTokenIndex(int i)
protected abstract IToken getRhsFirstIToken(int i)
protected abstract int getRhsLastTokenIndex(int i)
protected abstract IToken getRhsLastIToken(int i)
protected abstract int getLeftSpan()
protected abstract IToken getLeftIToken()
protected abstract int getRightSpan()
protected abstract IToken getRightIToken()
protected abstract int getRhsErrorTokenIndex(int i)
protected abstract ErrorToken getRhsErrorIToken(int i)
protected abstract void setResult(Object object)
Copyright © 2015 Open eHealth Foundation. All rights reserved.