I try to iterate over all comments in a C++ source file, but I fail to access M3.comments.
I tried iprintln, for-, switch- and visit-statements.
iprintln(m3) gives the following output:
m3(
|file://bla.c|,
macroExpansions={},
methodOverrides={},
includeDirectives={
...
},
inactiveIncludes={},
comments=[
|file://bla.c|(0,80),
|file://bla.c|(82,34),
...
],
macroDefinitions={},
includeResolution={
...
})
'''
The following code matches
visit (m3) { case comments: println("match"); }
but I am unable to get the locations.
E.g.
visit (m3) { case c:comments: println(c); }
gives back "Ambiguous code (internal error), c:comments:".
Next
visit (m3) { case comments(c): println("c"); }
does not match
And
iprintln(m3.comments);
gives back "Undeclared field: comments for M3".
How can I access the comments?
You can project out the comments by this:
theComments = m3Model.comments;
That "." expression selects the comments field of the m3 data constructor.
If you want to match a keyword field like comments
instead, you'd write a pattern like so:
m3(comments=theComments) := myM3Model
If the field is undeclared, you could declare it like so:
data M3(list[loc] comments=[]);
However, that should have been in the Claire library declarations already. Please report an issue on GitHub?