Cursor lookup

When you regularly parse a document you enter at the root document level, there is however also the possibility to parse the document and lookup a one-dimensional index or a line and column in the document, which means you enter the document at whichever element is at that location. This can be used for autocomplete providers in an IDE or text editor, or other rich eno document inspection usecases.

require 'enolib'

lookup = Enolib.lookup('field: value', index: 3) # "what is at string offset 3?"
#=> { element: #<Enolib::Element key=field>, range: :key }

lookup = Enolib.lookup('field: value', index: 5) # "what is at string offset 5?"
#=>{ element: #<Enolib::Element key=field>, range: :element_operator }

lookup = Enolib.lookup('field: value', line: 0, column: 10) # "what is at line 0, column 10?"
#=>{ element: #<Enolib::Element key=field>, range: :value }

Note that the element returned as a lookup property is of variable type, therefore you need to use the methods described in Dynamic layouts to further query the document from this entry point.

As you don't enter at the root you can also use .parent to navigate up the hierarchy.


Next page: Querying content