org.eclipse.xtext.nodemodel.impl.NodeModelBuilder Java Examples
The following examples show how to use
org.eclipse.xtext.nodemodel.impl.NodeModelBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractAntlrParser.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected IParseResult doParse(String ruleName, CharStream in, NodeModelBuilder nodeModelBuilder, int initialLookAhead) { TokenSource tokenSource = createLexer(in); XtextTokenStream tokenStream = createTokenStream(tokenSource); tokenStream.initCurrentLookAhead(initialLookAhead); setInitialHiddenTokens(tokenStream); AbstractInternalAntlrParser parser = createParser(tokenStream); parser.setTokenTypeMap(getTokenDefProvider().getTokenDefMap()); parser.setSyntaxErrorProvider(getSyntaxErrorProvider()); parser.setNodeModelBuilder(nodeModelBuilder); parser.setSemanticModelBuilder(getElementFactory()); IUnorderedGroupHelper helper = getUnorderedGroupHelper().get(); parser.setUnorderedGroupHelper(helper); helper.initializeWith(parser); try { if(ruleName != null) return parser.parse(ruleName); return parser.parse(); } catch (Exception re) { throw new ParseException(re.getMessage(),re); } }
Example #2
Source File: AbstractContextualAntlrParser.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** {@inheritDoc} */ @Override protected IParseResult doParse(final String ruleName, final CharStream in, final NodeModelBuilder nodeModelBuilder, final int initialLookAhead) { final IParseResult parseResult = super.doParse(ruleName, in, nodeModelBuilder, initialLookAhead); if (delegate == null || parseResult.hasSyntaxErrors()) { return parseResult; } // If delegation was potentially used, we need to check for syntax errors in replaced nodes boolean hasError = false; Iterator<AbstractNode> nodeIterator = ((CompositeNode) parseResult.getRootNode()).basicIterator(); while (nodeIterator.hasNext()) { AbstractNode node = nodeIterator.next(); if (node.getSyntaxErrorMessage() != null) { hasError = true; break; } } if (hasError) { return new ParseResult(parseResult.getRootASTElement(), parseResult.getRootNode(), true); } return parseResult; }
Example #3
Source File: LazyURIEncoderTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testNodePath() throws Exception { NodeModelBuilder builder = new NodeModelBuilder(); ICompositeNode n = new CompositeNode(); ICompositeNode n1 = new CompositeNode(); builder.addChild(n, (AbstractNode) n1); ICompositeNode n2 = new CompositeNode(); builder.addChild(n, (AbstractNode) n2); ILeafNode l1 = new LeafNode(); builder.addChild(n2, (AbstractNode) l1); ILeafNode l2 = new LeafNode(); builder.addChild(n2, (AbstractNode) l2); assertEquals(n, find(n,n)); assertEquals(n1, find(n,n1)); assertEquals(n2, find(n,n2)); assertEquals(l1, find(n,l1)); assertEquals(l2, find(n,l2)); }
Example #4
Source File: HiddenAndTokenNodeIteratorTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Before public void setUp() throws Exception { nodes = new INode[NUM_NODES]; NodeModelBuilder builder = new NodeModelBuilder(); nodes[0] = new CompositeNode(); nodes[1] = new CompositeNode(); nodes[2] = new HiddenLeafNode(); nodes[3] = new LeafNode(); nodes[4] = new HiddenLeafNode(); nodes[5] = new CompositeNode(); nodes[6] = new LeafNode(); nodes[7] = new CompositeNode(); nodes[8] = new HiddenLeafNode(); nodes[9] = new LeafNode(); builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[1]); builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[5]); builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[7]); builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[9]); builder.addChild((ICompositeNode)nodes[1], (AbstractNode)nodes[2]); builder.addChild((ICompositeNode)nodes[1], (AbstractNode)nodes[3]); builder.addChild((ICompositeNode)nodes[1], (AbstractNode)nodes[4]); builder.addChild((ICompositeNode)nodes[5], (AbstractNode)nodes[6]); builder.addChild((ICompositeNode)nodes[7], (AbstractNode)nodes[8]); }
Example #5
Source File: NodeIteratorTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public static INode nodeWithTwoSiblings() { NodeModelBuilder builder = new NodeModelBuilder(); String text = "alpha beta gamma"; ICompositeNode root = builder.newRootNode(text); EObject alpha = new EObjectImpl() {}; ILeafNode alphaNode = builder.newLeafNode(text.indexOf("alpha"), "alpha".length(), alpha, false, null, root); EObject beta = new EObjectImpl() {}; builder.newLeafNode(text.indexOf("beta"), "beta".length(), beta, false, null, root); EObject gamma = new EObjectImpl() {}; builder.newLeafNode(text.indexOf("gamma"), "gamma".length(), gamma, false, null, root); return alphaNode; }
Example #6
Source File: CustomXtendParser.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public IParseResult parse(RuleCall ruleCall, Reader reader, int initialLookAhead) { NodeModelBuilder builder = createNodeModelBuilder(); builder.setForcedFirstGrammarElement(ruleCall); IParseResult parseResult = doParse(ruleCall.getRule().getName(), new ReaderCharStream(reader), builder, initialLookAhead); return parseResult; }
Example #7
Source File: AbstractContextualAntlrParser.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc}. * For parser delegation it is critically important that the root node of the parsed sub-tree is not merged. Otherwise we do not have a proper new composite * node for replacement. */ public IParseResult parseDelegate(final ParserRule rule, final Reader reader) { try { NodeModelBuilder builder = createNodeModelBuilder(); builder.setForcedFirstGrammarElement(null); return doParse(rule.getName(), new ANTLRReaderStream(reader), builder, 0); } catch (IOException e) { throw new WrappedException(e); } }
Example #8
Source File: LazyLinkerTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private ICompositeNode newSimpleNodeAdapter(final INode... nodes) { NodeModelBuilder builder = new NodeModelBuilder(); ICompositeNode result = new CompositeNodeWithSemanticElement(); for(INode node: nodes) { builder.addChild(result, (AbstractNode) node); } return result; }
Example #9
Source File: NodeIteratorTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Before public void setUp() throws Exception { NodeModelBuilder builder = new NodeModelBuilder(); nodes = new INode[NUM_NODES]; nodes[0] = new CompositeNode(); nodes[1] = new LeafNode(); nodes[2] = new CompositeNode(); nodes[3] = new CompositeNode(); nodes[4] = new LeafNode(); nodes[5] = new LeafNode(); nodes[6] = new LeafNode(); nodes[7] = new CompositeNode(); nodes[8] = new LeafNode(); nodes[9] = new LeafNode(); nodes[10]= new CompositeNode(); builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[1]); builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[2]); builder.addChild((ICompositeNode)nodes[2], (AbstractNode)nodes[3]); builder.addChild((ICompositeNode)nodes[3], (AbstractNode)nodes[4]); builder.addChild((ICompositeNode)nodes[3], (AbstractNode)nodes[5]); builder.addChild((ICompositeNode)nodes[2], (AbstractNode)nodes[6]); builder.addChild((ICompositeNode)nodes[2], (AbstractNode)nodes[7]); builder.addChild((ICompositeNode)nodes[2], (AbstractNode)nodes[8]); builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[9]); builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[10]); }
Example #10
Source File: AbstractAntlrParser.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public IParseResult parse(RuleCall ruleCall, Reader reader, int initialLookAhead) { try { NodeModelBuilder builder = nodeModelBuilder.get(); builder.setForcedFirstGrammarElement(ruleCall); IParseResult parseResult = doParse(ruleCall.getRule().getName(), new ANTLRReaderStream(reader), builder, initialLookAhead); return parseResult; } catch (IOException e) { throw new WrappedException(e); } }
Example #11
Source File: AbstractCompositeNodeTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Before public void setUp() throws Exception { this.mutator = new NodeModelBuilder(); }
Example #12
Source File: AbstractNodeTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Before public void setUp() throws Exception { builder = new NodeModelBuilder(); }
Example #13
Source File: BasicNodeIteratorTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public static AbstractNode nodeWithTwoSiblings() { NodeModelBuilder builder = new NodeModelBuilder(); String text = "alpha beta gamma"; RootNode root = new RootNode(); root.basicSetCompleteContent(text); EObject alpha = new EObjectImpl() {}; builder.newLeafNode(text.indexOf("alpha"), "alpha".length(), alpha, false, null, root); EObject beta = new EObjectImpl() {}; builder.newLeafNode(text.indexOf("beta"), "beta".length(), beta, false, null, root); EObject gamma = new EObjectImpl() {}; builder.newLeafNode(text.indexOf("gamma"), "gamma".length(), gamma, false, null, root); return root.basicGetFirstChild(); }
Example #14
Source File: AbstractInternalAntlrParser.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public NodeModelBuilder getNodeModelBuilder() { return nodeBuilder; }
Example #15
Source File: AbstractInternalAntlrParser.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public void setNodeModelBuilder(NodeModelBuilder nodeModelBuilder) { this.nodeBuilder = nodeModelBuilder; }
Example #16
Source File: AbstractAntlrParser.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.5 */ protected NodeModelBuilder createNodeModelBuilder() { return nodeModelBuilder.get(); }
Example #17
Source File: DefaultXbaseRuntimeModule.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.9 */ public Class<? extends NodeModelBuilder> bindNodeModelBuilder() { return LookAheadPreservingNodeModelBuilder.class; }