use of org.eclipse.titan.designer.parsers.asn1parser.Asn1Parser in project titan.EclipsePlug-ins by eclipse.
the class SpecialASN1Module method parseSpecialInternalAssignment.
/**
* Parses the special internal assignments to build their semantic
* representation.
*
* @param inputCode
* the code to parse.
* @param identifier
* the identifier for the assignment to be created.
*
* @return the parsed assignment.
*/
public static ASN1Assignment parseSpecialInternalAssignment(final String inputCode, final Identifier identifier) {
ASN1Assignment assignment = null;
final StringReader reader = new StringReader(inputCode);
final CharStream charStream = new UnbufferedCharStream(reader);
final Asn1Lexer lexer = new Asn1Lexer(charStream);
lexer.setTokenFactory(new TokenWithIndexAndSubTokensFactory(true));
final ASN1Listener lexerListener = new ASN1Listener();
// remove ConsoleErrorListener
lexer.removeErrorListeners();
lexer.addErrorListener(lexerListener);
final ModuleLevelTokenStreamTracker tracker = new ModuleLevelTokenStreamTracker(lexer);
tracker.discard(Asn1Lexer.WS);
tracker.discard(Asn1Lexer.MULTILINECOMMENT);
tracker.discard(Asn1Lexer.SINGLELINECOMMENT);
final Asn1Parser parser = new Asn1Parser(tracker);
parser.setBuildParseTree(false);
final ASN1Listener parserListener = new ASN1Listener(parser);
// remove ConsoleErrorListener
parser.removeErrorListeners();
parser.addErrorListener(parserListener);
assignment = parser.pr_TITAN_special_Assignment(identifier).assignment;
if (!parser.getErrorStorage().isEmpty()) {
ErrorReporter.INTERNAL_ERROR(PARSINGFAILED);
for (SyntacticErrorStorage temp : parser.getErrorStorage()) {
ErrorReporter.logError(temp.message);
}
}
return assignment;
}
use of org.eclipse.titan.designer.parsers.asn1parser.Asn1Parser in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Enumerated_Type method parseBlockEnumeration.
private void parseBlockEnumeration() {
if (null == mBlock) {
return;
}
final Asn1Parser parser = BlockLevelTokenStreamTracker.getASN1ParserForBlock(mBlock);
if (null == parser) {
return;
}
enumerations = parser.pr_special_Enumerations().enumeration;
final List<SyntacticErrorStorage> errors = parser.getErrorStorage();
if (null != errors && !errors.isEmpty()) {
isErroneous = true;
enumerations = null;
for (int i = 0; i < errors.size(); i++) {
ParserMarkerSupport.createOnTheFlyMixedMarker((IFile) mBlock.getLocation().getFile(), errors.get(i), IMarker.SEVERITY_ERROR);
}
}
if (enumerations != null) {
if (enumerations.enumItems1 != null) {
enumerations.enumItems1.setFullNameParent(this);
enumerations.enumItems1.setMyScope(getMyScope());
}
if (enumerations.enumItems2 != null) {
enumerations.enumItems2.setFullNameParent(this);
enumerations.enumItems2.setMyScope(getMyScope());
}
}
}
use of org.eclipse.titan.designer.parsers.asn1parser.Asn1Parser in project titan.EclipsePlug-ins by eclipse.
the class TableConstraint method parseBlocks.
private void parseBlocks() {
if (mObjectSetBlock == null) {
return;
}
objectSet = null;
atNotationList = null;
if (null != mObjectSetBlock) {
if (mAtNotationsBlock == null) {
// SimpleTableConstraint
Asn1Parser parser = BlockLevelTokenStreamTracker.getASN1ParserForBlock(mObjectSetBlock, 0);
if (parser != null) {
objectSet = parser.pr_special_ObjectSetSpec().definition;
List<SyntacticErrorStorage> errors = parser.getErrorStorage();
if (null != errors && !errors.isEmpty()) {
objectSet = null;
for (int i = 0; i < errors.size(); i++) {
ParserMarkerSupport.createOnTheFlyMixedMarker((IFile) mObjectSetBlock.getLocation().getFile(), errors.get(i), IMarker.SEVERITY_ERROR);
}
}
}
} else {
// ComponentRelationConstraint
Asn1Parser parser = BlockLevelTokenStreamTracker.getASN1ParserForBlock(mObjectSetBlock, 0);
if (parser != null) {
objectSet = parser.pr_DefinedObjectSetBlock().objectSet;
List<SyntacticErrorStorage> errors = parser.getErrorStorage();
if (null != errors && !errors.isEmpty()) {
objectSet = null;
for (int i = 0; i < errors.size(); i++) {
ParserMarkerSupport.createOnTheFlySyntacticMarker((IFile) mObjectSetBlock.getLocation().getFile(), errors.get(i), IMarker.SEVERITY_ERROR);
}
}
}
parser = BlockLevelTokenStreamTracker.getASN1ParserForBlock(mAtNotationsBlock, 0);
if (parser != null) {
atNotationList = parser.pr_AtNotationList().notationList;
List<SyntacticErrorStorage> errors = parser.getErrorStorage();
if (null != errors && !errors.isEmpty()) {
objectSet = null;
for (int i = 0; i < errors.size(); i++) {
ParserMarkerSupport.createOnTheFlySyntacticMarker((IFile) mAtNotationsBlock.getLocation().getFile(), errors.get(i), IMarker.SEVERITY_ERROR);
}
}
}
if (atNotationList == null) {
atNotationList = new AtNotations();
}
}
}
if (objectSet == null) {
objectSet = new ObjectSet_definition();
}
}
use of org.eclipse.titan.designer.parsers.asn1parser.Asn1Parser in project titan.EclipsePlug-ins by eclipse.
the class Parameterised_Reference method addAssignments.
/**
* Fill the assignments according to the formal parameters
* @param aAssPard (in) formal parameters for the conversion
* @param aCompilationTimeStamp compilation timestamp
*/
private void addAssignments(final Ass_pard aAssPard, final CompilationTimeStamp aCompilationTimeStamp) {
final List<FormalParameter_Helper> formalParameters = aAssPard.getFormalParameters(aCompilationTimeStamp);
final int nofFormalParameters = formalParameters.size();
if (null != mBlock) {
final List<List<Token>> actualParameters = new ArrayList<List<Token>>();
List<Token> temporalBuffer = new ArrayList<Token>();
// TODO: implement according to the C++ code:
// See AST_asn1.cc/void Ass_pard::preparse_pars()
// The java version handles only the list of references.
// The tokens containing assignments are not handled properly
/* splitting the list of actual parameters */
final List<Token> unprocessParameters = mBlock.getTokenList();
for (int i = 0; i < unprocessParameters.size(); i++) {
final Token tempToken = unprocessParameters.get(i);
if (tempToken.getType() == Asn1Lexer.COMMA) {
temporalBuffer.add(new TokenWithIndexAndSubTokens(Token.EOF));
actualParameters.add(temporalBuffer);
temporalBuffer = new ArrayList<Token>();
} else {
temporalBuffer.add(tempToken);
}
}
if (!temporalBuffer.isEmpty()) {
temporalBuffer.add(new TokenWithIndexAndSubTokens(Token.EOF));
actualParameters.add(temporalBuffer);
}
/* checking the number of parameters */
final int nofActualParameters = actualParameters.size();
if (nofActualParameters != nofFormalParameters) {
location.reportSemanticError(MessageFormat.format(DIFFERENTPARAMETERNUMBERS, (nofActualParameters < nofFormalParameters) ? "few" : "many", nofFormalParameters, nofActualParameters));
}
assignments = new ASN1Assignments();
for (int i = 0; i < nofFormalParameters; i++) {
final Identifier tempIdentifier = formalParameters.get(i).identifier;
ASN1Assignment temporalAssignment = null;
if (i < nofActualParameters) {
final List<Token> temporalTokenBuffer = new ArrayList<Token>();
temporalTokenBuffer.add(formalParameters.get(i).formalParameterToken);
final Token temporalToken = formalParameters.get(i).governorToken;
if (null != temporalToken) {
temporalTokenBuffer.add(temporalToken);
}
temporalTokenBuffer.add(new TokenWithIndexAndSubTokens(Asn1Lexer.ASSIGNMENT));
temporalTokenBuffer.addAll(actualParameters.get(i));
// parse temp_tokenBuffer as an assignment
// List<ANTLRException> exceptions = null;
final Asn1Parser parser = BlockLevelTokenStreamTracker.getASN1ParserForBlock(new Block(temporalTokenBuffer, location));
if (null != parser) {
temporalAssignment = parser.pr_special_Assignment().assignment;
final List<SyntacticErrorStorage> errors = parser.getErrorStorage();
if (null != errors && !errors.isEmpty()) {
isErroneous = true;
temporalAssignment = null;
for (int j = 0; j < errors.size(); j++) {
ParserMarkerSupport.createOnTheFlyMixedMarker((IFile) mBlock.getLocation().getFile(), errors.get(j), IMarker.SEVERITY_ERROR);
}
}
}
}
if (null == temporalAssignment) {
temporalAssignment = new Type_Assignment(tempIdentifier, null, null);
}
temporalAssignment.setLocation(location);
assignments.addAssignment(temporalAssignment);
}
for (List<Token> temporalActualParamater : actualParameters) {
temporalActualParamater.clear();
}
actualParameters.clear();
}
}
use of org.eclipse.titan.designer.parsers.asn1parser.Asn1Parser in project titan.EclipsePlug-ins by eclipse.
the class ObjectSet_definition method parseBlockObjectSetSpecifications.
private void parseBlockObjectSetSpecifications() {
if (mBlock == null) {
return;
}
final Asn1Parser parser = BlockLevelTokenStreamTracker.getASN1ParserForBlock(mBlock);
if (parser == null) {
return;
}
final ObjectSet_definition temporalDefinition = parser.pr_special_ObjectSetSpec().definition;
// internalIndex += parser.nof_consumed_tokens();
final List<SyntacticErrorStorage> errors = parser.getErrorStorage();
if (null != errors && !errors.isEmpty()) {
for (int i = 0; i < errors.size(); i++) {
ParserMarkerSupport.createOnTheFlyMixedMarker((IFile) mBlock.getLocation().getFile(), errors.get(i), IMarker.SEVERITY_ERROR);
}
}
if (null == temporalDefinition) {
isErroneous = true;
return;
}
temporalDefinition.getObjectSetElements();
for (int i = 0; i < temporalDefinition.getObjectSetElements().size(); i++) {
addObjectSetElement(temporalDefinition.getObjectSetElements().get(i));
}
temporalDefinition.setObjectSetElements(null);
setMyScope(getMyScope());
}
Aggregations