-
Notifications
You must be signed in to change notification settings - Fork 207
Auto-home bare same-package references (#4529) #5425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
b8e43de
7f1fb6f
fc1fda9
84b0622
5020c99
daa6ee7
1846943
501c5d1
c89f9be
08c23fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,16 +7,19 @@ | |
| import com.github.lombrozo.xnav.Filter; | ||
| import com.github.lombrozo.xnav.Xnav; | ||
| import com.jcabi.log.Logger; | ||
| import com.jcabi.xml.XML; | ||
| import com.jcabi.xml.XMLDocument; | ||
| import java.io.FileNotFoundException; | ||
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.function.UnaryOperator; | ||
| import java.util.stream.Collectors; | ||
| import org.cactoos.iterable.Filtered; | ||
| import org.cactoos.text.TextOf; | ||
| import org.eolang.parser.Canonical; | ||
| import org.w3c.dom.Node; | ||
|
|
||
| /** | ||
|
|
@@ -115,10 +118,15 @@ final class Parsing implements Step { | |
| @Override | ||
| public void exec() { | ||
| final Collection<TjForeign> sources = this.tojos.withSources(); | ||
| final int total = new Threaded<>( | ||
| new Filtered<>(TjForeign::notParsed, sources), | ||
| this::parsed | ||
| ).total(); | ||
| final String objects = sources.stream() | ||
| .map(TjForeign::identifier) | ||
| .filter(id -> id.contains(".")) | ||
| .map(id -> id.substring(id.lastIndexOf('.') + 1)) | ||
| .distinct() | ||
| .collect(Collectors.joining(" ")); | ||
| final int total = this.parsed( | ||
| sources, new Canonical(objects), Integer.toHexString(objects.hashCode()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 501c5d1. The qualified names are now sorted and hashed with SHA-256 (cactoos Generated by Claude Code |
||
| ); | ||
| if (0 == total) { | ||
| if (sources.isEmpty()) { | ||
| Logger.info( | ||
|
|
@@ -140,13 +148,35 @@ public void exec() { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Parse all the given sources to XMIRs, concurrently. | ||
| * @param sources The sources to parse | ||
| * @param pipeline The canonical parsing transform to apply | ||
| * @param digest Digest of the set of known objects (part of the cache key) | ||
| * @return Amount of parsed tojos | ||
| */ | ||
| private int parsed( | ||
| final Collection<TjForeign> sources, | ||
| final UnaryOperator<XML> pipeline, | ||
| final String digest | ||
| ) { | ||
| return new Threaded<>( | ||
| new Filtered<>(TjForeign::notParsed, sources), | ||
| tojo -> this.parsed(tojo, pipeline, digest) | ||
| ).total(); | ||
| } | ||
|
|
||
| /** | ||
| * Parse EO file to XML. | ||
| * @param tojo The tojo | ||
| * @param pipeline The canonical parsing transform to apply | ||
| * @param digest Digest of the set of known objects (part of the cache key) | ||
| * @return Amount of parsed tojos | ||
| * @throws Exception If fails | ||
| */ | ||
| private int parsed(final TjForeign tojo) throws Exception { | ||
| private int parsed( | ||
| final TjForeign tojo, final UnaryOperator<XML> pipeline, final String digest | ||
| ) throws Exception { | ||
| final Path source = tojo.source(); | ||
| final String name = tojo.identifier(); | ||
| final Path base = this.targetDir.resolve(Parsing.DIR); | ||
|
|
@@ -157,18 +187,18 @@ private int parsed(final TjForeign tojo) throws Exception { | |
| new Cache( | ||
| new CachePath( | ||
| this.cacheDir.resolve(Parsing.CACHE), | ||
| this.version, | ||
| String.format("%s-%s", this.version, digest), | ||
| new TojoHash(tojo).get() | ||
| ), | ||
| src -> { | ||
| final Node node = this.parsed(src, name); | ||
| final Node node = this.parsed(src, name, pipeline); | ||
| refs.add(node); | ||
| return new XMLDocument(node).toString(); | ||
| } | ||
| ) | ||
| ).apply(source, target, base.relativize(target)); | ||
| } else { | ||
| final Node node = this.parsed(source, name); | ||
| final Node node = this.parsed(source, name, pipeline); | ||
| new Saved(new XMLDocument(node).toString(), target).value(); | ||
| refs.add(node); | ||
| } | ||
|
|
@@ -198,11 +228,14 @@ private int parsed(final TjForeign tojo) throws Exception { | |
| * Source parsed to {@link Node}. | ||
| * @param source Relative source path | ||
| * @param identifier Name of the EO object as tojo identifier | ||
| * @param pipeline The canonical parsing transform to apply | ||
| * @return Parsed EO object as {@link Node} | ||
| * @throws IOException If fails to parse | ||
| */ | ||
| private Node parsed(final Path source, final String identifier) throws IOException { | ||
| final EoSource.Xmir xmir = new EoSource(identifier, source).parsed(); | ||
| private Node parsed( | ||
| final Path source, final String identifier, final UnaryOperator<XML> pipeline | ||
| ) throws IOException { | ||
| final EoSource.Xmir xmir = new EoSource(identifier, source, pipeline).parsed(); | ||
| Logger.debug( | ||
| Parsing.class, | ||
| "Parsed program '%s' from %[file]s:%n %s", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This flattens every object across all packages into one set of simple names, so
eo:homedhomes a bare name into the current package whenever the name exists in any package.ssandttalready both definecontains/index-of/last-index-of, andss/index-of.eouses a barenumber— the day any package gains anumberobject, that reference silently re-homes toΦ.ss.number. Keying on the qualified name avoids this: pass the.-containing identifiers asobjectsunchanged, then home only whenconcat($package, '.', $name)matches. Same single pipeline, no simple-name collisions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 501c5d1.
add-default-package.xslnow keys on the qualified name: the plugin passes the.-containing identifiers (package.name) unchanged, and a bare name is homed only whenconcat($package, '.', $name)is in the list. So the simple-name collision is gone — verified against eo-runtime, the barenumberinss/index-of.eostaysΦ.number(33 occurrences, 0Φ.ss.number).Generated by Claude Code