Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
Deep dive into Xtext scoping
local and global scopes explained
Sebastian Holger
Who are these guys?
Scoping with Xtext
What is scoping?
What is scoping?
What is scoping?
Convention
What is scoping?
QualifiedName
What is scoping?
QualifiedName
grandfather
father
son1
son2
- grandfather.father.son1
- grandfather.father.son2
What is scoping?
Simple name
What is scoping?
What is scoping?
Same EMF Container
What is scoping?
What is scoping?
PrefixMatcher does it’s job
What is scoping?
What is scoping?
Not same container
Imports?
Imports?
org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider
Imports?
org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider
Imports?
org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider
Feels wrong
Implicit imports
Implicit imports
Implicit imports
Implicit imports
Not called for root object!
Implicit imports
Implicit imports
Implicit imports
So far easy…
So far easy…
But what is a scope?
So far easy…
But what is a scope?
It describes the reachable Elements…
So far easy…
But what is a scope?
…depending on the context…
It describes the reachable Elements…
So far easy…
But what is a scope?
…depending on the context…
…and maps name to EObject…
It describes the reachable Element...
So far easy…
But what is a scope?
…depending on the context…
…and maps name to EObject…
…in a chain of scopes.
It describe...
Simply spoken
Scope
EObjectDescription
EObjectDescription
…
EObjectDescription
QualifiedName URI UserData
A chain of responsibility
Scope
EObjectDescription
EObjectDescription
…
Scope
EObjectDescription
EObjectDescription
…
oute...
A chain of responsibility
Scope
EObjectDescription
EObjectDescription
…
Scope
EObjectDescription
EObjectDescription
…
oute...
Index
ResourceDescription
…
ResourceDescription URI
ExportedObjects
ReferencedObjects
ImportedNames
- List of EObjectDescr...
Local vs. global scoping
Local
Local vs. global scoping
Local Global
Other files in project and more…
Who creates Scopes?
Local Scopes Global Scope
aka. the Index
Who creates Scopes?
Local Scopes Global Scope
aka. the Index
YOU! The builder!
Override getScope!
Don’t use the declarative stuff any
more!
Simple Example
Simple Example
Simple Example
Collect all fields
Collect all fields
Collect all fields
More logic
More logic
Walkthrough
Walkthrough
Field
More logic
Walkthrough
Walkthrough
Field
More logic
Walkthrough
Walkthrough
Field
Field
More logic
More logic
More logic
More logic
context.getField cannot be called!
CyclicLinkingException
Objects can have different names in
different contexts
Function to transform the name
The implementation creates new EObje...
Objects can have different names in
different contexts
org.eclipse.xtext.resource.impl.AliasedEObjectDescription
org.eclip...
Don’t create too tight scopes
Don’t create too tight scopes
Use validations instead!
They can produce more meaningful
messages then!
The NodeModel
EObject CompositeNode
Adapter
LeafNode LeafNode CompositeNode
LeafNode LeafNode
EObject CompositeNode
Adapter
LeafNode LeafNode CompositeNode
LeafNode LeafNode
The NodeModel
Don’trelyontheNodeModeldurin...
Never load resources explicitly
There is a global scope
Global Scoping
Global Scoping
ResourceDescriptions
Constructed when the builder runs…
Global Scoping
ResourceDescriptions
Constructed when the builder runs…
org.eclipse.xtext.resource.impl.ResourceDescription...
Global Scoping
ResourceDescriptions
Constructed when the builder runs…
org.eclipse.xtext.resource.impl.ResourceDescription...
Information hiding
Not everything should be referable
Information hiding
Not everything should be referable
Save memory and time!
EObjectDescription(QualifiedName qualifiedName,
EObject element, Map<String, String> userData)
UserData
Serializable stuff
I...
Index in Standalone
ResourceSetGlobalScopeProvider
Long time the
was the default.
Index in Standalone
ResourceSetGlobalScopeProvider
Long time the
was the default.
Today we can do better but you need to u...
Index in Standalone
Fill the index and install it on the ResourceSet!
Load each resource and ask the
ResourceDescriptionMa...
Index in Standalone
Fill the index and install it on the ResourceSet!
Load each resource and ask the
ResourceDescriptionMa...
Lessons learned
Never use #getResource
Avoid the Node Model
CyclicResolutionExceptions!
UserData helps
Never use #getResou...
Nächste SlideShare
Wird geladen in …5
×

von

Deep dive into Xtext scoping local and global scopes explained Slide 1 Deep dive into Xtext scoping local and global scopes explained Slide 2 Deep dive into Xtext scoping local and global scopes explained Slide 3 Deep dive into Xtext scoping local and global scopes explained Slide 4 Deep dive into Xtext scoping local and global scopes explained Slide 5 Deep dive into Xtext scoping local and global scopes explained Slide 6 Deep dive into Xtext scoping local and global scopes explained Slide 7 Deep dive into Xtext scoping local and global scopes explained Slide 8 Deep dive into Xtext scoping local and global scopes explained Slide 9 Deep dive into Xtext scoping local and global scopes explained Slide 10 Deep dive into Xtext scoping local and global scopes explained Slide 11 Deep dive into Xtext scoping local and global scopes explained Slide 12 Deep dive into Xtext scoping local and global scopes explained Slide 13 Deep dive into Xtext scoping local and global scopes explained Slide 14 Deep dive into Xtext scoping local and global scopes explained Slide 15 Deep dive into Xtext scoping local and global scopes explained Slide 16 Deep dive into Xtext scoping local and global scopes explained Slide 17 Deep dive into Xtext scoping local and global scopes explained Slide 18 Deep dive into Xtext scoping local and global scopes explained Slide 19 Deep dive into Xtext scoping local and global scopes explained Slide 20 Deep dive into Xtext scoping local and global scopes explained Slide 21 Deep dive into Xtext scoping local and global scopes explained Slide 22 Deep dive into Xtext scoping local and global scopes explained Slide 23 Deep dive into Xtext scoping local and global scopes explained Slide 24 Deep dive into Xtext scoping local and global scopes explained Slide 25 Deep dive into Xtext scoping local and global scopes explained Slide 26 Deep dive into Xtext scoping local and global scopes explained Slide 27 Deep dive into Xtext scoping local and global scopes explained Slide 28 Deep dive into Xtext scoping local and global scopes explained Slide 29 Deep dive into Xtext scoping local and global scopes explained Slide 30 Deep dive into Xtext scoping local and global scopes explained Slide 31 Deep dive into Xtext scoping local and global scopes explained Slide 32 Deep dive into Xtext scoping local and global scopes explained Slide 33 Deep dive into Xtext scoping local and global scopes explained Slide 34 Deep dive into Xtext scoping local and global scopes explained Slide 35 Deep dive into Xtext scoping local and global scopes explained Slide 36 Deep dive into Xtext scoping local and global scopes explained Slide 37 Deep dive into Xtext scoping local and global scopes explained Slide 38 Deep dive into Xtext scoping local and global scopes explained Slide 39 Deep dive into Xtext scoping local and global scopes explained Slide 40 Deep dive into Xtext scoping local and global scopes explained Slide 41 Deep dive into Xtext scoping local and global scopes explained Slide 42 Deep dive into Xtext scoping local and global scopes explained Slide 43 Deep dive into Xtext scoping local and global scopes explained Slide 44 Deep dive into Xtext scoping local and global scopes explained Slide 45 Deep dive into Xtext scoping local and global scopes explained Slide 46 Deep dive into Xtext scoping local and global scopes explained Slide 47 Deep dive into Xtext scoping local and global scopes explained Slide 48 Deep dive into Xtext scoping local and global scopes explained Slide 49 Deep dive into Xtext scoping local and global scopes explained Slide 50 Deep dive into Xtext scoping local and global scopes explained Slide 51 Deep dive into Xtext scoping local and global scopes explained Slide 52 Deep dive into Xtext scoping local and global scopes explained Slide 53 Deep dive into Xtext scoping local and global scopes explained Slide 54 Deep dive into Xtext scoping local and global scopes explained Slide 55 Deep dive into Xtext scoping local and global scopes explained Slide 56 Deep dive into Xtext scoping local and global scopes explained Slide 57 Deep dive into Xtext scoping local and global scopes explained Slide 58 Deep dive into Xtext scoping local and global scopes explained Slide 59 Deep dive into Xtext scoping local and global scopes explained Slide 60 Deep dive into Xtext scoping local and global scopes explained Slide 61 Deep dive into Xtext scoping local and global scopes explained Slide 62 Deep dive into Xtext scoping local and global scopes explained Slide 63 Deep dive into Xtext scoping local and global scopes explained Slide 64 Deep dive into Xtext scoping local and global scopes explained Slide 65 Deep dive into Xtext scoping local and global scopes explained Slide 66 Deep dive into Xtext scoping local and global scopes explained Slide 67 Deep dive into Xtext scoping local and global scopes explained Slide 68 Deep dive into Xtext scoping local and global scopes explained Slide 69 Deep dive into Xtext scoping local and global scopes explained Slide 70 Deep dive into Xtext scoping local and global scopes explained Slide 71 Deep dive into Xtext scoping local and global scopes explained Slide 72 Deep dive into Xtext scoping local and global scopes explained Slide 73 Deep dive into Xtext scoping local and global scopes explained Slide 74
Nächste SlideShare
What to Upload to SlideShare
Weiter
Herunterladen, um offline zu lesen und im Vollbildmodus anzuzeigen.

2 Gefällt mir

Teilen

Herunterladen, um offline zu lesen

Deep dive into Xtext scoping local and global scopes explained

Herunterladen, um offline zu lesen

In Xtext's grammar language syntax and structure of models are defined at a single location in a very concise way. The nesting structure and the references between objects are expressed which goes beyond plain abstract syntax trees. By just pointing to a type of an object, we describe the shape of a syntax graph. But the grammar alone has no meaning to describe the visibility rules inside of a resource or across resource boundaries. Therefore Xtext has a concept of scopes that are modeled as a chain of responsibility. Xtext comes with a good default scoping semantic that fits for most simple problems, but when the amount of models grows or your problem cannot be handled by the default you have to get in touch with the scoping API. Or as others have said it: Beyond here are dragons.

Most Xtext users know how to implement scoping rules that are applied within the same resource. After all, the API is pretty straight forward. Referencing objects located in other resources is usually more tricky. Here the so called global scope provider is doing it’s job. By default, the global scope contains every object that has a name. Again, that’s good as a starting point and will work in most of the cases, but for serious languages, it doesn't cut it. Memory consumption and performance will play a bigger role as the amount of models grows. There is no turning back: As a language engineer, you really need to understand what’s going on under the covers to define scaling implementations.

In this session we will provide a thorough explaination of the most important concepts of Xtext’s way of scoping. You will learn, that an object might have different names in different contexts and what's behind nested scopes, shadowing and filtering. We will discuss typical problems and solutions along with best practices for scoping. In the end, it's about the right compromise between implementation effort, memory consumption and performance.

Ähnliche Bücher

Kostenlos mit einer 30-tägigen Testversion von Scribd

Alle anzeigen

Ähnliche Hörbücher

Kostenlos mit einer 30-tägigen Testversion von Scribd

Alle anzeigen

Deep dive into Xtext scoping local and global scopes explained

  1. 1. Deep dive into Xtext scoping local and global scopes explained
  2. 2. Sebastian Holger Who are these guys?
  3. 3. Scoping with Xtext
  4. 4. What is scoping?
  5. 5. What is scoping?
  6. 6. What is scoping? Convention
  7. 7. What is scoping? QualifiedName
  8. 8. What is scoping? QualifiedName grandfather father son1 son2 - grandfather.father.son1 - grandfather.father.son2
  9. 9. What is scoping? Simple name
  10. 10. What is scoping?
  11. 11. What is scoping? Same EMF Container
  12. 12. What is scoping?
  13. 13. What is scoping? PrefixMatcher does it’s job
  14. 14. What is scoping?
  15. 15. What is scoping? Not same container
  16. 16. Imports?
  17. 17. Imports? org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider
  18. 18. Imports? org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider
  19. 19. Imports? org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider Feels wrong
  20. 20. Implicit imports
  21. 21. Implicit imports
  22. 22. Implicit imports
  23. 23. Implicit imports Not called for root object!
  24. 24. Implicit imports
  25. 25. Implicit imports
  26. 26. Implicit imports
  27. 27. So far easy…
  28. 28. So far easy… But what is a scope?
  29. 29. So far easy… But what is a scope? It describes the reachable Elements…
  30. 30. So far easy… But what is a scope? …depending on the context… It describes the reachable Elements…
  31. 31. So far easy… But what is a scope? …depending on the context… …and maps name to EObject… It describes the reachable Elements…
  32. 32. So far easy… But what is a scope? …depending on the context… …and maps name to EObject… …in a chain of scopes. It describes the reachable Elements…
  33. 33. Simply spoken Scope EObjectDescription EObjectDescription … EObjectDescription QualifiedName URI UserData
  34. 34. A chain of responsibility Scope EObjectDescription EObjectDescription … Scope EObjectDescription EObjectDescription … outer Index global ResourceDescription … Simply spoken
  35. 35. A chain of responsibility Scope EObjectDescription EObjectDescription … Scope EObjectDescription EObjectDescription … outer Index global ResourceDescription … Simply spoken
  36. 36. Index ResourceDescription … ResourceDescription URI ExportedObjects ReferencedObjects ImportedNames - List of EObjectDescriptions - List of ReferenceDesciptions - All the names Simply spoken
  37. 37. Local vs. global scoping Local
  38. 38. Local vs. global scoping Local Global Other files in project and more…
  39. 39. Who creates Scopes? Local Scopes Global Scope aka. the Index
  40. 40. Who creates Scopes? Local Scopes Global Scope aka. the Index YOU! The builder!
  41. 41. Override getScope! Don’t use the declarative stuff any more!
  42. 42. Simple Example
  43. 43. Simple Example
  44. 44. Simple Example
  45. 45. Collect all fields
  46. 46. Collect all fields
  47. 47. Collect all fields
  48. 48. More logic
  49. 49. More logic Walkthrough Walkthrough Field
  50. 50. More logic Walkthrough Walkthrough Field
  51. 51. More logic Walkthrough Walkthrough Field Field
  52. 52. More logic
  53. 53. More logic
  54. 54. More logic
  55. 55. More logic context.getField cannot be called! CyclicLinkingException
  56. 56. Objects can have different names in different contexts Function to transform the name The implementation creates new EObjectDescriptions
  57. 57. Objects can have different names in different contexts org.eclipse.xtext.resource.impl.AliasedEObjectDescription org.eclipse.xtext.scoping.impl.ImportScope
  58. 58. Don’t create too tight scopes
  59. 59. Don’t create too tight scopes Use validations instead! They can produce more meaningful messages then!
  60. 60. The NodeModel EObject CompositeNode Adapter LeafNode LeafNode CompositeNode LeafNode LeafNode
  61. 61. EObject CompositeNode Adapter LeafNode LeafNode CompositeNode LeafNode LeafNode The NodeModel Don’trelyontheNodeModelduring scoping
  62. 62. Never load resources explicitly There is a global scope
  63. 63. Global Scoping
  64. 64. Global Scoping ResourceDescriptions Constructed when the builder runs…
  65. 65. Global Scoping ResourceDescriptions Constructed when the builder runs… org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider …accessible through… IResourceDescriptions - getResourceDescriptions(ResourceSet)
  66. 66. Global Scoping ResourceDescriptions Constructed when the builder runs… org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider …accessible through… IResourceDescriptions - getResourceDescriptions(ResourceSet) …depending on the LoadOptions… LIVE_SCOPE NAMED_BUILDER_SCOPE
  67. 67. Information hiding Not everything should be referable
  68. 68. Information hiding Not everything should be referable Save memory and time!
  69. 69. EObjectDescription(QualifiedName qualifiedName, EObject element, Map<String, String> userData) UserData Serializable stuff Informations without resolving the proxy
  70. 70. Index in Standalone ResourceSetGlobalScopeProvider Long time the was the default.
  71. 71. Index in Standalone ResourceSetGlobalScopeProvider Long time the was the default. Today we can do better but you need to use it and know that there is something new… For Maven- and Gradle it’s done.
  72. 72. Index in Standalone Fill the index and install it on the ResourceSet! Load each resource and ask the ResourceDescriptionManager to create a ResourceDescription…
  73. 73. Index in Standalone Fill the index and install it on the ResourceSet! Load each resource and ask the ResourceDescriptionManager to create a ResourceDescription… Install it on the ResourceSet
  74. 74. Lessons learned Never use #getResource Avoid the Node Model CyclicResolutionExceptions! UserData helps Never use #getResource! Don’t Filter - But Validate!
  • AubinMah

    Apr. 26, 2019
  • kthoms

    Jun. 27, 2017

In Xtext's grammar language syntax and structure of models are defined at a single location in a very concise way. The nesting structure and the references between objects are expressed which goes beyond plain abstract syntax trees. By just pointing to a type of an object, we describe the shape of a syntax graph. But the grammar alone has no meaning to describe the visibility rules inside of a resource or across resource boundaries. Therefore Xtext has a concept of scopes that are modeled as a chain of responsibility. Xtext comes with a good default scoping semantic that fits for most simple problems, but when the amount of models grows or your problem cannot be handled by the default you have to get in touch with the scoping API. Or as others have said it: Beyond here are dragons. Most Xtext users know how to implement scoping rules that are applied within the same resource. After all, the API is pretty straight forward. Referencing objects located in other resources is usually more tricky. Here the so called global scope provider is doing it’s job. By default, the global scope contains every object that has a name. Again, that’s good as a starting point and will work in most of the cases, but for serious languages, it doesn't cut it. Memory consumption and performance will play a bigger role as the amount of models grows. There is no turning back: As a language engineer, you really need to understand what’s going on under the covers to define scaling implementations. In this session we will provide a thorough explaination of the most important concepts of Xtext’s way of scoping. You will learn, that an object might have different names in different contexts and what's behind nested scopes, shadowing and filtering. We will discuss typical problems and solutions along with best practices for scoping. In the end, it's about the right compromise between implementation effort, memory consumption and performance.

Aufrufe

Aufrufe insgesamt

2.947

Auf Slideshare

0

Aus Einbettungen

0

Anzahl der Einbettungen

16

Befehle

Downloads

38

Geteilt

0

Kommentare

0

Likes

2

×