Mentions légales du service

Skip to content

allow specifying a starting position when parsing code fragments

LAWALL Julia requested to merge lawall/coccinelle:starting_position into master

For #if lines, the condition is parsed after the fact, from a string. This was causing it to end up with the offset 0 and line number 1. These tokens would then come out at the front of the sequence of tokens in the entire top-level entity, making the entity's starting line number incorrect. Make it possible to specify the starting position of the argument to #if in this case. Setting the lex_abs_pos field sets the character offset from the start of the file. Setting the lex_curr_p field sets the line number. OCaml 4.11 is promised to have a function Lexing.set_position to address this issue.

In the future this approach could be extended to improve the lines numbers of tokens reread from a file when a function is modified. But if the modification causes the code to increase in size, there could be multiple lines that seem to have the same line number, so more thought is required.

Merge request reports