Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.15.4</version>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
Expand Down
33 changes: 32 additions & 1 deletion src/org/rascalmpl/library/lang/xml/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public class IO {
private final IValueFactory vf;
private static final String SRC_ATTR = "src";
private static final String QUALIFIED_SRC_ATTR = "rascal-src";

private static final String SRCS_ATTR = "srcs";
private static final String QUALIFIED_SRCS_ATTR = "rascal-srcs";

public IO(IValueFactory vf) {
this.vf = vf;
Expand Down Expand Up @@ -147,6 +148,15 @@ else if (a.getKey().equals("xmlns")) {
.map(a -> removeNamespace(a, elem.attributes(), fullyQualify))
.collect(Collectors.toMap(a -> normalizeAttr(a.getKey()), a -> vf.string(a.getValue())));

// we traverse again to record the source positions of each attribute
IMap Srcs = file != null ? StreamSupport.stream(elem.attributes().spliterator(), false)
.filter(a -> !a.getKey().startsWith("xmlns"))
.map(a -> removeNamespace(a, elem.attributes(), fullyQualify))
.map(a -> vf.tuple(vf.string(normalizeAttr(a.getKey())), attrToLoc(a, file)))
.collect(vf.mapWriter())
: vf.map()
;

if (fullyQualify) {
IMap m = namespaces.done();

Expand All @@ -164,6 +174,9 @@ else if (a.getKey().equals("xmlns")) {

if (file != null) {
kws.put(kws.containsKey(SRC_ATTR) ? QUALIFIED_SRC_ATTR : SRC_ATTR, nodeToLoc((Element) node, file, includeEndTags));
if (!Srcs.isEmpty()) {
kws.put(kws.containsKey(SRCS_ATTR) ? QUALIFIED_SRCS_ATTR : SRCS_ATTR, Srcs);
}
}

return vf.node(removeNamespace(node.nodeName(), fullyQualify), args).asWithKeywordParameters().setParameters(kws);
Expand Down Expand Up @@ -209,6 +222,24 @@ private static Attribute removeNamespace(Attribute a, Attributes otherAttributes
return new Attribute(newKey, a.getValue());
}

private ISourceLocation attrToLoc(Attribute a, ISourceLocation file) {
Range range = a.sourceRange().valueRange();

if (range.start().pos() < 0) {
// this is strange
return file;
}

return vf.sourceLocation(file,
range.start().pos(),
range.end().pos() - range.start().pos(),
range.start().lineNumber(),
range.end().lineNumber(),
range.start().columnNumber() - 1,
range.end().columnNumber() - 1
);
}

private ISourceLocation nodeToLoc(Element node, ISourceLocation file, boolean includeEndTags) {
Range startRange = node.sourceRange();
if (!startRange.isTracked()) {
Expand Down