2

What is the preferred way to implement a column counter in a Ragel finite state machine. If it makes any difference, my main machine is a scanner as defined in chapter 6.3 of the Ragel manual. I'm thinking probably that I just need to be able to execute an action for every character consumed (i.e. incrementing a counter), but if there's a better way to do it, I'd love to know.

brooks94
  • 3,836
  • 4
  • 30
  • 57

1 Answers1

0

You can keep track of the position of newlines in the input and get the column using the current position whenever you need to, using something like column = p - lineStart + 1, where lineStart is the position just after the previous newline (or the beginning of the file if you're on the first line).

John Sensebe
  • 1,386
  • 8
  • 11