Section » lookup

lookup(index) → Hash or None
lookup(line, column) → Hash or None

Ask the document Hey what's at column X in line Y in my eno file?. The lookup always returns an element for valid indices (the document/section in case of an empty line/space), only indices outside the range of the document return None. Note that all arguments are zero-indexed, i.e. the first lines and columns are numbered 0, not 1.

enocolor: blue

# notes
python>>> document = enopy.parse(input)

>>> document.lookup(3)  # 'o'
{ 'element': <class Field name="color" value="blue">, 'zone': 'name' }
>>> document.lookup(7)  # 'b'
{ 'element': <class Field name="color" value="blue">, 'zone': 'value' }
>>> document.lookup(0, 3)  # 'o'  
{ 'element': <class Field name="color" value="blue">, 'zone': 'name' }
>>> document.lookup(0, 7)  # 'b'  
{ 'element': <class Field name="color" value="blue">, 'zone': 'value' }
>>> document.lookup(13)  # '#' 
{ 'element': <class Section name="notes" elements=0>, 'zone': 'section_operator' }
>>> document.lookup(19)  # 's' 
{ 'element': <class Section name="notes" elements=0>, 'zone': 'name' }
>>> document.lookup(2, 0)  # '#'   
{ 'element': <class Section name="notes" elements=0>, 'zone': 'section_operator' }
>>> document.lookup(2, 6)  # 's'   
{ 'element': <class Section name="notes" elements=0>, 'zone': 'name' }

Parameters

index

A one-dimensional index to look up (0-indexed, i.e. the first position is 0, not 1) - only applies when it's the single only given argument.

line

The line to look up (0-indexed, i.e. the first line is 0, not 1) - only applies when you supply a column as well.

column

The column to look up (0-indexed, i.e. the first column is 0, not 1) - only applies when you supply a line as well.

Return value

For all valid indices within the document returns a Hash with two keys:

element: An Section, Fieldset, Field.. . For empty lines you get the containing section.

zone: A string denoting the token at the specified position, here's the full list:

'[empty-lines-and-spaces-between-tokens]' => element
'[inside-blocks]' => content
'[inside-comments]' => comment
'[name]' => name
'[template]' => value
'[value]' => value
':' => name_operator
'-' => item_operator
'=' => entry_operator
'--' => block_operator
'>' => comment_operator
'`' => escape_begin_operator
'`' => escape_end_operator
'|' => newline_continuation_operator
'\' => line_continuation_operator
'#' => section_operator
'<' => copy_operator
'<<' => deep_copy_operator

When an index outside the document is supplied, None is returned.