mjijackson/citrus — pull request #40 by blambeau (2012-02-22 08:08:37+00:00)
Title: Traceability of matches towards parsed source

Hi!

Here is a bunch of commits that provide support for keeping traceability of the matches in the input source (text). This is typically useful for compiling chains where semantic passes need to provide feedback in terms of locations in the source text.

Roughly, with this pull request, Citrus supports a scenario like the one below + more. Commits are well commented to ease your review.

rule additive
(factor operator:('+' | '-') space* term){
location = [source, offset]
semantic_value = ...
semantic_value.location = location
}
end

# ...

path = Pathname.new("a/path/to/a/file")
sem_value = grammar.parse_file(path).value
sem_value.location
# [ path, 0 ]