Eno\Section » lookup
lookup($index) → array or null
lookup($line, $column) → array or null
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 null
. Note that
all arguments are zero-indexed, i.e. the first lines and columns are numbered 0
, not 1
.
enocolor: blue
# notes
php$document = Parser::parse($input);
$document->lookup(3); // 'o'
// returns [ 'element' => [Field name="color" value="blue"], 'zone' => 'name' }
$document->lookup(7); // 'b'
// returns [ 'element' => [Field name="color" value="blue"], 'zone' => 'value' }
$document->lookup(0, 3); // 'o'
// returns [ 'element' => [Field name="color" value="blue"], 'zone' => 'name' }
$document->lookup(0, 7); // 'b'
// returns [ 'element' => [Field name="color" value="blue"], 'zone' => 'value' }
$document->lookup(13); // '#'
// returns [ 'element' => [Section name="notes" elements=0], 'zone' => 'sectionOperator' }
$document->lookup(19); // 's'
// returns [ 'element' => [Section name="notes" elements=0], 'zone' => 'name' }
$document->lookup(2, 0); // '#'
// returns [ 'element' => [Section name="notes" elements=0], 'zone' => 'sectionOperator' }
$document->lookup(2, 6); // 's'
// returns [ 'element' => [Section name="notes" elements=0], 'zone' => 'name' }
Parameters
$indexA one-dimensional index to look up (0-indexed, i.e. the first position is 0, not 1)- only applies when it's the only given argument.
$lineThe line to look up (0-indexed, i.e. the first line is 0, not 1) - only applies when you supply $column
as well.
The column to look up (0-indexed, i.e. the first column is 0, not 1) - only applies when you supply $line
as well.
Return value
For all valid indices within the document returns an array with two keys:
zone
: A string denoting the token at the index, 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
element
: A Section
, Fieldset
, Field
.. . For empty lines you get the containing section.
When an index outside the document is supplied, null
is returned.