org.eclipse.ocl.lpg
Class AbstractParser

java.lang.Object
  extended by org.eclipse.ocl.lpg.AbstractParser
Direct Known Subclasses:
AbstractOCLParser

public abstract class AbstractParser
extends java.lang.Object

The 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 Summary
AbstractParser(AbstractLexer lexer)
           
AbstractParser(BasicEnvironment environment)
           
 
Method Summary
 java.lang.String computeInputString(int left, int right)
          Returns a single line string representation of the input chars for the given range.
protected  char decodeEscapeSequence(java.text.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(java.text.StringCharacterIterator i)
          Return the value of the next character if it is an octal character.
protected  java.lang.String decodeString(IToken token, java.lang.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  java.lang.Object getRhsSym(int i)
           
protected abstract  int getRhsTokenIndex(int i)
           
protected abstract  IToken getRightIToken()
           
protected abstract  int getRightSpan()
           
abstract  int numTokenKinds()
           
abstract  java.lang.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, IToken startEnd)
          Sets the start and end offsets of the given CSTNode to the start and end offsets of the given IToken
protected abstract  void setResult(java.lang.Object object)
           
protected  java.lang.String unDoubleQuote(IToken token)
          Deprecated. double quotes form no part of the OCL specification
protected  java.lang.String unquote(java.lang.String quoted)
          Deprecated. Use unDoubleQuote
protected  java.lang.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).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractParser

public AbstractParser(BasicEnvironment environment)

AbstractParser

public AbstractParser(AbstractLexer lexer)
Method Detail

computeInputString

public java.lang.String computeInputString(int left,
                                           int right)
Returns a single line string representation of the input chars for the given range.

Parameters:
left - left most char index
right - right most char index
Returns:
a single line string representation of the input chars

getEnvironment

public BasicEnvironment getEnvironment()

getDefaultRepairCount

public int getDefaultRepairCount()
Since:
1.3

getLexer

public AbstractLexer getLexer()

parseTokensToCST

@Deprecated
public CSTNode parseTokensToCST()
Deprecated. clients should invoke parser()


resetLexStream

@Deprecated
public void resetLexStream(LexStream lexStream)
Deprecated. To set/reset the lex stream use reset(ILexStream)

Parameters:
lexStream -

setDefaultRepairCount

public 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. When repair count is 0, no Error token recoveries occur. When repair count is > 0, it limits the number of Error token recoveries. When repair count is < 0, the number of error token recoveries is unlimited.

Parameters:
defaultRepairCount - the default repair count
Since:
1.3

setLexStream

@Deprecated
public void setLexStream(AbstractLexer lexer)
Deprecated. To set/reset the lex stream use reset(ILexStream)

Parameters:
lexer -

setOffsets

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

Parameters:
cstNode - CSTNode to set offsets
startEnd - IToken to retrieve offsets from

setOffsets

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

Parameters:
cstNode - CSTNode to set offsets
start - CSTNode to retrieve start offset from
end - CSTNode to retrieve end offset from

setOffsets

protected 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

Parameters:
cstNode - a concrete-syntax node
Since:
3.0

unquote

@Deprecated
protected java.lang.String unquote(java.lang.String quoted)
Deprecated. Use unDoubleQuote

Removes the "s surrounding a quoted string, if any.

Parameters:
quoted - a possibly quoted string
Returns:
quoted without the surrounding quotes, or just quoted verbatim if there were none

unDoubleQuote

@Deprecated
protected java.lang.String unDoubleQuote(IToken token)
Deprecated. double quotes form no part of the OCL specification

Removes any "s surrounding a quoted string and decodes any escape sequences within it using 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.

Parameters:
token - containing string to be decoded
Returns:
string value of token with escapes replaced
Since:
3.0

unSingleQuote

protected java.lang.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).

For MDT/OCL 1.3.0 compatibility, escape sequences conversion can be disabled by resetting #ParsingOption.USE_BACKSLASH_ESCAPE_PROCESSING.

Parameters:
token - containing string to be decoded
Returns:
string value of token with escapes replaced
Since:
3.0

decodeString

protected java.lang.String decodeString(IToken token,
                                        java.lang.String string)
Returns a string with any escape sequences decoded by decodeEscapeSequence(java.text.StringCharacterIterator).

Parameters:
token - the token from which the string originated
string - to be decoded
Returns:
string without any escapes replaced
Since:
3.0

decodeEscapeSequence

protected char decodeEscapeSequence(java.text.StringCharacterIterator i)
Decodes an escape sequence in accordance with the Issue 14357 proposals for Concrete Syntaxes. For compatibility octal escape sequences are also supported.

\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



























Parameters:
i - character iterator pointing at first character after the introducer
Returns:
the decoded character and i updated to point to the first character following the escape sequence, or DONE and i unchanged if the escape sequence is unrecognised
Since:
3.0

decodeHexCharacter

protected int decodeHexCharacter(char c)
Return the value of the next character if it is a hexadecimal character.

Parameters:
c - potentially hex character
Returns:
the hex value or -1 if the next character is not a hex character
Since:
3.0

decodeOctalCharacter

protected int decodeOctalCharacter(java.text.StringCharacterIterator i)
Return the value of the next character if it is an octal character.

Parameters:
c - potentially octal character
Returns:
the hex value or -1 if the next character is not a octal character
Since:
3.0

orderedTerminalSymbols

public abstract java.lang.String[] orderedTerminalSymbols()

numTokenKinds

public abstract int numTokenKinds()
Returns:
the number of different parser tokens
Since:
3.0

getIPrsStream

public abstract DerivedPrsStream getIPrsStream()
Returns:
the parser's parseStream
Since:
3.0

reset

public abstract void reset(ILexStream lexStream)
Resets the parser's lexStream

Parameters:
lexStream -
Since:
3.0

parser

public abstract CSTNode parser()
Runs the parser with the current lex and parse streams

Returns:
the root CSTNode which results from the parsing process
Since:
3.0

parser

public abstract CSTNode parser(Monitor monitor)
Runs the parser with the current lex and parse streams using the given Monitor

Returns:
the root CSTNode which results from the parsing process
Since:
3.0

parser

public 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)

Returns:
the root CSTNode which results from the parsing process
Since:
3.0

getParseTable

public abstract ParseTable getParseTable()
Returns:
the ParseTable used by the parser
Since:
3.0

getRhsSym

protected abstract java.lang.Object getRhsSym(int i)
Since:
3.0

getRhsTokenIndex

protected abstract int getRhsTokenIndex(int i)
Since:
3.0

getRhsIToken

protected abstract IToken getRhsIToken(int i)
Since:
3.0

getRhsFirstTokenIndex

protected abstract int getRhsFirstTokenIndex(int i)
Since:
3.0

getRhsFirstIToken

protected abstract IToken getRhsFirstIToken(int i)
Since:
3.0

getRhsLastTokenIndex

protected abstract int getRhsLastTokenIndex(int i)
Since:
3.0

getRhsLastIToken

protected abstract IToken getRhsLastIToken(int i)
Since:
3.0

getLeftSpan

protected abstract int getLeftSpan()
Since:
3.0

getLeftIToken

protected abstract IToken getLeftIToken()
Since:
3.0

getRightSpan

protected abstract int getRightSpan()
Since:
3.0

getRightIToken

protected abstract IToken getRightIToken()
Since:
3.0

getRhsErrorTokenIndex

protected abstract int getRhsErrorTokenIndex(int i)
Since:
3.0

getRhsErrorIToken

protected abstract ErrorToken getRhsErrorIToken(int i)
Since:
3.0

setResult

protected abstract void setResult(java.lang.Object object)
Since:
3.0

Copyright 2002, 2007 IBM Corporation and others.
All Rights Reserved.