NAME

Language::FormulaEngine::Parser::ContextUtil - utility methods for parsers

VERSION

version 0.06

EXPORTED FUNCTIONS

calc_text_coordinates

  my ($line, $col)= calc_text_coordinates( $buffer, $pos );
  my ($line, $col)= calc_text_coordinates( $buffer, $pos, $buffer_line, $buffer_col );

Returns the 0-based line number and character number of an offset within a buffer. The line/column of the start of the buffer can be given as additional arguments.

format_context_string

  my $message= format_context_string( $buffer, $token_start, $token_limit, $buffer_line, $buffer_col );
  # "'blah blah' on line 15, char 12"

Returns a single-string view of where the token occurs in the buffer. This is useful for single-line "die" messages.

format_context_multiline

  my $tty_text= format_context_multiline( $buffer, $token_start, $token_limit, \%args );
  
  #   "blah blah blah token blah blah\n"
  #  ."               ^^^^^\n"
  #  ." (line 15, char 16)\n";

More advanced view of the input string, printed on three lines with the second marking the token within its context and third listing the line/column. This is only useful with a fixed-width font in a multi-line context.

This method also supports various options for formatting.

AUTHOR

Michael Conrad <mconrad@intellitree.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2021 by Michael Conrad, IntelliTree Solutions llc.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.