Skip to content

Getting line and column in the input? #141

Answered by renggli
Oualitsen asked this question in Q&A
Discussion options

You must be logged in to vote

The Token class provides such a helper:

static List<int> lineAndColumnOf(String buffer, int position) {

You can either use that static method, or build your own similar helper.

Example usage:

final result = parser.parse(input);
if (result.isFailure) {
  final lineAndColumn = Token.lineAndColumnOf(input, result.position);
  print('Error ${result.message} at ${lineAndColumn.join(':')}');
  ...

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by renggli
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #140 on November 06, 2022 09:20.