Search in sources :

Example 71 with ParseTree

use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.

the class GroupsSubPage method createNewGroup.

private Group createNewGroup() {
    if (groupSectionHandler == null) {
        return null;
    }
    final Group newGroup = new GroupSectionHandler.Group();
    final ParseTree root = new ParserRuleContext();
    newGroup.setRoot(root);
    final ParseTree groupName = new AddedParseTree("group_name");
    final ParseTree item = new AddedParseTree("item");
    newGroup.setGroupName(groupName);
    newGroup.setGroupItems(new ArrayList<GroupItem>());
    newGroup.getGroupItems().add(new GroupSectionHandler.GroupItem(item));
    ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode("\n"));
    ConfigTreeNodeUtilities.addChild(root, groupName);
    ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(" := "));
    ConfigTreeNodeUtilities.addChild(root, item);
    return newGroup;
}
Also used : Group(org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.Group) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) GroupSectionHandler(org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler) GroupItem(org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.GroupItem) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree) GroupItem(org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.GroupItem)

Example 72 with ParseTree

use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.

the class GroupsSubPage method createNewGroupsSection.

private void createNewGroupsSection() {
    if (groupSectionHandler == null) {
        return;
    }
    ParserRuleContext sectionRoot = new ParserRuleContext();
    groupSectionHandler.setLastSectionRoot(sectionRoot);
    ParseTree header = new AddedParseTree("\n[GROUPS]");
    ConfigTreeNodeUtilities.addChild(sectionRoot, header);
    ParserRuleContext root = editor.getParseTreeRoot();
    if (root != null) {
        root.addChild(sectionRoot);
    }
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 73 with ParseTree

use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.

the class MCSubPage method createMCSection.

// creates the maincontroller section if needed
private void createMCSection() {
    if (mcSectionHandler == null || mcSectionHandler.getLastSectionRoot() != null) {
        return;
    }
    ParserRuleContext sectionRoot = new ParserRuleContext();
    mcSectionHandler.setLastSectionRoot(sectionRoot);
    ParseTree header = new AddedParseTree("\n[MAIN_CONTROLLER]");
    ConfigTreeNodeUtilities.addChild(sectionRoot, header);
    ParserRuleContext root = editor.getParseTreeRoot();
    if (root != null) {
        root.addChild(sectionRoot);
    }
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 74 with ParseTree

use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.

the class MCSubPage method createMainControllerSection.

void createMainControllerSection(final Composite parent, final ScrolledForm form, final FormToolkit toolkit) {
    Section section = toolkit.createSection(parent, ExpandableComposite.TWISTIE | Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
    section.setActiveToggleColor(toolkit.getHyperlinkGroup().getActiveForeground());
    section.setToggleColor(toolkit.getColors().getColor(IFormColors.SEPARATOR));
    section.setText("Main Controller options");
    section.setDescription("Specify the Main Controller directing options for this configuration.");
    section.setExpanded(true);
    section.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(final ExpansionEvent e) {
            form.reflow(false);
        }
    });
    GridData gd = new GridData(SWT.FILL, SWT.NONE, true, false);
    section.setLayoutData(gd);
    Composite client = toolkit.createComposite(section, SWT.WRAP);
    section.setClient(client);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    client.setLayout(layout);
    toolkit.paintBordersFor(client);
    valueChanged = true;
    toolkit.createLabel(client, "Local Address:");
    localAddressText = toolkit.createText(client, "", SWT.SINGLE);
    localAddressText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    localAddressText.setEnabled(mcSectionHandler != null);
    localAddressText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || mcSectionHandler == null) {
                return;
            }
            editor.setDirty();
            String temp = localAddressText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (mcSectionHandler.getLocalAddressRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(mcSectionHandler.getLastSectionRoot(), mcSectionHandler.getLocalAddressRoot());
                }
                mcSectionHandler.setLocalAddress(null);
                mcSectionHandler.setLocalAddressRoot(null);
                removeMCSection();
            } else if (mcSectionHandler.getLocalAddress() == null) {
                // create the node
                createMCSection();
                ParseTree localAddressRoot = new ParserRuleContext();
                mcSectionHandler.setLocalAddressRoot(localAddressRoot);
                ConfigTreeNodeUtilities.addChild(mcSectionHandler.getLastSectionRoot(), localAddressRoot);
                ConfigTreeNodeUtilities.addChild(localAddressRoot, new AddedParseTree("\nlocalAddress := "));
                ParseTree localAddress = new AddedParseTree(temp.trim());
                mcSectionHandler.setLocalAddress(localAddress);
                ConfigTreeNodeUtilities.addChild(localAddressRoot, localAddress);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(mcSectionHandler.getLocalAddress(), temp.trim());
            }
        }
    });
    if (mcSectionHandler != null && mcSectionHandler.getLocalAddress() != null) {
        localAddressText.setText(ConfigTreeNodeUtilities.toString(mcSectionHandler.getLocalAddress()));
    }
    toolkit.createLabel(client, "TCP port:");
    tcpPortText = toolkit.createText(client, "", SWT.SINGLE);
    tcpPortText.setEnabled(mcSectionHandler != null);
    tcpPortText.setLayoutData(new GridData(75, SWT.DEFAULT));
    tcpPortText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || mcSectionHandler == null) {
                return;
            }
            editor.setDirty();
            String temp = tcpPortText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (mcSectionHandler.getTcpPortRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(mcSectionHandler.getLastSectionRoot(), mcSectionHandler.getTcpPortRoot());
                }
                mcSectionHandler.setTcpPort(null);
                mcSectionHandler.setTcpPortRoot(null);
                removeMCSection();
            } else if (mcSectionHandler.getTcpPort() == null) {
                // create the node
                createMCSection();
                ParseTree tcpPortRoot = new ParserRuleContext();
                mcSectionHandler.setTcpPortRoot(tcpPortRoot);
                ConfigTreeNodeUtilities.addChild(mcSectionHandler.getLastSectionRoot(), tcpPortRoot);
                ConfigTreeNodeUtilities.addChild(tcpPortRoot, new AddedParseTree("\nTCPPort := "));
                ParseTree tcpPort = new AddedParseTree(temp.trim());
                mcSectionHandler.setTcpPort(tcpPort);
                ConfigTreeNodeUtilities.addChild(tcpPortRoot, tcpPort);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(mcSectionHandler.getTcpPort(), temp.trim());
            }
        }
    });
    if (mcSectionHandler != null && mcSectionHandler.getTcpPort() != null) {
        tcpPortText.setText(ConfigTreeNodeUtilities.toString(mcSectionHandler.getTcpPort()));
    }
    toolkit.createLabel(client, "Kill timer:");
    killTimerText = toolkit.createText(client, "", SWT.SINGLE);
    killTimerText.setEnabled(mcSectionHandler != null);
    killTimerText.setLayoutData(new GridData(75, SWT.DEFAULT));
    killTimerText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || mcSectionHandler == null) {
                return;
            }
            editor.setDirty();
            String temp = killTimerText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (mcSectionHandler.getKillTimerRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(mcSectionHandler.getLastSectionRoot(), mcSectionHandler.getKillTimerRoot());
                }
                mcSectionHandler.setKillTimer(null);
                mcSectionHandler.setKillTimerRoot(null);
                removeMCSection();
            } else if (mcSectionHandler.getKillTimer() == null) {
                // create the node
                createMCSection();
                ParseTree killTimerRoot = new ParserRuleContext();
                mcSectionHandler.setKillTimerRoot(killTimerRoot);
                ConfigTreeNodeUtilities.addChild(mcSectionHandler.getLastSectionRoot(), killTimerRoot);
                ConfigTreeNodeUtilities.addChild(killTimerRoot, new AddedParseTree("\nkillTimer := "));
                ParseTree killTimer = new AddedParseTree(temp.trim());
                mcSectionHandler.setTcpPort(killTimer);
                ConfigTreeNodeUtilities.addChild(killTimerRoot, killTimer);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(mcSectionHandler.getKillTimer(), temp.trim());
            }
        }
    });
    if (mcSectionHandler != null && mcSectionHandler.getKillTimer() != null) {
        killTimerText.setText(ConfigTreeNodeUtilities.toString(mcSectionHandler.getKillTimer()));
    }
    toolkit.createLabel(client, "Number of Host Contollers:");
    numHCsText = toolkit.createText(client, "", SWT.SINGLE);
    numHCsText.setEnabled(mcSectionHandler != null);
    numHCsText.setLayoutData(new GridData(75, SWT.DEFAULT));
    numHCsText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || mcSectionHandler == null) {
                return;
            }
            editor.setDirty();
            String temp = numHCsText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (mcSectionHandler.getNumHCsTextRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(mcSectionHandler.getLastSectionRoot(), mcSectionHandler.getNumHCsTextRoot());
                }
                mcSectionHandler.setNumHCsText(null);
                mcSectionHandler.setNumHCsTextRoot(null);
                removeMCSection();
            } else if (mcSectionHandler.getNumHCsText() == null) {
                // create the node
                createMCSection();
                ParseTree numHCsTextRoot = new ParserRuleContext();
                mcSectionHandler.setKillTimerRoot(numHCsTextRoot);
                ConfigTreeNodeUtilities.addChild(mcSectionHandler.getLastSectionRoot(), numHCsTextRoot);
                ConfigTreeNodeUtilities.addChild(numHCsTextRoot, new AddedParseTree("\nnumHCs := "));
                ParseTree numHCsText = new AddedParseTree(temp.trim());
                mcSectionHandler.setNumHCsText(numHCsText);
                ConfigTreeNodeUtilities.addChild(numHCsTextRoot, numHCsText);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(mcSectionHandler.getNumHCsText(), temp.trim());
            }
        }
    });
    if (mcSectionHandler != null && mcSectionHandler.getNumHCsText() != null) {
        numHCsText.setText(ConfigTreeNodeUtilities.toString(mcSectionHandler.getNumHCsText()));
    }
    toolkit.createLabel(client, "Use of unix domain socket communication:");
    unixDomainSocketText = new CCombo(client, SWT.FLAT);
    unixDomainSocketText.setEnabled(mcSectionHandler != null);
    unixDomainSocketText.setLayoutData(new GridData(75, SWT.DEFAULT));
    unixDomainSocketText.add("Yes");
    unixDomainSocketText.add("No");
    unixDomainSocketText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || mcSectionHandler == null) {
                return;
            }
            editor.setDirty();
            String temp = unixDomainSocketText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (mcSectionHandler.getUnixDomainSocketRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(mcSectionHandler.getLastSectionRoot(), mcSectionHandler.getUnixDomainSocketRoot());
                }
                mcSectionHandler.setUnixDomainSocket(null);
                mcSectionHandler.setUnixDomainSocketRoot(null);
                removeMCSection();
            } else if (mcSectionHandler.getUnixDomainSocket() == null) {
                // create the node
                createMCSection();
                ParseTree unixDomainSocketRoot = new ParserRuleContext();
                mcSectionHandler.setUnixDomainSocketRoot(unixDomainSocketRoot);
                ConfigTreeNodeUtilities.addChild(mcSectionHandler.getLastSectionRoot(), unixDomainSocketRoot);
                ConfigTreeNodeUtilities.addChild(unixDomainSocketRoot, new AddedParseTree("\nUnixSocketsEnabled := "));
                ParseTree unixDomainSocket = new AddedParseTree(temp.trim());
                mcSectionHandler.setUnixDomainSocket(unixDomainSocket);
                ConfigTreeNodeUtilities.addChild(unixDomainSocketRoot, unixDomainSocket);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(mcSectionHandler.getUnixDomainSocket(), temp.trim());
            }
        }
    });
    if (mcSectionHandler != null && mcSectionHandler.getUnixDomainSocket() != null) {
        unixDomainSocketText.setText(ConfigTreeNodeUtilities.toString(mcSectionHandler.getUnixDomainSocket()));
    }
    valueChanged = false;
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ModifyListener(org.eclipse.swt.events.ModifyListener) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) Section(org.eclipse.ui.forms.widgets.Section) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CCombo(org.eclipse.swt.custom.CCombo) GridData(org.eclipse.swt.layout.GridData) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 75 with ParseTree

use of org.antlr.v4.runtime.tree.ParseTree in project contribution by checkstyle.

the class ExpectedParseTreeGenerator method walk.

public String walk(ParseTree t, String parentObjectName) {
    final String className = t.getClass().getSimpleName();
    String id = null;
    if (t instanceof TerminalNode) {
        final TerminalNodeImpl terminal = (TerminalNodeImpl) t;
        final int type = terminal.symbol.getType();
        String tokenType = "";
        if (type == -1) {
            tokenType = "EOF";
        } else {
            tokenType = JavadocUtils.getTokenName(type);
        }
        String text = terminal.getText();
        if ("\n".equals(text)) {
            text = "\\n";
        } else if ("\t".equals(text)) {
            text = "\\t";
        } else {
            text = text.replace("\"", "\\\"");
        }
        final int number = getVariableCounter(tokenType);
        id = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, tokenType.toLowerCase()) + number;
        System.out.println("    CommonToken " + id + " = new CommonToken(JavadocTokenTypes." + tokenType + ", \"" + text + "\");");
    } else {
        int number = getVariableCounter(className);
        id = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, className) + number++;
        System.out.println("    " + className + " " + id + " = new " + className + "(" + parentObjectName + ", 0);");
        final int n = t.getChildCount();
        for (int i = 0; i < n; i++) {
            final String childId = walk(t.getChild(i), id);
            System.out.println("    " + id + ".addChild(" + childId + ");");
        }
    }
    return id;
}
Also used : TerminalNodeImpl(org.antlr.v4.runtime.tree.TerminalNodeImpl) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode)

Aggregations

ParseTree (org.antlr.v4.runtime.tree.ParseTree)311 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)104 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)60 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)49 AddedParseTree (org.eclipse.titan.common.parsers.AddedParseTree)46 CharStream (org.antlr.v4.runtime.CharStream)43 Test (org.junit.Test)43 CommonToken (org.antlr.v4.runtime.CommonToken)35 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)35 JavadocContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.JavadocContext)31 TextContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.TextContext)29 File (java.io.File)26 ArrayList (java.util.ArrayList)22 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)22 CancellationException (java.util.concurrent.CancellationException)20 ConsoleErrorListener (org.antlr.v4.runtime.ConsoleErrorListener)20 Grammar (org.antlr.v4.tool.Grammar)20 ByteArrayInputStream (java.io.ByteArrayInputStream)19 IOException (java.io.IOException)19 LexerGrammar (org.antlr.v4.tool.LexerGrammar)16