Search in sources :

Example 16 with Asn1Parser

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;
}
Also used : Asn1Parser(org.eclipse.titan.designer.parsers.asn1parser.Asn1Parser) Asn1Lexer(org.eclipse.titan.designer.parsers.asn1parser.Asn1Lexer) SyntacticErrorStorage(org.eclipse.titan.common.parsers.SyntacticErrorStorage) StringReader(java.io.StringReader) ASN1Listener(org.eclipse.titan.designer.parsers.asn1parser.ASN1Listener) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) ModuleLevelTokenStreamTracker(org.eclipse.titan.designer.parsers.asn1parser.ModuleLevelTokenStreamTracker) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) TokenWithIndexAndSubTokensFactory(org.eclipse.titan.designer.parsers.asn1parser.TokenWithIndexAndSubTokensFactory) CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream)

Example 17 with Asn1Parser

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());
        }
    }
}
Also used : Asn1Parser(org.eclipse.titan.designer.parsers.asn1parser.Asn1Parser) SyntacticErrorStorage(org.eclipse.titan.common.parsers.SyntacticErrorStorage)

Example 18 with Asn1Parser

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();
    }
}
Also used : Asn1Parser(org.eclipse.titan.designer.parsers.asn1parser.Asn1Parser) ObjectSet_definition(org.eclipse.titan.designer.AST.ASN1.Object.ObjectSet_definition) SyntacticErrorStorage(org.eclipse.titan.common.parsers.SyntacticErrorStorage) Constraint(org.eclipse.titan.designer.AST.Constraint) AtNotations(org.eclipse.titan.designer.AST.AtNotations)

Example 19 with Asn1Parser

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();
    }
}
Also used : TokenWithIndexAndSubTokens(org.eclipse.titan.designer.parsers.asn1parser.TokenWithIndexAndSubTokens) ArrayList(java.util.ArrayList) Token(org.antlr.v4.runtime.Token) Asn1Parser(org.eclipse.titan.designer.parsers.asn1parser.Asn1Parser) Identifier(org.eclipse.titan.designer.AST.Identifier) SyntacticErrorStorage(org.eclipse.titan.common.parsers.SyntacticErrorStorage) ArrayList(java.util.ArrayList) List(java.util.List) FormalParameter_Helper(org.eclipse.titan.designer.parsers.asn1parser.FormalParameter_Helper)

Example 20 with Asn1Parser

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());
}
Also used : Asn1Parser(org.eclipse.titan.designer.parsers.asn1parser.Asn1Parser) SyntacticErrorStorage(org.eclipse.titan.common.parsers.SyntacticErrorStorage)

Aggregations

Asn1Parser (org.eclipse.titan.designer.parsers.asn1parser.Asn1Parser)25 SyntacticErrorStorage (org.eclipse.titan.common.parsers.SyntacticErrorStorage)24 StringReader (java.io.StringReader)2 CharStream (org.antlr.v4.runtime.CharStream)2 UnbufferedCharStream (org.antlr.v4.runtime.UnbufferedCharStream)2 ASN1Listener (org.eclipse.titan.designer.parsers.asn1parser.ASN1Listener)2 Asn1Lexer (org.eclipse.titan.designer.parsers.asn1parser.Asn1Lexer)2 ModuleLevelTokenStreamTracker (org.eclipse.titan.designer.parsers.asn1parser.ModuleLevelTokenStreamTracker)2 TokenWithIndexAndSubTokensFactory (org.eclipse.titan.designer.parsers.asn1parser.TokenWithIndexAndSubTokensFactory)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Token (org.antlr.v4.runtime.Token)1 ASN1Assignment (org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)1 ASN1Object (org.eclipse.titan.designer.AST.ASN1.ASN1Object)1 ASN1Type (org.eclipse.titan.designer.AST.ASN1.ASN1Type)1 ObjectSet_definition (org.eclipse.titan.designer.AST.ASN1.Object.ObjectSet_definition)1 ObjectSet (org.eclipse.titan.designer.AST.ASN1.ObjectSet)1 AtNotations (org.eclipse.titan.designer.AST.AtNotations)1 Constraint (org.eclipse.titan.designer.AST.Constraint)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1