Improved synthetic token placement

This commit is contained in:
Sebastian Zarnekow 2017-06-07 10:31:21 +02:00
parent 08ae63f360
commit 19a3930632
25 changed files with 2846 additions and 74 deletions

View file

@ -5,10 +5,21 @@
<eClassifiers xsi:type="ecore:EClass" name="Tree">
<eStructuralFeatures xsi:type="ecore:EReference" name="nodes" upperBound="-1"
eType="#//TreeNode" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="moreNodes" upperBound="-1"
eType="#//OtherTreeNode" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="TreeNode">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
eType="#//TreeNode" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="OtherTreeNode">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="childList" eType="#//ChildList"
containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ChildList">
<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
eType="#//OtherTreeNode" containment="true"/>
</eClassifiers>
</ecore:EPackage>

View file

@ -3,16 +3,24 @@
xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" copyrightText="generated by Xtext" modelDirectory="/org.eclipse.xtext.tests/src-gen"
modelPluginID="org.eclipse.xtext.tests" forceOverwrite="true" modelName="IndentationAwareTestLanguage"
updateClasspath="false" rootExtendsClass="org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container"
complianceLevel="6.0" copyrightFields="false" runtimeVersion="2.9" usedGenPackages="platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel#//ecore">
complianceLevel="6.0" copyrightFields="false" runtimeVersion="2.9">
<genPackages prefix="IndentationAwareTestLanguage" basePackage="org.eclipse.xtext.parser.indentation"
disposableProviderFactory="true" fileExtensions="indentationawaretestlanguage"
ecorePackage="IndentationAwareTestLanguage.ecore#/">
<genClasses ecoreClass="IndentationAwareTestLanguage.ecore#//Tree">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference IndentationAwareTestLanguage.ecore#//Tree/nodes"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference IndentationAwareTestLanguage.ecore#//Tree/moreNodes"/>
</genClasses>
<genClasses ecoreClass="IndentationAwareTestLanguage.ecore#//TreeNode">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute IndentationAwareTestLanguage.ecore#//TreeNode/name"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference IndentationAwareTestLanguage.ecore#//TreeNode/children"/>
</genClasses>
<genClasses ecoreClass="IndentationAwareTestLanguage.ecore#//OtherTreeNode">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute IndentationAwareTestLanguage.ecore#//OtherTreeNode/name"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference IndentationAwareTestLanguage.ecore#//OtherTreeNode/childList"/>
</genClasses>
<genClasses ecoreClass="IndentationAwareTestLanguage.ecore#//ChildList">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference IndentationAwareTestLanguage.ecore#//ChildList/children"/>
</genClasses>
</genPackages>
</genmodel:GenModel>

View file

@ -0,0 +1,44 @@
/**
* generated by Xtext
*/
package org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
/**
* <!-- begin-user-doc -->
* A representation of the model object '<em><b>Child List</b></em>'.
* <!-- end-user-doc -->
*
* <p>
* The following features are supported:
* </p>
* <ul>
* <li>{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.ChildList#getChildren <em>Children</em>}</li>
* </ul>
*
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.IndentationAwareTestLanguagePackage#getChildList()
* @model
* @generated
*/
public interface ChildList extends EObject
{
/**
* Returns the value of the '<em><b>Children</b></em>' containment reference list.
* The list contents are of type {@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode}.
* <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Children</em>' containment reference list isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @return the value of the '<em>Children</em>' containment reference list.
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.IndentationAwareTestLanguagePackage#getChildList_Children()
* @model containment="true"
* @generated
*/
EList<OtherTreeNode> getChildren();
} // ChildList

View file

@ -41,6 +41,24 @@ public interface IndentationAwareTestLanguageFactory extends EFactory
*/
TreeNode createTreeNode();
/**
* Returns a new object of class '<em>Other Tree Node</em>'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return a new object of class '<em>Other Tree Node</em>'.
* @generated
*/
OtherTreeNode createOtherTreeNode();
/**
* Returns a new object of class '<em>Child List</em>'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return a new object of class '<em>Child List</em>'.
* @generated
*/
ChildList createChildList();
/**
* Returns the package supported by this factory.
* <!-- begin-user-doc -->

View file

@ -76,6 +76,15 @@ public interface IndentationAwareTestLanguagePackage extends EPackage
*/
int TREE__NODES = 0;
/**
* The feature id for the '<em><b>More Nodes</b></em>' containment reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int TREE__MORE_NODES = 1;
/**
* The number of structural features of the '<em>Tree</em>' class.
* <!-- begin-user-doc -->
@ -83,7 +92,7 @@ public interface IndentationAwareTestLanguagePackage extends EPackage
* @generated
* @ordered
*/
int TREE_FEATURE_COUNT = 1;
int TREE_FEATURE_COUNT = 2;
/**
* The meta object id for the '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.TreeNodeImpl <em>Tree Node</em>}' class.
@ -122,6 +131,71 @@ public interface IndentationAwareTestLanguagePackage extends EPackage
*/
int TREE_NODE_FEATURE_COUNT = 2;
/**
* The meta object id for the '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.OtherTreeNodeImpl <em>Other Tree Node</em>}' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.OtherTreeNodeImpl
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.IndentationAwareTestLanguagePackageImpl#getOtherTreeNode()
* @generated
*/
int OTHER_TREE_NODE = 2;
/**
* The feature id for the '<em><b>Name</b></em>' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int OTHER_TREE_NODE__NAME = 0;
/**
* The feature id for the '<em><b>Child List</b></em>' containment reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int OTHER_TREE_NODE__CHILD_LIST = 1;
/**
* The number of structural features of the '<em>Other Tree Node</em>' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int OTHER_TREE_NODE_FEATURE_COUNT = 2;
/**
* The meta object id for the '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.ChildListImpl <em>Child List</em>}' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.ChildListImpl
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.IndentationAwareTestLanguagePackageImpl#getChildList()
* @generated
*/
int CHILD_LIST = 3;
/**
* The feature id for the '<em><b>Children</b></em>' containment reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int CHILD_LIST__CHILDREN = 0;
/**
* The number of structural features of the '<em>Child List</em>' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int CHILD_LIST_FEATURE_COUNT = 1;
/**
* Returns the meta object for class '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree <em>Tree</em>}'.
@ -144,6 +218,17 @@ public interface IndentationAwareTestLanguagePackage extends EPackage
*/
EReference getTree_Nodes();
/**
* Returns the meta object for the containment reference list '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree#getMoreNodes <em>More Nodes</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for the containment reference list '<em>More Nodes</em>'.
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree#getMoreNodes()
* @see #getTree()
* @generated
*/
EReference getTree_MoreNodes();
/**
* Returns the meta object for class '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.TreeNode <em>Tree Node</em>}'.
* <!-- begin-user-doc -->
@ -176,6 +261,59 @@ public interface IndentationAwareTestLanguagePackage extends EPackage
*/
EReference getTreeNode_Children();
/**
* Returns the meta object for class '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode <em>Other Tree Node</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for class '<em>Other Tree Node</em>'.
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode
* @generated
*/
EClass getOtherTreeNode();
/**
* Returns the meta object for the attribute '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode#getName <em>Name</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for the attribute '<em>Name</em>'.
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode#getName()
* @see #getOtherTreeNode()
* @generated
*/
EAttribute getOtherTreeNode_Name();
/**
* Returns the meta object for the containment reference '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode#getChildList <em>Child List</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for the containment reference '<em>Child List</em>'.
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode#getChildList()
* @see #getOtherTreeNode()
* @generated
*/
EReference getOtherTreeNode_ChildList();
/**
* Returns the meta object for class '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.ChildList <em>Child List</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for class '<em>Child List</em>'.
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.ChildList
* @generated
*/
EClass getChildList();
/**
* Returns the meta object for the containment reference list '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.ChildList#getChildren <em>Children</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for the containment reference list '<em>Children</em>'.
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.ChildList#getChildren()
* @see #getChildList()
* @generated
*/
EReference getChildList_Children();
/**
* Returns the factory that creates the instances of the model.
* <!-- begin-user-doc -->
@ -217,6 +355,14 @@ public interface IndentationAwareTestLanguagePackage extends EPackage
*/
EReference TREE__NODES = eINSTANCE.getTree_Nodes();
/**
* The meta object literal for the '<em><b>More Nodes</b></em>' containment reference list feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
EReference TREE__MORE_NODES = eINSTANCE.getTree_MoreNodes();
/**
* The meta object literal for the '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.TreeNodeImpl <em>Tree Node</em>}' class.
* <!-- begin-user-doc -->
@ -243,6 +389,50 @@ public interface IndentationAwareTestLanguagePackage extends EPackage
*/
EReference TREE_NODE__CHILDREN = eINSTANCE.getTreeNode_Children();
/**
* The meta object literal for the '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.OtherTreeNodeImpl <em>Other Tree Node</em>}' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.OtherTreeNodeImpl
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.IndentationAwareTestLanguagePackageImpl#getOtherTreeNode()
* @generated
*/
EClass OTHER_TREE_NODE = eINSTANCE.getOtherTreeNode();
/**
* The meta object literal for the '<em><b>Name</b></em>' attribute feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
EAttribute OTHER_TREE_NODE__NAME = eINSTANCE.getOtherTreeNode_Name();
/**
* The meta object literal for the '<em><b>Child List</b></em>' containment reference feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
EReference OTHER_TREE_NODE__CHILD_LIST = eINSTANCE.getOtherTreeNode_ChildList();
/**
* The meta object literal for the '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.ChildListImpl <em>Child List</em>}' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.ChildListImpl
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.IndentationAwareTestLanguagePackageImpl#getChildList()
* @generated
*/
EClass CHILD_LIST = eINSTANCE.getChildList();
/**
* The meta object literal for the '<em><b>Children</b></em>' containment reference list feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
EReference CHILD_LIST__CHILDREN = eINSTANCE.getChildList_Children();
}
} //IndentationAwareTestLanguagePackage

View file

@ -0,0 +1,79 @@
/**
* generated by Xtext
*/
package org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage;
import org.eclipse.emf.ecore.EObject;
/**
* <!-- begin-user-doc -->
* A representation of the model object '<em><b>Other Tree Node</b></em>'.
* <!-- end-user-doc -->
*
* <p>
* The following features are supported:
* </p>
* <ul>
* <li>{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode#getName <em>Name</em>}</li>
* <li>{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode#getChildList <em>Child List</em>}</li>
* </ul>
*
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.IndentationAwareTestLanguagePackage#getOtherTreeNode()
* @model
* @generated
*/
public interface OtherTreeNode extends EObject
{
/**
* Returns the value of the '<em><b>Name</b></em>' attribute.
* <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Name</em>' attribute isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @return the value of the '<em>Name</em>' attribute.
* @see #setName(String)
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.IndentationAwareTestLanguagePackage#getOtherTreeNode_Name()
* @model
* @generated
*/
String getName();
/**
* Sets the value of the '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode#getName <em>Name</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Name</em>' attribute.
* @see #getName()
* @generated
*/
void setName(String value);
/**
* Returns the value of the '<em><b>Child List</b></em>' containment reference.
* <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Child List</em>' containment reference isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @return the value of the '<em>Child List</em>' containment reference.
* @see #setChildList(ChildList)
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.IndentationAwareTestLanguagePackage#getOtherTreeNode_ChildList()
* @model containment="true"
* @generated
*/
ChildList getChildList();
/**
* Sets the value of the '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode#getChildList <em>Child List</em>}' containment reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Child List</em>' containment reference.
* @see #getChildList()
* @generated
*/
void setChildList(ChildList value);
} // OtherTreeNode

View file

@ -17,6 +17,7 @@ import org.eclipse.emf.ecore.EObject;
* </p>
* <ul>
* <li>{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree#getNodes <em>Nodes</em>}</li>
* <li>{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree#getMoreNodes <em>More Nodes</em>}</li>
* </ul>
*
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.IndentationAwareTestLanguagePackage#getTree()
@ -41,4 +42,20 @@ public interface Tree extends EObject
*/
EList<TreeNode> getNodes();
/**
* Returns the value of the '<em><b>More Nodes</b></em>' containment reference list.
* The list contents are of type {@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode}.
* <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>More Nodes</em>' containment reference list isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @return the value of the '<em>More Nodes</em>' containment reference list.
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.IndentationAwareTestLanguagePackage#getTree_MoreNodes()
* @model containment="true"
* @generated
*/
EList<OtherTreeNode> getMoreNodes();
} // Tree

View file

@ -0,0 +1,168 @@
/**
* generated by Xtext
*/
package org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl;
import java.util.Collection;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.ChildList;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.IndentationAwareTestLanguagePackage;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Child List</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* </p>
* <ul>
* <li>{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.ChildListImpl#getChildren <em>Children</em>}</li>
* </ul>
*
* @generated
*/
public class ChildListImpl extends MinimalEObjectImpl.Container implements ChildList
{
/**
* The cached value of the '{@link #getChildren() <em>Children</em>}' containment reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getChildren()
* @generated
* @ordered
*/
protected EList<OtherTreeNode> children;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected ChildListImpl()
{
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass()
{
return IndentationAwareTestLanguagePackage.Literals.CHILD_LIST;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EList<OtherTreeNode> getChildren()
{
if (children == null)
{
children = new EObjectContainmentEList<OtherTreeNode>(OtherTreeNode.class, this, IndentationAwareTestLanguagePackage.CHILD_LIST__CHILDREN);
}
return children;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
{
switch (featureID)
{
case IndentationAwareTestLanguagePackage.CHILD_LIST__CHILDREN:
return ((InternalEList<?>)getChildren()).basicRemove(otherEnd, msgs);
}
return super.eInverseRemove(otherEnd, featureID, msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType)
{
switch (featureID)
{
case IndentationAwareTestLanguagePackage.CHILD_LIST__CHILDREN:
return getChildren();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue)
{
switch (featureID)
{
case IndentationAwareTestLanguagePackage.CHILD_LIST__CHILDREN:
getChildren().clear();
getChildren().addAll((Collection<? extends OtherTreeNode>)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID)
{
switch (featureID)
{
case IndentationAwareTestLanguagePackage.CHILD_LIST__CHILDREN:
getChildren().clear();
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID)
{
switch (featureID)
{
case IndentationAwareTestLanguagePackage.CHILD_LIST__CHILDREN:
return children != null && !children.isEmpty();
}
return super.eIsSet(featureID);
}
} //ChildListImpl

View file

@ -67,6 +67,8 @@ public class IndentationAwareTestLanguageFactoryImpl extends EFactoryImpl implem
{
case IndentationAwareTestLanguagePackage.TREE: return createTree();
case IndentationAwareTestLanguagePackage.TREE_NODE: return createTreeNode();
case IndentationAwareTestLanguagePackage.OTHER_TREE_NODE: return createOtherTreeNode();
case IndentationAwareTestLanguagePackage.CHILD_LIST: return createChildList();
default:
throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier");
}
@ -94,6 +96,28 @@ public class IndentationAwareTestLanguageFactoryImpl extends EFactoryImpl implem
return treeNode;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public OtherTreeNode createOtherTreeNode()
{
OtherTreeNodeImpl otherTreeNode = new OtherTreeNodeImpl();
return otherTreeNode;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public ChildList createChildList()
{
ChildListImpl childList = new ChildListImpl();
return childList;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->

View file

@ -7,12 +7,13 @@ import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.impl.EPackageImpl;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.ChildList;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.IndentationAwareTestLanguageFactory;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.IndentationAwareTestLanguagePackage;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.TreeNode;
@ -38,6 +39,20 @@ public class IndentationAwareTestLanguagePackageImpl extends EPackageImpl implem
*/
private EClass treeNodeEClass = null;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
private EClass otherTreeNodeEClass = null;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
private EClass childListEClass = null;
/**
* Creates an instance of the model <b>Package</b>, registered with
* {@link org.eclipse.emf.ecore.EPackage.Registry EPackage.Registry} by the package
@ -86,9 +101,6 @@ public class IndentationAwareTestLanguagePackageImpl extends EPackageImpl implem
isInited = true;
// Initialize simple dependencies
EcorePackage.eINSTANCE.eClass();
// Create package meta-data objects
theIndentationAwareTestLanguagePackage.createPackageContents();
@ -124,6 +136,16 @@ public class IndentationAwareTestLanguagePackageImpl extends EPackageImpl implem
return (EReference)treeEClass.getEStructuralFeatures().get(0);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EReference getTree_MoreNodes()
{
return (EReference)treeEClass.getEStructuralFeatures().get(1);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@ -154,6 +176,56 @@ public class IndentationAwareTestLanguagePackageImpl extends EPackageImpl implem
return (EReference)treeNodeEClass.getEStructuralFeatures().get(1);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EClass getOtherTreeNode()
{
return otherTreeNodeEClass;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EAttribute getOtherTreeNode_Name()
{
return (EAttribute)otherTreeNodeEClass.getEStructuralFeatures().get(0);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EReference getOtherTreeNode_ChildList()
{
return (EReference)otherTreeNodeEClass.getEStructuralFeatures().get(1);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EClass getChildList()
{
return childListEClass;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EReference getChildList_Children()
{
return (EReference)childListEClass.getEStructuralFeatures().get(0);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@ -186,10 +258,18 @@ public class IndentationAwareTestLanguagePackageImpl extends EPackageImpl implem
// Create classes and their features
treeEClass = createEClass(TREE);
createEReference(treeEClass, TREE__NODES);
createEReference(treeEClass, TREE__MORE_NODES);
treeNodeEClass = createEClass(TREE_NODE);
createEAttribute(treeNodeEClass, TREE_NODE__NAME);
createEReference(treeNodeEClass, TREE_NODE__CHILDREN);
otherTreeNodeEClass = createEClass(OTHER_TREE_NODE);
createEAttribute(otherTreeNodeEClass, OTHER_TREE_NODE__NAME);
createEReference(otherTreeNodeEClass, OTHER_TREE_NODE__CHILD_LIST);
childListEClass = createEClass(CHILD_LIST);
createEReference(childListEClass, CHILD_LIST__CHILDREN);
}
/**
@ -216,9 +296,6 @@ public class IndentationAwareTestLanguagePackageImpl extends EPackageImpl implem
setNsPrefix(eNS_PREFIX);
setNsURI(eNS_URI);
// Obtain other dependent packages
EcorePackage theEcorePackage = (EcorePackage)EPackage.Registry.INSTANCE.getEPackage(EcorePackage.eNS_URI);
// Create type parameters
// Set bounds for type parameters
@ -228,11 +305,19 @@ public class IndentationAwareTestLanguagePackageImpl extends EPackageImpl implem
// Initialize classes and features; add operations and parameters
initEClass(treeEClass, Tree.class, "Tree", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEReference(getTree_Nodes(), this.getTreeNode(), null, "nodes", null, 0, -1, Tree.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getTree_MoreNodes(), this.getOtherTreeNode(), null, "moreNodes", null, 0, -1, Tree.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEClass(treeNodeEClass, TreeNode.class, "TreeNode", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEAttribute(getTreeNode_Name(), theEcorePackage.getEString(), "name", null, 0, 1, TreeNode.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getTreeNode_Name(), ecorePackage.getEString(), "name", null, 0, 1, TreeNode.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getTreeNode_Children(), this.getTreeNode(), null, "children", null, 0, -1, TreeNode.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEClass(otherTreeNodeEClass, OtherTreeNode.class, "OtherTreeNode", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEAttribute(getOtherTreeNode_Name(), ecorePackage.getEString(), "name", null, 0, 1, OtherTreeNode.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getOtherTreeNode_ChildList(), this.getChildList(), null, "childList", null, 0, 1, OtherTreeNode.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEClass(childListEClass, ChildList.class, "ChildList", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEReference(getChildList_Children(), this.getOtherTreeNode(), null, "children", null, 0, -1, ChildList.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
// Create resource
createResource(eNS_URI);
}

View file

@ -0,0 +1,266 @@
/**
* generated by Xtext
*/
package org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.ChildList;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.IndentationAwareTestLanguagePackage;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Other Tree Node</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* </p>
* <ul>
* <li>{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.OtherTreeNodeImpl#getName <em>Name</em>}</li>
* <li>{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.OtherTreeNodeImpl#getChildList <em>Child List</em>}</li>
* </ul>
*
* @generated
*/
public class OtherTreeNodeImpl extends MinimalEObjectImpl.Container implements OtherTreeNode
{
/**
* The default value of the '{@link #getName() <em>Name</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getName()
* @generated
* @ordered
*/
protected static final String NAME_EDEFAULT = null;
/**
* The cached value of the '{@link #getName() <em>Name</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getName()
* @generated
* @ordered
*/
protected String name = NAME_EDEFAULT;
/**
* The cached value of the '{@link #getChildList() <em>Child List</em>}' containment reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getChildList()
* @generated
* @ordered
*/
protected ChildList childList;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected OtherTreeNodeImpl()
{
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass()
{
return IndentationAwareTestLanguagePackage.Literals.OTHER_TREE_NODE;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String getName()
{
return name;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setName(String newName)
{
String oldName = name;
name = newName;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, IndentationAwareTestLanguagePackage.OTHER_TREE_NODE__NAME, oldName, name));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public ChildList getChildList()
{
return childList;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetChildList(ChildList newChildList, NotificationChain msgs)
{
ChildList oldChildList = childList;
childList = newChildList;
if (eNotificationRequired())
{
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, IndentationAwareTestLanguagePackage.OTHER_TREE_NODE__CHILD_LIST, oldChildList, newChildList);
if (msgs == null) msgs = notification; else msgs.add(notification);
}
return msgs;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setChildList(ChildList newChildList)
{
if (newChildList != childList)
{
NotificationChain msgs = null;
if (childList != null)
msgs = ((InternalEObject)childList).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - IndentationAwareTestLanguagePackage.OTHER_TREE_NODE__CHILD_LIST, null, msgs);
if (newChildList != null)
msgs = ((InternalEObject)newChildList).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - IndentationAwareTestLanguagePackage.OTHER_TREE_NODE__CHILD_LIST, null, msgs);
msgs = basicSetChildList(newChildList, msgs);
if (msgs != null) msgs.dispatch();
}
else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, IndentationAwareTestLanguagePackage.OTHER_TREE_NODE__CHILD_LIST, newChildList, newChildList));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
{
switch (featureID)
{
case IndentationAwareTestLanguagePackage.OTHER_TREE_NODE__CHILD_LIST:
return basicSetChildList(null, msgs);
}
return super.eInverseRemove(otherEnd, featureID, msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType)
{
switch (featureID)
{
case IndentationAwareTestLanguagePackage.OTHER_TREE_NODE__NAME:
return getName();
case IndentationAwareTestLanguagePackage.OTHER_TREE_NODE__CHILD_LIST:
return getChildList();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue)
{
switch (featureID)
{
case IndentationAwareTestLanguagePackage.OTHER_TREE_NODE__NAME:
setName((String)newValue);
return;
case IndentationAwareTestLanguagePackage.OTHER_TREE_NODE__CHILD_LIST:
setChildList((ChildList)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID)
{
switch (featureID)
{
case IndentationAwareTestLanguagePackage.OTHER_TREE_NODE__NAME:
setName(NAME_EDEFAULT);
return;
case IndentationAwareTestLanguagePackage.OTHER_TREE_NODE__CHILD_LIST:
setChildList((ChildList)null);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID)
{
switch (featureID)
{
case IndentationAwareTestLanguagePackage.OTHER_TREE_NODE__NAME:
return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
case IndentationAwareTestLanguagePackage.OTHER_TREE_NODE__CHILD_LIST:
return childList != null;
}
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public String toString()
{
if (eIsProxy()) return super.toString();
StringBuffer result = new StringBuffer(super.toString());
result.append(" (name: ");
result.append(name);
result.append(')');
return result.toString();
}
} //OtherTreeNodeImpl

View file

@ -18,6 +18,7 @@ import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.IndentationAwareTestLanguagePackage;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.TreeNode;
@ -30,6 +31,7 @@ import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.TreeNod
* </p>
* <ul>
* <li>{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.TreeImpl#getNodes <em>Nodes</em>}</li>
* <li>{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.impl.TreeImpl#getMoreNodes <em>More Nodes</em>}</li>
* </ul>
*
* @generated
@ -46,6 +48,16 @@ public class TreeImpl extends MinimalEObjectImpl.Container implements Tree
*/
protected EList<TreeNode> nodes;
/**
* The cached value of the '{@link #getMoreNodes() <em>More Nodes</em>}' containment reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getMoreNodes()
* @generated
* @ordered
*/
protected EList<OtherTreeNode> moreNodes;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@ -81,6 +93,20 @@ public class TreeImpl extends MinimalEObjectImpl.Container implements Tree
return nodes;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EList<OtherTreeNode> getMoreNodes()
{
if (moreNodes == null)
{
moreNodes = new EObjectContainmentEList<OtherTreeNode>(OtherTreeNode.class, this, IndentationAwareTestLanguagePackage.TREE__MORE_NODES);
}
return moreNodes;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@ -93,6 +119,8 @@ public class TreeImpl extends MinimalEObjectImpl.Container implements Tree
{
case IndentationAwareTestLanguagePackage.TREE__NODES:
return ((InternalEList<?>)getNodes()).basicRemove(otherEnd, msgs);
case IndentationAwareTestLanguagePackage.TREE__MORE_NODES:
return ((InternalEList<?>)getMoreNodes()).basicRemove(otherEnd, msgs);
}
return super.eInverseRemove(otherEnd, featureID, msgs);
}
@ -109,6 +137,8 @@ public class TreeImpl extends MinimalEObjectImpl.Container implements Tree
{
case IndentationAwareTestLanguagePackage.TREE__NODES:
return getNodes();
case IndentationAwareTestLanguagePackage.TREE__MORE_NODES:
return getMoreNodes();
}
return super.eGet(featureID, resolve, coreType);
}
@ -128,6 +158,10 @@ public class TreeImpl extends MinimalEObjectImpl.Container implements Tree
getNodes().clear();
getNodes().addAll((Collection<? extends TreeNode>)newValue);
return;
case IndentationAwareTestLanguagePackage.TREE__MORE_NODES:
getMoreNodes().clear();
getMoreNodes().addAll((Collection<? extends OtherTreeNode>)newValue);
return;
}
super.eSet(featureID, newValue);
}
@ -145,6 +179,9 @@ public class TreeImpl extends MinimalEObjectImpl.Container implements Tree
case IndentationAwareTestLanguagePackage.TREE__NODES:
getNodes().clear();
return;
case IndentationAwareTestLanguagePackage.TREE__MORE_NODES:
getMoreNodes().clear();
return;
}
super.eUnset(featureID);
}
@ -161,6 +198,8 @@ public class TreeImpl extends MinimalEObjectImpl.Container implements Tree
{
case IndentationAwareTestLanguagePackage.TREE__NODES:
return nodes != null && !nodes.isEmpty();
case IndentationAwareTestLanguagePackage.TREE__MORE_NODES:
return moreNodes != null && !moreNodes.isEmpty();
}
return super.eIsSet(featureID);
}

View file

@ -86,6 +86,16 @@ public class IndentationAwareTestLanguageAdapterFactory extends AdapterFactoryIm
return createTreeNodeAdapter();
}
@Override
public Adapter caseOtherTreeNode(OtherTreeNode object)
{
return createOtherTreeNodeAdapter();
}
@Override
public Adapter caseChildList(ChildList object)
{
return createChildListAdapter();
}
@Override
public Adapter defaultCase(EObject object)
{
return createEObjectAdapter();
@ -137,6 +147,36 @@ public class IndentationAwareTestLanguageAdapterFactory extends AdapterFactoryIm
return null;
}
/**
* Creates a new adapter for an object of class '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode <em>Other Tree Node</em>}'.
* <!-- begin-user-doc -->
* This default implementation returns null so that we can easily ignore cases;
* it's useful to ignore a case when inheritance will catch all the cases anyway.
* <!-- end-user-doc -->
* @return the new adapter.
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode
* @generated
*/
public Adapter createOtherTreeNodeAdapter()
{
return null;
}
/**
* Creates a new adapter for an object of class '{@link org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.ChildList <em>Child List</em>}'.
* <!-- begin-user-doc -->
* This default implementation returns null so that we can easily ignore cases;
* it's useful to ignore a case when inheritance will catch all the cases anyway.
* <!-- end-user-doc -->
* @return the new adapter.
* @see org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.ChildList
* @generated
*/
public Adapter createChildListAdapter()
{
return null;
}
/**
* Creates a new adapter for the default case.
* <!-- begin-user-doc -->

View file

@ -87,6 +87,20 @@ public class IndentationAwareTestLanguageSwitch<T> extends Switch<T>
if (result == null) result = defaultCase(theEObject);
return result;
}
case IndentationAwareTestLanguagePackage.OTHER_TREE_NODE:
{
OtherTreeNode otherTreeNode = (OtherTreeNode)theEObject;
T result = caseOtherTreeNode(otherTreeNode);
if (result == null) result = defaultCase(theEObject);
return result;
}
case IndentationAwareTestLanguagePackage.CHILD_LIST:
{
ChildList childList = (ChildList)theEObject;
T result = caseChildList(childList);
if (result == null) result = defaultCase(theEObject);
return result;
}
default: return defaultCase(theEObject);
}
}
@ -123,6 +137,38 @@ public class IndentationAwareTestLanguageSwitch<T> extends Switch<T>
return null;
}
/**
* Returns the result of interpreting the object as an instance of '<em>Other Tree Node</em>'.
* <!-- begin-user-doc -->
* This implementation returns null;
* returning a non-null result will terminate the switch.
* <!-- end-user-doc -->
* @param object the target of the switch.
* @return the result of interpreting the object as an instance of '<em>Other Tree Node</em>'.
* @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
* @generated
*/
public T caseOtherTreeNode(OtherTreeNode object)
{
return null;
}
/**
* Returns the result of interpreting the object as an instance of '<em>Child List</em>'.
* <!-- begin-user-doc -->
* This implementation returns null;
* returning a non-null result will terminate the switch.
* <!-- end-user-doc -->
* @param object the target of the switch.
* @return the result of interpreting the object as an instance of '<em>Child List</em>'.
* @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
* @generated
*/
public T caseChildList(ChildList object)
{
return null;
}
/**
* Returns the result of interpreting the object as an instance of '<em>EObject</em>'.
* <!-- begin-user-doc -->

View file

@ -95,6 +95,25 @@ ruleTree returns [EObject current=null]
}
)
)*
(
(
{
newCompositeNode(grammarAccess.getTreeAccess().getMoreNodesOtherTreeNodeParserRuleCall_2_0());
}
lv_moreNodes_2_0=ruleOtherTreeNode
{
if ($current==null) {
$current = createModelElementForParent(grammarAccess.getTreeRule());
}
add(
$current,
"moreNodes",
lv_moreNodes_2_0,
"org.eclipse.xtext.parser.indentation.IndentationAwareTestLanguage.OtherTreeNode");
afterParserOrEnumRuleCall();
}
)
)*
)
;
@ -163,3 +182,112 @@ ruleTreeNode returns [EObject current=null]
)?
)
;
// Entry rule entryRuleOtherTreeNode
entryRuleOtherTreeNode returns [EObject current=null]:
{ newCompositeNode(grammarAccess.getOtherTreeNodeRule()); }
iv_ruleOtherTreeNode=ruleOtherTreeNode
{ $current=$iv_ruleOtherTreeNode.current; }
EOF;
// Rule OtherTreeNode
ruleOtherTreeNode returns [EObject current=null]
@init {
enterRule();
}
@after {
leaveRule();
}:
(
(
(
lv_name_0_0=RULE_STRING
{
newLeafNode(lv_name_0_0, grammarAccess.getOtherTreeNodeAccess().getNameSTRINGTerminalRuleCall_0_0());
}
{
if ($current==null) {
$current = createModelElement(grammarAccess.getOtherTreeNodeRule());
}
setWithLastConsumed(
$current,
"name",
lv_name_0_0,
"org.eclipse.xtext.common.Terminals.STRING");
}
)
)
(
(
{
newCompositeNode(grammarAccess.getOtherTreeNodeAccess().getChildListChildListParserRuleCall_1_0());
}
lv_childList_1_0=ruleChildList
{
if ($current==null) {
$current = createModelElementForParent(grammarAccess.getOtherTreeNodeRule());
}
set(
$current,
"childList",
lv_childList_1_0,
"org.eclipse.xtext.parser.indentation.IndentationAwareTestLanguage.ChildList");
afterParserOrEnumRuleCall();
}
)
)?
)
;
// Entry rule entryRuleChildList
entryRuleChildList returns [EObject current=null]:
{ newCompositeNode(grammarAccess.getChildListRule()); }
iv_ruleChildList=ruleChildList
{ $current=$iv_ruleChildList.current; }
EOF;
// Rule ChildList
ruleChildList returns [EObject current=null]
@init {
enterRule();
}
@after {
leaveRule();
}:
(
(
{
$current = forceCreateModelElement(
grammarAccess.getChildListAccess().getChildListAction_0(),
$current);
}
)
this_INDENT_1=RULE_INDENT
{
newLeafNode(this_INDENT_1, grammarAccess.getChildListAccess().getINDENTTerminalRuleCall_1());
}
(
(
{
newCompositeNode(grammarAccess.getChildListAccess().getChildrenOtherTreeNodeParserRuleCall_2_0());
}
lv_children_2_0=ruleOtherTreeNode
{
if ($current==null) {
$current = createModelElementForParent(grammarAccess.getChildListRule());
}
add(
$current,
"children",
lv_children_2_0,
"org.eclipse.xtext.parser.indentation.IndentationAwareTestLanguage.OtherTreeNode");
afterParserOrEnumRuleCall();
}
)
)+
this_DEDENT_3=RULE_DEDENT
{
newLeafNode(this_DEDENT_3, grammarAccess.getChildListAccess().getDEDENTTerminalRuleCall_3());
}
)
;

View file

@ -110,22 +110,24 @@ public class InternalIndentationAwareTestLanguageParser extends AbstractInternal
// $ANTLR start "ruleTree"
// InternalIndentationAwareTestLanguageParser.g:64:1: ruleTree returns [EObject current=null] : ( () ( (lv_nodes_1_0= ruleTreeNode ) )* ) ;
// InternalIndentationAwareTestLanguageParser.g:64:1: ruleTree returns [EObject current=null] : ( () ( (lv_nodes_1_0= ruleTreeNode ) )* ( (lv_moreNodes_2_0= ruleOtherTreeNode ) )* ) ;
public final EObject ruleTree() throws RecognitionException {
EObject current = null;
EObject lv_nodes_1_0 = null;
EObject lv_moreNodes_2_0 = null;
enterRule();
try {
// InternalIndentationAwareTestLanguageParser.g:70:2: ( ( () ( (lv_nodes_1_0= ruleTreeNode ) )* ) )
// InternalIndentationAwareTestLanguageParser.g:71:2: ( () ( (lv_nodes_1_0= ruleTreeNode ) )* )
// InternalIndentationAwareTestLanguageParser.g:70:2: ( ( () ( (lv_nodes_1_0= ruleTreeNode ) )* ( (lv_moreNodes_2_0= ruleOtherTreeNode ) )* ) )
// InternalIndentationAwareTestLanguageParser.g:71:2: ( () ( (lv_nodes_1_0= ruleTreeNode ) )* ( (lv_moreNodes_2_0= ruleOtherTreeNode ) )* )
{
// InternalIndentationAwareTestLanguageParser.g:71:2: ( () ( (lv_nodes_1_0= ruleTreeNode ) )* )
// InternalIndentationAwareTestLanguageParser.g:72:3: () ( (lv_nodes_1_0= ruleTreeNode ) )*
// InternalIndentationAwareTestLanguageParser.g:71:2: ( () ( (lv_nodes_1_0= ruleTreeNode ) )* ( (lv_moreNodes_2_0= ruleOtherTreeNode ) )* )
// InternalIndentationAwareTestLanguageParser.g:72:3: () ( (lv_nodes_1_0= ruleTreeNode ) )* ( (lv_moreNodes_2_0= ruleOtherTreeNode ) )*
{
// InternalIndentationAwareTestLanguageParser.g:72:3: ()
// InternalIndentationAwareTestLanguageParser.g:73:4:
@ -187,6 +189,55 @@ public class InternalIndentationAwareTestLanguageParser extends AbstractInternal
}
} while (true);
// InternalIndentationAwareTestLanguageParser.g:98:3: ( (lv_moreNodes_2_0= ruleOtherTreeNode ) )*
loop2:
do {
int alt2=2;
int LA2_0 = input.LA(1);
if ( (LA2_0==RULE_STRING) ) {
alt2=1;
}
switch (alt2) {
case 1 :
// InternalIndentationAwareTestLanguageParser.g:99:4: (lv_moreNodes_2_0= ruleOtherTreeNode )
{
// InternalIndentationAwareTestLanguageParser.g:99:4: (lv_moreNodes_2_0= ruleOtherTreeNode )
// InternalIndentationAwareTestLanguageParser.g:100:5: lv_moreNodes_2_0= ruleOtherTreeNode
{
newCompositeNode(grammarAccess.getTreeAccess().getMoreNodesOtherTreeNodeParserRuleCall_2_0());
pushFollow(FollowSets000.FOLLOW_4);
lv_moreNodes_2_0=ruleOtherTreeNode();
state._fsp--;
if (current==null) {
current = createModelElementForParent(grammarAccess.getTreeRule());
}
add(
current,
"moreNodes",
lv_moreNodes_2_0,
"org.eclipse.xtext.parser.indentation.IndentationAwareTestLanguage.OtherTreeNode");
afterParserOrEnumRuleCall();
}
}
break;
default :
break loop2;
}
} while (true);
}
@ -210,7 +261,7 @@ public class InternalIndentationAwareTestLanguageParser extends AbstractInternal
// $ANTLR start "entryRuleTreeNode"
// InternalIndentationAwareTestLanguageParser.g:102:1: entryRuleTreeNode returns [EObject current=null] : iv_ruleTreeNode= ruleTreeNode EOF ;
// InternalIndentationAwareTestLanguageParser.g:121:1: entryRuleTreeNode returns [EObject current=null] : iv_ruleTreeNode= ruleTreeNode EOF ;
public final EObject entryRuleTreeNode() throws RecognitionException {
EObject current = null;
@ -218,8 +269,8 @@ public class InternalIndentationAwareTestLanguageParser extends AbstractInternal
try {
// InternalIndentationAwareTestLanguageParser.g:102:49: (iv_ruleTreeNode= ruleTreeNode EOF )
// InternalIndentationAwareTestLanguageParser.g:103:2: iv_ruleTreeNode= ruleTreeNode EOF
// InternalIndentationAwareTestLanguageParser.g:121:49: (iv_ruleTreeNode= ruleTreeNode EOF )
// InternalIndentationAwareTestLanguageParser.g:122:2: iv_ruleTreeNode= ruleTreeNode EOF
{
newCompositeNode(grammarAccess.getTreeNodeRule());
pushFollow(FollowSets000.FOLLOW_1);
@ -246,7 +297,7 @@ public class InternalIndentationAwareTestLanguageParser extends AbstractInternal
// $ANTLR start "ruleTreeNode"
// InternalIndentationAwareTestLanguageParser.g:109:1: ruleTreeNode returns [EObject current=null] : ( ( (lv_name_0_0= RULE_ID ) ) (this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleTreeNode ) )* this_DEDENT_3= RULE_DEDENT )? ) ;
// InternalIndentationAwareTestLanguageParser.g:128:1: ruleTreeNode returns [EObject current=null] : ( ( (lv_name_0_0= RULE_ID ) ) (this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleTreeNode ) )* this_DEDENT_3= RULE_DEDENT )? ) ;
public final EObject ruleTreeNode() throws RecognitionException {
EObject current = null;
@ -260,19 +311,19 @@ public class InternalIndentationAwareTestLanguageParser extends AbstractInternal
enterRule();
try {
// InternalIndentationAwareTestLanguageParser.g:115:2: ( ( ( (lv_name_0_0= RULE_ID ) ) (this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleTreeNode ) )* this_DEDENT_3= RULE_DEDENT )? ) )
// InternalIndentationAwareTestLanguageParser.g:116:2: ( ( (lv_name_0_0= RULE_ID ) ) (this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleTreeNode ) )* this_DEDENT_3= RULE_DEDENT )? )
// InternalIndentationAwareTestLanguageParser.g:134:2: ( ( ( (lv_name_0_0= RULE_ID ) ) (this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleTreeNode ) )* this_DEDENT_3= RULE_DEDENT )? ) )
// InternalIndentationAwareTestLanguageParser.g:135:2: ( ( (lv_name_0_0= RULE_ID ) ) (this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleTreeNode ) )* this_DEDENT_3= RULE_DEDENT )? )
{
// InternalIndentationAwareTestLanguageParser.g:116:2: ( ( (lv_name_0_0= RULE_ID ) ) (this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleTreeNode ) )* this_DEDENT_3= RULE_DEDENT )? )
// InternalIndentationAwareTestLanguageParser.g:117:3: ( (lv_name_0_0= RULE_ID ) ) (this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleTreeNode ) )* this_DEDENT_3= RULE_DEDENT )?
// InternalIndentationAwareTestLanguageParser.g:135:2: ( ( (lv_name_0_0= RULE_ID ) ) (this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleTreeNode ) )* this_DEDENT_3= RULE_DEDENT )? )
// InternalIndentationAwareTestLanguageParser.g:136:3: ( (lv_name_0_0= RULE_ID ) ) (this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleTreeNode ) )* this_DEDENT_3= RULE_DEDENT )?
{
// InternalIndentationAwareTestLanguageParser.g:117:3: ( (lv_name_0_0= RULE_ID ) )
// InternalIndentationAwareTestLanguageParser.g:118:4: (lv_name_0_0= RULE_ID )
// InternalIndentationAwareTestLanguageParser.g:136:3: ( (lv_name_0_0= RULE_ID ) )
// InternalIndentationAwareTestLanguageParser.g:137:4: (lv_name_0_0= RULE_ID )
{
// InternalIndentationAwareTestLanguageParser.g:118:4: (lv_name_0_0= RULE_ID )
// InternalIndentationAwareTestLanguageParser.g:119:5: lv_name_0_0= RULE_ID
// InternalIndentationAwareTestLanguageParser.g:137:4: (lv_name_0_0= RULE_ID )
// InternalIndentationAwareTestLanguageParser.g:138:5: lv_name_0_0= RULE_ID
{
lv_name_0_0=(Token)match(input,RULE_ID,FollowSets000.FOLLOW_4);
lv_name_0_0=(Token)match(input,RULE_ID,FollowSets000.FOLLOW_5);
newLeafNode(lv_name_0_0, grammarAccess.getTreeNodeAccess().getNameIDTerminalRuleCall_0_0());
@ -292,43 +343,43 @@ public class InternalIndentationAwareTestLanguageParser extends AbstractInternal
}
// InternalIndentationAwareTestLanguageParser.g:135:3: (this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleTreeNode ) )* this_DEDENT_3= RULE_DEDENT )?
int alt3=2;
int LA3_0 = input.LA(1);
// InternalIndentationAwareTestLanguageParser.g:154:3: (this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleTreeNode ) )* this_DEDENT_3= RULE_DEDENT )?
int alt4=2;
int LA4_0 = input.LA(1);
if ( (LA3_0==RULE_INDENT) ) {
alt3=1;
if ( (LA4_0==RULE_INDENT) ) {
alt4=1;
}
switch (alt3) {
switch (alt4) {
case 1 :
// InternalIndentationAwareTestLanguageParser.g:136:4: this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleTreeNode ) )* this_DEDENT_3= RULE_DEDENT
// InternalIndentationAwareTestLanguageParser.g:155:4: this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleTreeNode ) )* this_DEDENT_3= RULE_DEDENT
{
this_INDENT_1=(Token)match(input,RULE_INDENT,FollowSets000.FOLLOW_5);
this_INDENT_1=(Token)match(input,RULE_INDENT,FollowSets000.FOLLOW_6);
newLeafNode(this_INDENT_1, grammarAccess.getTreeNodeAccess().getINDENTTerminalRuleCall_1_0());
// InternalIndentationAwareTestLanguageParser.g:140:4: ( (lv_children_2_0= ruleTreeNode ) )*
loop2:
// InternalIndentationAwareTestLanguageParser.g:159:4: ( (lv_children_2_0= ruleTreeNode ) )*
loop3:
do {
int alt2=2;
int LA2_0 = input.LA(1);
int alt3=2;
int LA3_0 = input.LA(1);
if ( (LA2_0==RULE_ID) ) {
alt2=1;
if ( (LA3_0==RULE_ID) ) {
alt3=1;
}
switch (alt2) {
switch (alt3) {
case 1 :
// InternalIndentationAwareTestLanguageParser.g:141:5: (lv_children_2_0= ruleTreeNode )
// InternalIndentationAwareTestLanguageParser.g:160:5: (lv_children_2_0= ruleTreeNode )
{
// InternalIndentationAwareTestLanguageParser.g:141:5: (lv_children_2_0= ruleTreeNode )
// InternalIndentationAwareTestLanguageParser.g:142:6: lv_children_2_0= ruleTreeNode
// InternalIndentationAwareTestLanguageParser.g:160:5: (lv_children_2_0= ruleTreeNode )
// InternalIndentationAwareTestLanguageParser.g:161:6: lv_children_2_0= ruleTreeNode
{
newCompositeNode(grammarAccess.getTreeNodeAccess().getChildrenTreeNodeParserRuleCall_1_1_0());
pushFollow(FollowSets000.FOLLOW_5);
pushFollow(FollowSets000.FOLLOW_6);
lv_children_2_0=ruleTreeNode();
state._fsp--;
@ -352,7 +403,7 @@ public class InternalIndentationAwareTestLanguageParser extends AbstractInternal
break;
default :
break loop2;
break loop3;
}
} while (true);
@ -387,6 +438,302 @@ public class InternalIndentationAwareTestLanguageParser extends AbstractInternal
}
// $ANTLR end "ruleTreeNode"
// $ANTLR start "entryRuleOtherTreeNode"
// InternalIndentationAwareTestLanguageParser.g:187:1: entryRuleOtherTreeNode returns [EObject current=null] : iv_ruleOtherTreeNode= ruleOtherTreeNode EOF ;
public final EObject entryRuleOtherTreeNode() throws RecognitionException {
EObject current = null;
EObject iv_ruleOtherTreeNode = null;
try {
// InternalIndentationAwareTestLanguageParser.g:187:54: (iv_ruleOtherTreeNode= ruleOtherTreeNode EOF )
// InternalIndentationAwareTestLanguageParser.g:188:2: iv_ruleOtherTreeNode= ruleOtherTreeNode EOF
{
newCompositeNode(grammarAccess.getOtherTreeNodeRule());
pushFollow(FollowSets000.FOLLOW_1);
iv_ruleOtherTreeNode=ruleOtherTreeNode();
state._fsp--;
current =iv_ruleOtherTreeNode;
match(input,EOF,FollowSets000.FOLLOW_2);
}
}
catch (RecognitionException re) {
recover(input,re);
appendSkippedTokens();
}
finally {
}
return current;
}
// $ANTLR end "entryRuleOtherTreeNode"
// $ANTLR start "ruleOtherTreeNode"
// InternalIndentationAwareTestLanguageParser.g:194:1: ruleOtherTreeNode returns [EObject current=null] : ( ( (lv_name_0_0= RULE_STRING ) ) ( (lv_childList_1_0= ruleChildList ) )? ) ;
public final EObject ruleOtherTreeNode() throws RecognitionException {
EObject current = null;
Token lv_name_0_0=null;
EObject lv_childList_1_0 = null;
enterRule();
try {
// InternalIndentationAwareTestLanguageParser.g:200:2: ( ( ( (lv_name_0_0= RULE_STRING ) ) ( (lv_childList_1_0= ruleChildList ) )? ) )
// InternalIndentationAwareTestLanguageParser.g:201:2: ( ( (lv_name_0_0= RULE_STRING ) ) ( (lv_childList_1_0= ruleChildList ) )? )
{
// InternalIndentationAwareTestLanguageParser.g:201:2: ( ( (lv_name_0_0= RULE_STRING ) ) ( (lv_childList_1_0= ruleChildList ) )? )
// InternalIndentationAwareTestLanguageParser.g:202:3: ( (lv_name_0_0= RULE_STRING ) ) ( (lv_childList_1_0= ruleChildList ) )?
{
// InternalIndentationAwareTestLanguageParser.g:202:3: ( (lv_name_0_0= RULE_STRING ) )
// InternalIndentationAwareTestLanguageParser.g:203:4: (lv_name_0_0= RULE_STRING )
{
// InternalIndentationAwareTestLanguageParser.g:203:4: (lv_name_0_0= RULE_STRING )
// InternalIndentationAwareTestLanguageParser.g:204:5: lv_name_0_0= RULE_STRING
{
lv_name_0_0=(Token)match(input,RULE_STRING,FollowSets000.FOLLOW_5);
newLeafNode(lv_name_0_0, grammarAccess.getOtherTreeNodeAccess().getNameSTRINGTerminalRuleCall_0_0());
if (current==null) {
current = createModelElement(grammarAccess.getOtherTreeNodeRule());
}
setWithLastConsumed(
current,
"name",
lv_name_0_0,
"org.eclipse.xtext.common.Terminals.STRING");
}
}
// InternalIndentationAwareTestLanguageParser.g:220:3: ( (lv_childList_1_0= ruleChildList ) )?
int alt5=2;
int LA5_0 = input.LA(1);
if ( (LA5_0==RULE_INDENT) ) {
alt5=1;
}
switch (alt5) {
case 1 :
// InternalIndentationAwareTestLanguageParser.g:221:4: (lv_childList_1_0= ruleChildList )
{
// InternalIndentationAwareTestLanguageParser.g:221:4: (lv_childList_1_0= ruleChildList )
// InternalIndentationAwareTestLanguageParser.g:222:5: lv_childList_1_0= ruleChildList
{
newCompositeNode(grammarAccess.getOtherTreeNodeAccess().getChildListChildListParserRuleCall_1_0());
pushFollow(FollowSets000.FOLLOW_2);
lv_childList_1_0=ruleChildList();
state._fsp--;
if (current==null) {
current = createModelElementForParent(grammarAccess.getOtherTreeNodeRule());
}
set(
current,
"childList",
lv_childList_1_0,
"org.eclipse.xtext.parser.indentation.IndentationAwareTestLanguage.ChildList");
afterParserOrEnumRuleCall();
}
}
break;
}
}
}
leaveRule();
}
catch (RecognitionException re) {
recover(input,re);
appendSkippedTokens();
}
finally {
}
return current;
}
// $ANTLR end "ruleOtherTreeNode"
// $ANTLR start "entryRuleChildList"
// InternalIndentationAwareTestLanguageParser.g:243:1: entryRuleChildList returns [EObject current=null] : iv_ruleChildList= ruleChildList EOF ;
public final EObject entryRuleChildList() throws RecognitionException {
EObject current = null;
EObject iv_ruleChildList = null;
try {
// InternalIndentationAwareTestLanguageParser.g:243:50: (iv_ruleChildList= ruleChildList EOF )
// InternalIndentationAwareTestLanguageParser.g:244:2: iv_ruleChildList= ruleChildList EOF
{
newCompositeNode(grammarAccess.getChildListRule());
pushFollow(FollowSets000.FOLLOW_1);
iv_ruleChildList=ruleChildList();
state._fsp--;
current =iv_ruleChildList;
match(input,EOF,FollowSets000.FOLLOW_2);
}
}
catch (RecognitionException re) {
recover(input,re);
appendSkippedTokens();
}
finally {
}
return current;
}
// $ANTLR end "entryRuleChildList"
// $ANTLR start "ruleChildList"
// InternalIndentationAwareTestLanguageParser.g:250:1: ruleChildList returns [EObject current=null] : ( () this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleOtherTreeNode ) )+ this_DEDENT_3= RULE_DEDENT ) ;
public final EObject ruleChildList() throws RecognitionException {
EObject current = null;
Token this_INDENT_1=null;
Token this_DEDENT_3=null;
EObject lv_children_2_0 = null;
enterRule();
try {
// InternalIndentationAwareTestLanguageParser.g:256:2: ( ( () this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleOtherTreeNode ) )+ this_DEDENT_3= RULE_DEDENT ) )
// InternalIndentationAwareTestLanguageParser.g:257:2: ( () this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleOtherTreeNode ) )+ this_DEDENT_3= RULE_DEDENT )
{
// InternalIndentationAwareTestLanguageParser.g:257:2: ( () this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleOtherTreeNode ) )+ this_DEDENT_3= RULE_DEDENT )
// InternalIndentationAwareTestLanguageParser.g:258:3: () this_INDENT_1= RULE_INDENT ( (lv_children_2_0= ruleOtherTreeNode ) )+ this_DEDENT_3= RULE_DEDENT
{
// InternalIndentationAwareTestLanguageParser.g:258:3: ()
// InternalIndentationAwareTestLanguageParser.g:259:4:
{
current = forceCreateModelElement(
grammarAccess.getChildListAccess().getChildListAction_0(),
current);
}
this_INDENT_1=(Token)match(input,RULE_INDENT,FollowSets000.FOLLOW_7);
newLeafNode(this_INDENT_1, grammarAccess.getChildListAccess().getINDENTTerminalRuleCall_1());
// InternalIndentationAwareTestLanguageParser.g:269:3: ( (lv_children_2_0= ruleOtherTreeNode ) )+
int cnt6=0;
loop6:
do {
int alt6=2;
int LA6_0 = input.LA(1);
if ( (LA6_0==RULE_STRING) ) {
alt6=1;
}
switch (alt6) {
case 1 :
// InternalIndentationAwareTestLanguageParser.g:270:4: (lv_children_2_0= ruleOtherTreeNode )
{
// InternalIndentationAwareTestLanguageParser.g:270:4: (lv_children_2_0= ruleOtherTreeNode )
// InternalIndentationAwareTestLanguageParser.g:271:5: lv_children_2_0= ruleOtherTreeNode
{
newCompositeNode(grammarAccess.getChildListAccess().getChildrenOtherTreeNodeParserRuleCall_2_0());
pushFollow(FollowSets000.FOLLOW_8);
lv_children_2_0=ruleOtherTreeNode();
state._fsp--;
if (current==null) {
current = createModelElementForParent(grammarAccess.getChildListRule());
}
add(
current,
"children",
lv_children_2_0,
"org.eclipse.xtext.parser.indentation.IndentationAwareTestLanguage.OtherTreeNode");
afterParserOrEnumRuleCall();
}
}
break;
default :
if ( cnt6 >= 1 ) break loop6;
EarlyExitException eee =
new EarlyExitException(6, input);
throw eee;
}
cnt6++;
} while (true);
this_DEDENT_3=(Token)match(input,RULE_DEDENT,FollowSets000.FOLLOW_2);
newLeafNode(this_DEDENT_3, grammarAccess.getChildListAccess().getDEDENTTerminalRuleCall_3());
}
}
leaveRule();
}
catch (RecognitionException re) {
recover(input,re);
appendSkippedTokens();
}
finally {
}
return current;
}
// $ANTLR end "ruleChildList"
// Delegated rules
@ -396,9 +743,12 @@ public class InternalIndentationAwareTestLanguageParser extends AbstractInternal
private static class FollowSets000 {
public static final BitSet FOLLOW_1 = new BitSet(new long[]{0x0000000000000000L});
public static final BitSet FOLLOW_2 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_3 = new BitSet(new long[]{0x0000000000000082L});
public static final BitSet FOLLOW_4 = new BitSet(new long[]{0x0000000000000022L});
public static final BitSet FOLLOW_5 = new BitSet(new long[]{0x00000000000000C0L});
public static final BitSet FOLLOW_3 = new BitSet(new long[]{0x0000000000000282L});
public static final BitSet FOLLOW_4 = new BitSet(new long[]{0x0000000000000202L});
public static final BitSet FOLLOW_5 = new BitSet(new long[]{0x0000000000000022L});
public static final BitSet FOLLOW_6 = new BitSet(new long[]{0x00000000000002C0L});
public static final BitSet FOLLOW_7 = new BitSet(new long[]{0x0000000000000200L});
public static final BitSet FOLLOW_8 = new BitSet(new long[]{0x0000000000000240L});
}

View file

@ -10,7 +10,9 @@ import org.eclipse.emf.ecore.EPackage;
import org.eclipse.xtext.Action;
import org.eclipse.xtext.Parameter;
import org.eclipse.xtext.ParserRule;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.ChildList;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.IndentationAwareTestLanguagePackage;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.TreeNode;
import org.eclipse.xtext.parser.indentation.services.IndentationAwareTestLanguageGrammarAccess;
@ -31,6 +33,12 @@ public abstract class AbstractIndentationAwareTestLanguageSemanticSequencer exte
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == IndentationAwareTestLanguagePackage.eINSTANCE)
switch (semanticObject.eClass().getClassifierID()) {
case IndentationAwareTestLanguagePackage.CHILD_LIST:
sequence_ChildList(context, (ChildList) semanticObject);
return;
case IndentationAwareTestLanguagePackage.OTHER_TREE_NODE:
sequence_OtherTreeNode(context, (OtherTreeNode) semanticObject);
return;
case IndentationAwareTestLanguagePackage.TREE:
sequence_Tree(context, (Tree) semanticObject);
return;
@ -42,6 +50,30 @@ public abstract class AbstractIndentationAwareTestLanguageSemanticSequencer exte
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
/**
* Contexts:
* ChildList returns ChildList
*
* Constraint:
* children+=OtherTreeNode+
*/
protected void sequence_ChildList(ISerializationContext context, ChildList semanticObject) {
genericSequencer.createSequence(context, semanticObject);
}
/**
* Contexts:
* OtherTreeNode returns OtherTreeNode
*
* Constraint:
* (name=STRING childList=ChildList?)
*/
protected void sequence_OtherTreeNode(ISerializationContext context, OtherTreeNode semanticObject) {
genericSequencer.createSequence(context, semanticObject);
}
/**
* Contexts:
* TreeNode returns TreeNode
@ -59,7 +91,7 @@ public abstract class AbstractIndentationAwareTestLanguageSemanticSequencer exte
* Tree returns Tree
*
* Constraint:
* nodes+=TreeNode*
* (nodes+=TreeNode* moreNodes+=OtherTreeNode*)
*/
protected void sequence_Tree(ISerializationContext context, Tree semanticObject) {
genericSequencer.createSequence(context, semanticObject);

View file

@ -27,12 +27,15 @@ public class IndentationAwareTestLanguageGrammarAccess extends AbstractGrammarEl
private final Action cTreeAction_0 = (Action)cGroup.eContents().get(0);
private final Assignment cNodesAssignment_1 = (Assignment)cGroup.eContents().get(1);
private final RuleCall cNodesTreeNodeParserRuleCall_1_0 = (RuleCall)cNodesAssignment_1.eContents().get(0);
private final Assignment cMoreNodesAssignment_2 = (Assignment)cGroup.eContents().get(2);
private final RuleCall cMoreNodesOtherTreeNodeParserRuleCall_2_0 = (RuleCall)cMoreNodesAssignment_2.eContents().get(0);
//Tree:
// {Tree} nodes+=TreeNode*;
// {Tree} nodes+=TreeNode*
// moreNodes+=OtherTreeNode*;
@Override public ParserRule getRule() { return rule; }
//{Tree} nodes+=TreeNode*
//{Tree} nodes+=TreeNode* moreNodes+=OtherTreeNode*
public Group getGroup() { return cGroup; }
//{Tree}
@ -43,6 +46,12 @@ public class IndentationAwareTestLanguageGrammarAccess extends AbstractGrammarEl
//TreeNode
public RuleCall getNodesTreeNodeParserRuleCall_1_0() { return cNodesTreeNodeParserRuleCall_1_0; }
//moreNodes+=OtherTreeNode*
public Assignment getMoreNodesAssignment_2() { return cMoreNodesAssignment_2; }
//OtherTreeNode
public RuleCall getMoreNodesOtherTreeNodeParserRuleCall_2_0() { return cMoreNodesOtherTreeNodeParserRuleCall_2_0; }
}
public class TreeNodeElements extends AbstractParserRuleElementFinder {
private final ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.xtext.parser.indentation.IndentationAwareTestLanguage.TreeNode");
@ -85,10 +94,73 @@ public class IndentationAwareTestLanguageGrammarAccess extends AbstractGrammarEl
//DEDENT
public RuleCall getDEDENTTerminalRuleCall_1_2() { return cDEDENTTerminalRuleCall_1_2; }
}
public class OtherTreeNodeElements extends AbstractParserRuleElementFinder {
private final ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.xtext.parser.indentation.IndentationAwareTestLanguage.OtherTreeNode");
private final Group cGroup = (Group)rule.eContents().get(1);
private final Assignment cNameAssignment_0 = (Assignment)cGroup.eContents().get(0);
private final RuleCall cNameSTRINGTerminalRuleCall_0_0 = (RuleCall)cNameAssignment_0.eContents().get(0);
private final Assignment cChildListAssignment_1 = (Assignment)cGroup.eContents().get(1);
private final RuleCall cChildListChildListParserRuleCall_1_0 = (RuleCall)cChildListAssignment_1.eContents().get(0);
//OtherTreeNode:
// name=STRING
// childList=ChildList?;
@Override public ParserRule getRule() { return rule; }
//name=STRING childList=ChildList?
public Group getGroup() { return cGroup; }
//name=STRING
public Assignment getNameAssignment_0() { return cNameAssignment_0; }
//STRING
public RuleCall getNameSTRINGTerminalRuleCall_0_0() { return cNameSTRINGTerminalRuleCall_0_0; }
//childList=ChildList?
public Assignment getChildListAssignment_1() { return cChildListAssignment_1; }
//ChildList
public RuleCall getChildListChildListParserRuleCall_1_0() { return cChildListChildListParserRuleCall_1_0; }
}
public class ChildListElements extends AbstractParserRuleElementFinder {
private final ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.xtext.parser.indentation.IndentationAwareTestLanguage.ChildList");
private final Group cGroup = (Group)rule.eContents().get(1);
private final Action cChildListAction_0 = (Action)cGroup.eContents().get(0);
private final RuleCall cINDENTTerminalRuleCall_1 = (RuleCall)cGroup.eContents().get(1);
private final Assignment cChildrenAssignment_2 = (Assignment)cGroup.eContents().get(2);
private final RuleCall cChildrenOtherTreeNodeParserRuleCall_2_0 = (RuleCall)cChildrenAssignment_2.eContents().get(0);
private final RuleCall cDEDENTTerminalRuleCall_3 = (RuleCall)cGroup.eContents().get(3);
//ChildList:
// {ChildList} INDENT
// children+=OtherTreeNode+
// DEDENT;
@Override public ParserRule getRule() { return rule; }
//{ChildList} INDENT children+=OtherTreeNode+ DEDENT
public Group getGroup() { return cGroup; }
//{ChildList}
public Action getChildListAction_0() { return cChildListAction_0; }
//INDENT
public RuleCall getINDENTTerminalRuleCall_1() { return cINDENTTerminalRuleCall_1; }
//children+=OtherTreeNode+
public Assignment getChildrenAssignment_2() { return cChildrenAssignment_2; }
//OtherTreeNode
public RuleCall getChildrenOtherTreeNodeParserRuleCall_2_0() { return cChildrenOtherTreeNodeParserRuleCall_2_0; }
//DEDENT
public RuleCall getDEDENTTerminalRuleCall_3() { return cDEDENTTerminalRuleCall_3; }
}
private final TreeElements pTree;
private final TreeNodeElements pTreeNode;
private final OtherTreeNodeElements pOtherTreeNode;
private final ChildListElements pChildList;
private final TerminalRule tSL_COMMENT;
private final TerminalRule tINDENT;
private final TerminalRule tDEDENT;
@ -104,6 +176,8 @@ public class IndentationAwareTestLanguageGrammarAccess extends AbstractGrammarEl
this.gaTerminals = gaTerminals;
this.pTree = new TreeElements();
this.pTreeNode = new TreeNodeElements();
this.pOtherTreeNode = new OtherTreeNodeElements();
this.pChildList = new ChildListElements();
this.tSL_COMMENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.xtext.parser.indentation.IndentationAwareTestLanguage.SL_COMMENT");
this.tINDENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.xtext.parser.indentation.IndentationAwareTestLanguage.INDENT");
this.tDEDENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.xtext.parser.indentation.IndentationAwareTestLanguage.DEDENT");
@ -137,7 +211,8 @@ public class IndentationAwareTestLanguageGrammarAccess extends AbstractGrammarEl
//Tree:
// {Tree} nodes+=TreeNode*;
// {Tree} nodes+=TreeNode*
// moreNodes+=OtherTreeNode*;
public TreeElements getTreeAccess() {
return pTree;
}
@ -158,6 +233,29 @@ public class IndentationAwareTestLanguageGrammarAccess extends AbstractGrammarEl
return getTreeNodeAccess().getRule();
}
//OtherTreeNode:
// name=STRING
// childList=ChildList?;
public OtherTreeNodeElements getOtherTreeNodeAccess() {
return pOtherTreeNode;
}
public ParserRule getOtherTreeNodeRule() {
return getOtherTreeNodeAccess().getRule();
}
//ChildList:
// {ChildList} INDENT
// children+=OtherTreeNode+
// DEDENT;
public ChildListElements getChildListAccess() {
return pChildList;
}
public ParserRule getChildListRule() {
return getChildListAccess().getRule();
}
//@ Override terminal SL_COMMENT:
// '//' !('\n' | '\r')*;
public TerminalRule getSL_COMMENTRule() {

View file

@ -10,6 +10,7 @@ package org.eclipse.xtext.parser.indentation
import com.google.inject.Inject
import org.eclipse.xtend2.lib.StringConcatenation
import org.eclipse.xtext.nodemodel.impl.InvariantChecker
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.TreeNode
import org.eclipse.xtext.parser.indentation.tests.IndentationAwareTestLanguageInjectorProvider
@ -66,6 +67,71 @@ class IndentationAwareLanguageTest {
assertEquals('second', tree.nodes.last.name)
}
@Test
def void testIgnoreEmptyLines_1() {
val tree = '''
first
second
'''.parse
assertNotNull(tree)
assertEquals(2, tree.nodes.size)
assertEquals('first', tree.nodes.head.name)
assertEquals(0, tree.nodes.head.children.size)
assertEquals('second', tree.nodes.last.name)
}
@Test
def void testIgnoreEmptyLines_2() {
val tree = '''
"first"
"second"
'''.parse
assertNotNull(tree)
assertEquals(2, tree.moreNodes.size)
assertEquals('first', tree.moreNodes.head.name)
assertNull(tree.moreNodes.head.childList)
assertEquals('second', tree.moreNodes.last.name)
}
@Test
def void testIgnoreEmptyLines_3() {
val tree = 'first\n\t'.parse
assertNotNull(tree)
assertEquals(1, tree.nodes.size)
assertEquals('first', tree.nodes.head.name)
assertEquals(0, tree.nodes.head.children.size)
}
@Test
def void testIgnoreEmptyLines_4() {
val tree = '"first"\n\t'.parse
assertNotNull(tree)
assertEquals(1, tree.moreNodes.size)
assertEquals('first', tree.moreNodes.head.name)
assertNull(tree.moreNodes.head.childList)
}
@Test
def void testIgnoreEmptyLines_5() {
val tree = 'first\n\t\tabc\n\t'.parse
assertNotNull(tree)
assertEquals(1, tree.nodes.size)
assertEquals('first', tree.nodes.head.name)
assertEquals(1, tree.nodes.head.children.size)
}
@Test
def void testIgnoreEmptyLines_6() {
val tree = '"first"\n\t\t"abc"\n\t'.parse
assertNotNull(tree)
assertEquals(1, tree.moreNodes.size)
assertEquals('first', tree.moreNodes.head.name)
assertNotNull(tree.moreNodes.head.childList)
assertEquals(1, tree.moreNodes.head.childList.children.size)
}
@Test
def void testParentChild() {
val tree = '''
@ -214,6 +280,52 @@ class IndentationAwareLanguageTest {
'''.toString.assertEquals(tree.asText)
}
@Test
def void testTree_06() {
val tree = '''
"a"
"b"
'''.parseAndValidate
'''
a
b
'''.toString.assertEquals(tree.asText)
}
@Test
def void testTree_07() {
val tree = '''
"a"
"b"
'''.parseAndValidate
'''
a
b
'''.toString.assertEquals(tree.asText)
}
@Test
def void testTree_08() {
val tree = '''
"a"
"1"
"2"
"b"
"3"
'''.parseAndValidate
'''
a
>
1
2
b
>
3
'''.toString.assertEquals(tree.asText)
}
private def parseAndValidate(CharSequence s) {
val result = s.parse
result.assertNoIssues
@ -227,6 +339,9 @@ class IndentationAwareLanguageTest {
«FOR node: tree.nodes»
«node.asText»
«ENDFOR»
«FOR node: tree.moreNodes»
«node.asText»
«ENDFOR»
'''
private def StringConcatenation asText(TreeNode treeNode) '''
@ -236,4 +351,14 @@ class IndentationAwareLanguageTest {
«ENDFOR»
'''
private def StringConcatenation asText(OtherTreeNode treeNode) '''
«treeNode.name»
«IF treeNode.childList !== null»
>
«FOR node: treeNode.childList.children»
«node.asText»
«ENDFOR»
«ENDIF»
'''
}

View file

@ -11,6 +11,7 @@ generate indentationAwareTestLanguage "http://www.eclipse.org/2015/tmf/xtext/ind
Tree: {Tree}
nodes+=TreeNode*
moreNodes+=OtherTreeNode*
;
TreeNode:
@ -20,6 +21,17 @@ TreeNode:
DEDENT)?
;
OtherTreeNode:
name=STRING
childList = ChildList?
;
ChildList: {ChildList}
INDENT
children+=OtherTreeNode+
DEDENT
;
@Override
terminal SL_COMMENT: '//' !('\n'|'\r')*;

View file

@ -0,0 +1,381 @@
/*******************************************************************************
* Copyright (c) 2017 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.xtext.parser.indentation
import com.google.inject.Inject
import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.AbstractRule
import org.eclipse.xtext.Action
import org.eclipse.xtext.Keyword
import org.eclipse.xtext.RuleCall
import org.eclipse.xtext.nodemodel.INode
import org.eclipse.xtext.nodemodel.impl.InvariantChecker
import org.eclipse.xtext.nodemodel.util.NodeModelUtils
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree
import org.eclipse.xtext.parser.indentation.tests.IndentationAwareTestLanguageInjectorProvider
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.util.ParseHelper
import org.junit.Test
import org.junit.runner.RunWith
import static extension org.junit.Assert.*
/**
* @author Sebastian Zarnekow - Initial contribution and API
*/
@RunWith(XtextRunner)
@InjectWith(IndentationAwareTestLanguageInjectorProvider)
class NodeModelTest {
@Inject ParseHelper<Tree> parseHelper
@Inject
extension InvariantChecker invariantChecker
@Test
def void testEmptyTree() {
val tree = ''.rootNode
''.assertEquals(tree.asText)
}
@Test
def void testSingleRootNode() {
val tree = 'root'.rootNode
'''
[ID:root]
'''.toString.trim.assertEquals(tree.asText)
}
@Test
def void testTwoRootNodes() {
val tree = '''
first
second
'''.rootNode
'''
[ID:first][-WS:
][ID:second][-WS:
]
'''.toString.trim.assertEquals(tree.asText)
}
@Test
def void testParentChild() {
val tree = '''
parent
child
'''.rootNode
'''
[ID:parent][-WS:
\t][INDENT:][ID:child][-WS:
][DEDENT:]
'''.toString.trim.assertEquals(tree.asText)
}
@Test
def void testParentChildWithEof() {
val tree = '''
parent
child
'''.toString.trim.rootNode
'''
[ID:parent][-WS:
\t][INDENT:][ID:child][DEDENT:]
'''.toString.trim.assertEquals(tree.asText)
}
@Test
def void testParentChildren() {
val tree = '''
parent
child
child
'''.rootNode
'''
[ID:parent][-WS:
\t][INDENT:][ID:child][-WS:
\t][ID:child][-WS:
][DEDENT:]
'''.toString.trim.assertEquals(tree.asText)
}
@Test
def void testTree_01() {
val tree = '''
a
b
c
d
'''.rootNode
'''
[ID:a][-WS:
\t][INDENT:][ID:b][-WS:
\t ][INDENT:][ID:c][-WS:
][DEDENT:][-WS:\t][ID:d][-WS:
][DEDENT:]
'''.toString.trim.assertEquals(tree.asText)
}
@Test
def void testWeirdTree() {
val tree = '''
root
s4
s8
s6
'''.rootNode
'''
[ID:root][-WS:
][INDENT:][ID:s4][-WS:
][INDENT:][ID:s8][-WS:
][DEDENT:][-WS: ][INDENT:][ID:s6][-WS:
][DEDENT:][DEDENT:]
'''.toString.trim.assertEquals(tree.asText)
}
@Test
def void testWeirdTreeEof() {
val tree = '''
root
s4
s8
s6
'''.toString.trim.rootNode
'''
[ID:root][-WS:
][INDENT:][ID:s4][-WS:
][INDENT:][ID:s8][-WS:
][DEDENT:][-WS: ][INDENT:][ID:s6][DEDENT:][DEDENT:]
'''.toString.trim.assertEquals(tree.asText)
}
@Test
def void testIgnoreEmptyLines_1() {
val tree = '''
first
second
'''.rootNode
'''
[ID:first][-WS:
\t
][ID:second][-WS:
]
'''.toString.trim.assertEquals(tree.asText)
}
@Test
def void testIgnoreEmptyLines_2() {
val tree = '''
"first"
"second"
'''.rootNode
'''
[STRING:"first"][-WS:
\t
][STRING:"second"][-WS:
]
'''.toString.trim.assertEquals(tree.asText)
}
@Test
def void testIgnoreEmptyLines_3() {
val tree = 'first\n\t'.rootNode
'''
[ID:first][-WS:
\t]
'''.toString.trim.assertEquals(tree.asText)
}
@Test
def void testIgnoreEmptyLines_4() {
// first<LB>
// abc<LB>
// <EOF>
val tree = 'first\n\t\tabc\n\t'.rootNode
'''
[ID:first][-WS:
\t\t][INDENT:][ID:abc][-WS:
][DEDENT:][-WS:\t]
'''.toString.trim.assertEquals(tree.asText)
}
// @Test
// def void testTree_02() {
// val tree = '''
// a
// b
// c
// d
// e
// f
// g
// h
// '''.parseAndValidate
// '''
// a
// b
// c
// d
// e
// f
// g
// h
// '''.toString.assertEquals(tree.asText)
// }
//
// @Test
// def void testTree_03() {
// val tree = '''
// a
// b // single tab
// c // 8 spaces eq 1 tab
// d
// '''.parseAndValidate
// '''
// a
// b
// c
// d
// '''.toString.assertEquals(tree.asText)
// }
//
// @Test
// def void testTree_04() {
// val tree = '''
// level0_1
// level1_1
// level1_2
// level2_1
// level2_2
// level1_3
// level2_3
// level2_4
// level3_1
// level3_2
// level2_5
// level1_4
// level2_6
// level0_2
// level1_5
// level2_7
// level3_8
// level4_9
// '''.parseAndValidate
// '''
// level0_1
// level1_1
// level1_2
// level2_1
// level2_2
// level1_3
// level2_3
// level2_4
// level3_1
// level3_2
// level2_5
// level1_4
// level2_6
// level0_2
// level1_5
// level2_7
// level3_8
// level4_9
// '''.toString.assertEquals(tree.asText)
// }
//
// @Test
// def void testTree_05() {
// val tree = '''
// a
// x
// b // two tabs
// c // tab and 8 spaces (eq 2 tabs)
// y
// '''.parseAndValidate
// '''
// a
// x
// b
// c
// y
// '''.toString.assertEquals(tree.asText)
// }
//
// @Test
// def void testTree_06() {
// val tree = '''
// "a"
// "b"
// '''.parseAndValidate
// '''
// a
// b
// '''.toString.assertEquals(tree.asText)
// }
//
// @Test
// def void testTree_07() {
// val tree = '''
// "a"
//
// "b"
//
// '''.parseAndValidate
// '''
// a
// >
// b
// >
// '''.toString.assertEquals(tree.asText)
// }
//
// @Test
// def void testTree_08() {
// val tree = '''
// "a"
// "1"
// "2"
// "b"
// "3"
// '''.parseAndValidate
// '''
// a
// >
// 1
// 2
// b
// >
// 3
// '''.toString.assertEquals(tree.asText)
// }
private def getRootNode(CharSequence seq) {
val model = parseHelper.parse(seq);
val result = NodeModelUtils.getNode(model).rootNode
result.checkInvariant
return result
}
private def String asText(INode node) {
node.leafNodes.filter[!(grammarElement instanceof Action)].join('[', '][', ']') [
(if (isHidden) '-' else '') + grammarElement.tokenType + ':' + text.replace('\t', '\\t')
]
}
private def String tokenType(EObject obj) {
switch(obj) {
RuleCall: obj.rule.name
Keyword: obj.value
AbstractRule: obj.name
}
}
}

View file

@ -13,6 +13,8 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.nodemodel.ICompositeNode;
import org.eclipse.xtext.nodemodel.impl.InvariantChecker;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.ChildList;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.TreeNode;
import org.eclipse.xtext.parser.indentation.tests.IndentationAwareTestLanguageInjectorProvider;
@ -88,6 +90,101 @@ public class IndentationAwareLanguageTest {
}
}
@Test
public void testIgnoreEmptyLines_1() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("first");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("second");
_builder.newLine();
final Tree tree = this.parseHelper.parse(_builder);
Assert.assertNotNull(tree);
Assert.assertEquals(2, tree.getNodes().size());
Assert.assertEquals("first", IterableExtensions.<TreeNode>head(tree.getNodes()).getName());
Assert.assertEquals(0, IterableExtensions.<TreeNode>head(tree.getNodes()).getChildren().size());
Assert.assertEquals("second", IterableExtensions.<TreeNode>last(tree.getNodes()).getName());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void testIgnoreEmptyLines_2() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("\"first\"");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\"second\"");
_builder.newLine();
final Tree tree = this.parseHelper.parse(_builder);
Assert.assertNotNull(tree);
Assert.assertEquals(2, tree.getMoreNodes().size());
Assert.assertEquals("first", IterableExtensions.<OtherTreeNode>head(tree.getMoreNodes()).getName());
Assert.assertNull(IterableExtensions.<OtherTreeNode>head(tree.getMoreNodes()).getChildList());
Assert.assertEquals("second", IterableExtensions.<OtherTreeNode>last(tree.getMoreNodes()).getName());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void testIgnoreEmptyLines_3() {
try {
final Tree tree = this.parseHelper.parse("first\n\t");
Assert.assertNotNull(tree);
Assert.assertEquals(1, tree.getNodes().size());
Assert.assertEquals("first", IterableExtensions.<TreeNode>head(tree.getNodes()).getName());
Assert.assertEquals(0, IterableExtensions.<TreeNode>head(tree.getNodes()).getChildren().size());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void testIgnoreEmptyLines_4() {
try {
final Tree tree = this.parseHelper.parse("\"first\"\n\t");
Assert.assertNotNull(tree);
Assert.assertEquals(1, tree.getMoreNodes().size());
Assert.assertEquals("first", IterableExtensions.<OtherTreeNode>head(tree.getMoreNodes()).getName());
Assert.assertNull(IterableExtensions.<OtherTreeNode>head(tree.getMoreNodes()).getChildList());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void testIgnoreEmptyLines_5() {
try {
final Tree tree = this.parseHelper.parse("first\n\t\tabc\n\t");
Assert.assertNotNull(tree);
Assert.assertEquals(1, tree.getNodes().size());
Assert.assertEquals("first", IterableExtensions.<TreeNode>head(tree.getNodes()).getName());
Assert.assertEquals(1, IterableExtensions.<TreeNode>head(tree.getNodes()).getChildren().size());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void testIgnoreEmptyLines_6() {
try {
final Tree tree = this.parseHelper.parse("\"first\"\n\t\t\"abc\"\n\t");
Assert.assertNotNull(tree);
Assert.assertEquals(1, tree.getMoreNodes().size());
Assert.assertEquals("first", IterableExtensions.<OtherTreeNode>head(tree.getMoreNodes()).getName());
Assert.assertNotNull(IterableExtensions.<OtherTreeNode>head(tree.getMoreNodes()).getChildList());
Assert.assertEquals(1, IterableExtensions.<OtherTreeNode>head(tree.getMoreNodes()).getChildList().getChildren().size());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void testParentChild() {
try {
@ -400,6 +497,82 @@ public class IndentationAwareLanguageTest {
Assert.assertEquals(_builder_1.toString(), this.asText(tree));
}
@Test
public void testTree_06() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("\"a\"");
_builder.newLine();
_builder.append("\"b\"");
_builder.newLine();
final Tree tree = this.parseAndValidate(_builder);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("a");
_builder_1.newLine();
_builder_1.append("b");
_builder_1.newLine();
Assert.assertEquals(_builder_1.toString(), this.asText(tree));
}
@Test
public void testTree_07() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("\"a\"");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\"b\"");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
final Tree tree = this.parseAndValidate(_builder);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("a");
_builder_1.newLine();
_builder_1.append("b");
_builder_1.newLine();
Assert.assertEquals(_builder_1.toString(), this.asText(tree));
}
@Test
public void testTree_08() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("\"a\"");
_builder.newLine();
_builder.append("\t");
_builder.append("\"1\"");
_builder.newLine();
_builder.append("\t");
_builder.append("\"2\"");
_builder.newLine();
_builder.append("\"b\"");
_builder.newLine();
_builder.append("\t\t");
_builder.append("\"3\"");
_builder.newLine();
final Tree tree = this.parseAndValidate(_builder);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("a");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append(">");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("1");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("2");
_builder_1.newLine();
_builder_1.append("b");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append(">");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("3");
_builder_1.newLine();
Assert.assertEquals(_builder_1.toString(), this.asText(tree));
}
private Tree parseAndValidate(final CharSequence s) {
try {
final Tree result = this.parseHelper.parse(s);
@ -424,6 +597,14 @@ public class IndentationAwareLanguageTest {
_builder.newLineIfNotEmpty();
}
}
{
EList<OtherTreeNode> _moreNodes = tree.getMoreNodes();
for(final OtherTreeNode node_1 : _moreNodes) {
StringConcatenation _asText_1 = this.asText(node_1);
_builder.append(_asText_1);
_builder.newLineIfNotEmpty();
}
}
return _builder.toString();
}
@ -443,4 +624,31 @@ public class IndentationAwareLanguageTest {
}
return _builder;
}
private StringConcatenation asText(final OtherTreeNode treeNode) {
StringConcatenation _builder = new StringConcatenation();
String _name = treeNode.getName();
_builder.append(_name);
_builder.newLineIfNotEmpty();
{
ChildList _childList = treeNode.getChildList();
boolean _tripleNotEquals = (_childList != null);
if (_tripleNotEquals) {
_builder.append("\t");
_builder.append(">");
_builder.newLine();
{
EList<OtherTreeNode> _children = treeNode.getChildList().getChildren();
for(final OtherTreeNode node : _children) {
_builder.append("\t");
_builder.append("\t");
StringConcatenation _asText = this.asText(node);
_builder.append(_asText, "\t\t");
_builder.newLineIfNotEmpty();
}
}
}
}
return _builder;
}
}

View file

@ -0,0 +1,353 @@
/**
* Copyright (c) 2017 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.xtext.parser.indentation;
import com.google.inject.Inject;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.AbstractRule;
import org.eclipse.xtext.Action;
import org.eclipse.xtext.Keyword;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.nodemodel.ICompositeNode;
import org.eclipse.xtext.nodemodel.ILeafNode;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.nodemodel.impl.InvariantChecker;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree;
import org.eclipse.xtext.parser.indentation.tests.IndentationAwareTestLanguageInjectorProvider;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.XtextRunner;
import org.eclipse.xtext.testing.util.ParseHelper;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* @author Sebastian Zarnekow - Initial contribution and API
*/
@RunWith(XtextRunner.class)
@InjectWith(IndentationAwareTestLanguageInjectorProvider.class)
@SuppressWarnings("all")
public class NodeModelTest {
@Inject
private ParseHelper<Tree> parseHelper;
@Inject
@Extension
private InvariantChecker invariantChecker;
@Test
public void testEmptyTree() {
final ICompositeNode tree = this.getRootNode("");
Assert.assertEquals("", this.asText(tree));
}
@Test
public void testSingleRootNode() {
final ICompositeNode tree = this.getRootNode("root");
StringConcatenation _builder = new StringConcatenation();
_builder.append("[ID:root]");
_builder.newLine();
Assert.assertEquals(_builder.toString().trim(), this.asText(tree));
}
@Test
public void testTwoRootNodes() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("first");
_builder.newLine();
_builder.append("second");
_builder.newLine();
final ICompositeNode tree = this.getRootNode(_builder);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("[ID:first][-WS:");
_builder_1.newLine();
_builder_1.append("][ID:second][-WS:");
_builder_1.newLine();
_builder_1.append("]");
_builder_1.newLine();
Assert.assertEquals(_builder_1.toString().trim(), this.asText(tree));
}
@Test
public void testParentChild() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("parent");
_builder.newLine();
_builder.append("\t");
_builder.append("child");
_builder.newLine();
final ICompositeNode tree = this.getRootNode(_builder);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("[ID:parent][-WS:");
_builder_1.newLine();
_builder_1.append("\\t][INDENT:][ID:child][-WS:");
_builder_1.newLine();
_builder_1.append("][DEDENT:]");
_builder_1.newLine();
Assert.assertEquals(_builder_1.toString().trim(), this.asText(tree));
}
@Test
public void testParentChildWithEof() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("parent");
_builder.newLine();
_builder.append("\t");
_builder.append("child");
_builder.newLine();
final ICompositeNode tree = this.getRootNode(_builder.toString().trim());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("[ID:parent][-WS:");
_builder_1.newLine();
_builder_1.append("\\t][INDENT:][ID:child][DEDENT:]");
_builder_1.newLine();
Assert.assertEquals(_builder_1.toString().trim(), this.asText(tree));
}
@Test
public void testParentChildren() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("parent");
_builder.newLine();
_builder.append("\t");
_builder.append("child");
_builder.newLine();
_builder.append("\t");
_builder.append("child");
_builder.newLine();
final ICompositeNode tree = this.getRootNode(_builder);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("[ID:parent][-WS:");
_builder_1.newLine();
_builder_1.append("\\t][INDENT:][ID:child][-WS:");
_builder_1.newLine();
_builder_1.append("\\t][ID:child][-WS:");
_builder_1.newLine();
_builder_1.append("][DEDENT:]");
_builder_1.newLine();
Assert.assertEquals(_builder_1.toString().trim(), this.asText(tree));
}
@Test
public void testTree_01() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("a");
_builder.newLine();
_builder.append("\t");
_builder.append("b");
_builder.newLine();
_builder.append("\t ");
_builder.append("c");
_builder.newLine();
_builder.append("\t");
_builder.append("d");
_builder.newLine();
final ICompositeNode tree = this.getRootNode(_builder);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("[ID:a][-WS:");
_builder_1.newLine();
_builder_1.append("\\t][INDENT:][ID:b][-WS:");
_builder_1.newLine();
_builder_1.append("\\t ][INDENT:][ID:c][-WS:");
_builder_1.newLine();
_builder_1.append("][DEDENT:][-WS:\\t][ID:d][-WS:");
_builder_1.newLine();
_builder_1.append("][DEDENT:]");
_builder_1.newLine();
Assert.assertEquals(_builder_1.toString().trim(), this.asText(tree));
}
@Test
public void testWeirdTree() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("root");
_builder.newLine();
_builder.append(" ");
_builder.append("s4");
_builder.newLine();
_builder.append(" ");
_builder.append("s8");
_builder.newLine();
_builder.append(" ");
_builder.append("s6");
_builder.newLine();
final ICompositeNode tree = this.getRootNode(_builder);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("[ID:root][-WS:");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("][INDENT:][ID:s4][-WS:");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("][INDENT:][ID:s8][-WS:");
_builder_1.newLine();
_builder_1.append("][DEDENT:][-WS: ][INDENT:][ID:s6][-WS:");
_builder_1.newLine();
_builder_1.append("][DEDENT:][DEDENT:]");
_builder_1.newLine();
Assert.assertEquals(_builder_1.toString().trim(), this.asText(tree));
}
@Test
public void testWeirdTreeEof() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("root");
_builder.newLine();
_builder.append(" ");
_builder.append("s4");
_builder.newLine();
_builder.append(" ");
_builder.append("s8");
_builder.newLine();
_builder.append(" ");
_builder.append("s6");
_builder.newLine();
final ICompositeNode tree = this.getRootNode(_builder.toString().trim());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("[ID:root][-WS:");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("][INDENT:][ID:s4][-WS:");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("][INDENT:][ID:s8][-WS:");
_builder_1.newLine();
_builder_1.append("][DEDENT:][-WS: ][INDENT:][ID:s6][DEDENT:][DEDENT:]");
_builder_1.newLine();
Assert.assertEquals(_builder_1.toString().trim(), this.asText(tree));
}
@Test
public void testIgnoreEmptyLines_1() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("first");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("second");
_builder.newLine();
final ICompositeNode tree = this.getRootNode(_builder);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("[ID:first][-WS:");
_builder_1.newLine();
_builder_1.append("\\t");
_builder_1.newLine();
_builder_1.append("][ID:second][-WS:");
_builder_1.newLine();
_builder_1.append("]");
_builder_1.newLine();
Assert.assertEquals(_builder_1.toString().trim(), this.asText(tree));
}
@Test
public void testIgnoreEmptyLines_2() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("\"first\"");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\"second\"");
_builder.newLine();
final ICompositeNode tree = this.getRootNode(_builder);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("[STRING:\"first\"][-WS:");
_builder_1.newLine();
_builder_1.append("\\t");
_builder_1.newLine();
_builder_1.append("][STRING:\"second\"][-WS:");
_builder_1.newLine();
_builder_1.append("]");
_builder_1.newLine();
Assert.assertEquals(_builder_1.toString().trim(), this.asText(tree));
}
@Test
public void testIgnoreEmptyLines_3() {
final ICompositeNode tree = this.getRootNode("first\n\t");
StringConcatenation _builder = new StringConcatenation();
_builder.append("[ID:first][-WS:");
_builder.newLine();
_builder.append("\\t]");
_builder.newLine();
Assert.assertEquals(_builder.toString().trim(), this.asText(tree));
}
@Test
public void testIgnoreEmptyLines_4() {
final ICompositeNode tree = this.getRootNode("first\n\t\tabc\n\t");
StringConcatenation _builder = new StringConcatenation();
_builder.append("[ID:first][-WS:");
_builder.newLine();
_builder.append("\\t\\t][INDENT:][ID:abc][-WS:");
_builder.newLine();
_builder.append("][DEDENT:][-WS:\\t]");
_builder.newLine();
Assert.assertEquals(_builder.toString().trim(), this.asText(tree));
}
private ICompositeNode getRootNode(final CharSequence seq) {
try {
final Tree model = this.parseHelper.parse(seq);
final ICompositeNode result = NodeModelUtils.getNode(model).getRootNode();
this.invariantChecker.checkInvariant(result);
return result;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
private String asText(final INode node) {
final Function1<ILeafNode, Boolean> _function = (ILeafNode it) -> {
EObject _grammarElement = it.getGrammarElement();
return Boolean.valueOf((!(_grammarElement instanceof Action)));
};
final Function1<ILeafNode, CharSequence> _function_1 = (ILeafNode it) -> {
String _xifexpression = null;
boolean _isHidden = it.isHidden();
if (_isHidden) {
_xifexpression = "-";
} else {
_xifexpression = "";
}
String _kenType = this.tokenType(it.getGrammarElement());
String _plus = (_xifexpression + _kenType);
String _plus_1 = (_plus + ":");
String _replace = it.getText().replace("\t", "\\t");
return (_plus_1 + _replace);
};
return IterableExtensions.<ILeafNode>join(IterableExtensions.<ILeafNode>filter(node.getLeafNodes(), _function), "[", "][", "]", _function_1);
}
private String tokenType(final EObject obj) {
String _switchResult = null;
boolean _matched = false;
if (obj instanceof RuleCall) {
_matched=true;
_switchResult = ((RuleCall)obj).getRule().getName();
}
if (!_matched) {
if (obj instanceof Keyword) {
_matched=true;
_switchResult = ((Keyword)obj).getValue();
}
}
if (!_matched) {
if (obj instanceof AbstractRule) {
_matched=true;
_switchResult = ((AbstractRule)obj).getName();
}
}
return _switchResult;
}
}

View file

@ -16,6 +16,11 @@ import org.eclipse.xtext.parser.antlr.AbstractSplittingTokenSource;
import org.eclipse.xtext.parser.antlr.ITokenAcceptor;
/**
* Abstract implementation of a token source, that splits according to indentation levels
* after newlines.
* Blank lines are ignored. At the end of file token, all pending indentations will be handled
* and dedentation tokens will be issued accordingly if {@link #shouldEmitPendingEndTokens()} returns true.
*
* @author Sebastian Zarnekow - Initial contribution and API
* @since 2.8
*/
@ -27,6 +32,7 @@ public abstract class AbstractIndentationTokenSource extends AbstractSplittingTo
protected Stack<Integer> indentationStack = new Stack<Integer>();
// make sure we never face an empty indentation stack.
{
indentationStack.push(0);
}
@ -47,19 +53,23 @@ public abstract class AbstractIndentationTokenSource extends AbstractSplittingTo
*/
protected abstract boolean shouldSplitTokenImpl(Token token);
protected void doSplitEofToken(Token token, ITokenAcceptor result) {
if (shouldEmitPendingEndTokens()) {
while(indentationStack.size() > 1) {
indentationStack.pop();
result.accept(createEndToken(nextOffset));
}
}
result.accept(token);
}
@Override
protected void doSplitToken(Token token, ITokenAcceptor result) {
if (token.getType() == Token.EOF) {
if (shouldEmitPendingEndTokens()) {
while(indentationStack.size() > 1) {
indentationStack.pop();
result.accept(createEndToken(nextOffset));
}
}
result.accept(token);
return;
doSplitEofToken(token, result);
} else {
doSplitTokenImpl(token, result);
}
doSplitTokenImpl(token, result);
}
protected boolean shouldEmitPendingEndTokens() {
@ -78,7 +88,8 @@ public abstract class AbstractIndentationTokenSource extends AbstractSplittingTo
}
/**
* The token was previously determined as potentially to-be-splitted.
* The token was previously determined as potentially to-be-splitted thus we
* emit additional indentation or dedenting tokens.
*/
protected void doSplitTokenImpl(Token token, ITokenAcceptor result) {
String text = token.getText();
@ -88,16 +99,31 @@ public abstract class AbstractIndentationTokenSource extends AbstractSplittingTo
} else if (indentation > currentIndentation) {
splitIntoBeginToken(token, indentation, result);
} else if (indentation < currentIndentation) {
// emit whitespace including newline
int charCount = text.length() - computeIndentationRelevantCharCount(text);
String leading = text.substring(0, charCount);
if (leading.length() > 0) {
CommonToken leadingToken = createToken((CommonToken) token, leading, null, null, nextOffset, nextOffset + charCount - 1, null);
result.accept(leadingToken);
nextOffset += charCount;
}
// emit end tokens at the beginning of the line
while(indentation < currentIndentation) {
indentationStack.pop();
currentIndentation = indentationStack.peek();
result.accept(createEndToken(nextOffset));
}
if (indentation > currentIndentation) {
splitIntoBeginToken(token, indentation, result);
return;
String trailing = text.substring(charCount);
if (trailing.length() != 0) {
CommonToken trailingToken = createToken((CommonToken) token, trailing, null, null, nextOffset, null, null);
if (indentation > currentIndentation) {
splitIntoBeginToken(trailingToken, indentation, result);
return;
}
// emit pending whitespace
result.accept(trailingToken);
}
result.accept(token);
} else {
throw new IllegalStateException(String.valueOf(indentation));
}
@ -105,9 +131,21 @@ public abstract class AbstractIndentationTokenSource extends AbstractSplittingTo
private void splitIntoBeginToken(Token token, int indentation, ITokenAcceptor result) {
result.accept(token);
indentationStack.push(indentation);
currentIndentation = indentation;
result.accept(createBeginToken(((CommonToken) token).getStopIndex() + 1));
if (shouldEmitPendingEndTokens()) {
Token nextToken = getDelegate().nextToken();
if (shouldSplitToken(nextToken)) {
doSplitToken(nextToken, result);
} else {
indentationStack.push(indentation);
currentIndentation = indentation;
result.accept(createBeginToken(((CommonToken) token).getStopIndex() + 1));
result.accept(nextToken);
}
} else {
indentationStack.push(indentation);
currentIndentation = indentation;
result.accept(createBeginToken(((CommonToken) token).getStopIndex() + 1));
}
}
protected Token createEndToken(int offset) {
@ -130,7 +168,19 @@ public abstract class AbstractIndentationTokenSource extends AbstractSplittingTo
result.setStopIndex(offset-1);
return result;
}
protected int computeIndentationRelevantCharCount(String text) {
int result = 0;
for(int i = text.length() - 1; i>=0; i--) {
char c = text.charAt(i);
if (c == '\n' || c == '\r') {
return result;
}
result++;
}
return -1;
}
protected int computeIndentation(String text) {
int result = 0;
for(int i = text.length() - 1; i>=0; i--) {