Search in sources :

Example 21 with AddedParseTree

use of org.eclipse.titan.common.parsers.AddedParseTree in project titan.EclipsePlug-ins by eclipse.

the class DefineSubPage method createNewDefineItem.

private Definition createNewDefineItem() {
    if (defineSectionHandler == null) {
        return null;
    }
    final Definition item = new DefineSectionHandler.Definition();
    final ParseTree root = new ParserRuleContext();
    item.setRoot(root);
    final ParseTree name = new AddedParseTree("definition_name");
    final ParseTree value = new AddedParseTree("definition_value");
    item.setDefinitionName(name);
    item.setDefinitionValue(value);
    ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode("\n"));
    ConfigTreeNodeUtilities.addChild(root, name);
    ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(" := "));
    ConfigTreeNodeUtilities.addChild(root, value);
    return item;
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) Definition(org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 22 with AddedParseTree

use of org.eclipse.titan.common.parsers.AddedParseTree in project titan.EclipsePlug-ins by eclipse.

the class IncludeItemTransfer method nativeToJava.

@Override
protected ParseTree[] nativeToJava(final TransferData transferData) {
    byte[] bytes = (byte[]) super.nativeToJava(transferData);
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
    try {
        int n = in.readInt();
        ParseTree[] items = new ParseTree[2 * n];
        String fileName;
        String hiddenBefore;
        for (int i = 0; i < n; i++) {
            hiddenBefore = in.readUTF();
            fileName = in.readUTF();
            items[2 * i] = ConfigTreeNodeUtilities.createHiddenTokenNode(hiddenBefore);
            items[2 * i + 1] = new AddedParseTree(fileName);
        }
        return items;
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
        return new ParseTree[] {};
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 23 with AddedParseTree

use of org.eclipse.titan.common.parsers.AddedParseTree in project titan.EclipsePlug-ins by eclipse.

the class CfgParseTreePrinter method print.

/**
 * RECURSIVE
 * Builds parse tree text including hidden tokens
 * @param aParseTree parse tree
 * @param aTokens token list from the lexer (all, hidden and not hidden also)
 * @param aPrintHiddenBefore true to print hidden tokens before the parse tree
 *                           (NOTE: hidden tokens in the parse tree will be printed)
 * @param aResolveMode mode of resolving
 * @param aFile the parse tree of this file to print
 *                        needed only if aResolveMode != NO_RESOLVING, in case of [ORDERED_INCLUDE]
 */
private void print(final ParseTree aParseTree, final List<Token> aTokens, final boolean aPrintHiddenBefore, final ResolveMode aResolveMode, final Path aFile) {
    if (aParseTree == null) {
        ErrorReporter.logWarning("ConfigTreeNodeUtilities.print(): aParseTree == null");
        return;
    }
    if (aParseTree instanceof ParserRuleContext) {
        final ParserRuleContext rule = (ParserRuleContext) aParseTree;
        if (mDisallowedNodes != null && mDisallowedNodes.contains(rule.start.getType())) {
            return;
        }
        if (aPrintHiddenBefore && rule.getChildCount() > 0 && rule.getChild(0) instanceof AddedParseTree) {
            // special case: if AddedParseTree is the 1st in the rule, it has no information
            // about the hidden tokens, as it has no position in the token list, but the rule may have
            printHiddenTokensBefore(rule, aTokens);
        }
    } else if (aParseTree instanceof TerminalNodeImpl) {
        final TerminalNodeImpl tn = (TerminalNodeImpl) aParseTree;
        final Token token = tn.getSymbol();
        if (mDisallowedNodes == null || !mDisallowedNodes.contains(token.getType())) {
            printToken(token, aTokens, aPrintHiddenBefore, aResolveMode, aFile);
        }
    } else if (aParseTree instanceof AddedParseTree) {
        final AddedParseTree t = (AddedParseTree) aParseTree;
        mSb.append(t.getText());
    } else {
        ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.print(): unexpected ParseTree type");
    }
    for (int i = 0; i < aParseTree.getChildCount(); i++) {
        final ParseTree child = aParseTree.getChild(i);
        if (child == aParseTree) {
            ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.print(): child == aParseTree");
        } else {
            print(child, aTokens, aPrintHiddenBefore || i > 0, aResolveMode, aFile);
        }
    }
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) Token(org.antlr.v4.runtime.Token) TerminalNodeImpl(org.antlr.v4.runtime.tree.TerminalNodeImpl) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 24 with AddedParseTree

use of org.eclipse.titan.common.parsers.AddedParseTree in project titan.EclipsePlug-ins by eclipse.

the class ConfigTreeNodeUtilities method setParent.

/**
 * Sets the parent of a child node
 * @param aChild child node to modify
 * @param aParent parent rule, NOT null
 */
private static void setParent(final ParseTree aChild, final ParserRuleContext aParent) {
    if (aChild == null) {
        ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.setParent(): aChild == null");
        return;
    }
    if (aChild == aParent) {
        ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.setParent(): aChild == aParent");
        return;
    }
    if (aChild instanceof ParserRuleContext) {
        final ParserRuleContext rule = (ParserRuleContext) aChild;
        rule.parent = aParent;
    } else if (aChild instanceof TerminalNodeImpl) {
        final TerminalNodeImpl tn = (TerminalNodeImpl) aChild;
        tn.parent = aParent;
    } else if (aChild instanceof AddedParseTree) {
        final AddedParseTree t = (AddedParseTree) aChild;
        t.setParent(aParent);
    } else {
        ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.setParent(): unhandled ParseTree class type");
    }
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) TerminalNodeImpl(org.antlr.v4.runtime.tree.TerminalNodeImpl) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree)

Example 25 with AddedParseTree

use of org.eclipse.titan.common.parsers.AddedParseTree in project titan.EclipsePlug-ins by eclipse.

the class ConfigTreeNodeUtilities method setText.

/**
 * Changes the text of a parse tree
 * @param aParseTree parse tree to modify
 * @param aText new text
 */
public static void setText(final ParseTree aParseTree, final String aText) {
    if (aParseTree == null) {
        ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.setText(): aParseTree == null");
        return;
    }
    if (aParseTree instanceof ParserRuleContext) {
        final ParserRuleContext rule = (ParserRuleContext) aParseTree;
        // just delete it and replace the children with an AddedParseTree
        if (rule.children != null) {
            rule.children.clear();
        } else {
            rule.children = new ArrayList<ParseTree>();
        }
        final ParseTree newNode = new AddedParseTree(aText);
        addChild(rule, newNode);
    } else if (aParseTree instanceof AddedParseTree) {
        final AddedParseTree node = (AddedParseTree) aParseTree;
        node.setText(aText);
    } else if (aParseTree instanceof TerminalNodeImpl) {
        final TerminalNodeImpl node = (TerminalNodeImpl) aParseTree;
        final Token t = node.symbol;
        if (t instanceof WritableToken) {
            final WritableToken ct = (WritableToken) t;
            ct.setText(aText);
        } else {
            ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.setText(): unhandled token class type");
        }
    } else {
        ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.setText(): unhandled ParseTree class type");
    }
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) CommonToken(org.antlr.v4.runtime.CommonToken) Token(org.antlr.v4.runtime.Token) WritableToken(org.antlr.v4.runtime.WritableToken) TerminalNodeImpl(org.antlr.v4.runtime.tree.TerminalNodeImpl) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree) WritableToken(org.antlr.v4.runtime.WritableToken)

Aggregations

AddedParseTree (org.eclipse.titan.common.parsers.AddedParseTree)45 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)41 ParseTree (org.antlr.v4.runtime.tree.ParseTree)32 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DataInputStream (java.io.DataInputStream)6 IOException (java.io.IOException)6 TerminalNodeImpl (org.antlr.v4.runtime.tree.TerminalNodeImpl)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 ExpansionAdapter (org.eclipse.ui.forms.events.ExpansionAdapter)3 ExpansionEvent (org.eclipse.ui.forms.events.ExpansionEvent)3 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)3 Section (org.eclipse.ui.forms.widgets.Section)3 Token (org.antlr.v4.runtime.Token)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 Component (org.eclipse.titan.common.parsers.cfg.indices.ComponentSectionHandler.Component)2 Definition (org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition)2 ExecuteItem (org.eclipse.titan.common.parsers.cfg.indices.ExecuteSectionHandler.ExecuteItem)2