-
Notifications
You must be signed in to change notification settings - Fork 177
bug(#4559): auto phi formation correctly parsed with application precedences #4560
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
base: master
Are you sure you want to change the base?
Changes from 21 commits
06c4813
9bdb52f
da64738
554385c
d2f2257
2ebe627
32c2eec
18aeaaf
96763d6
eb1c1eb
d36d73f
e2a0396
ece0c48
7bedfad
82cd9ba
d9bea33
4ae096f
ac2de15
0971a90
82f1cb7
a67b94b
cfc1e13
f384915
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 |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| # yamllint disable rule:line-length | ||
| out: [] | ||
| file: org/eolang/snippets/foo.eo | ||
| args: ["org.eolang.snippets.foo"] | ||
| eo: | | ||
| +alias org.eolang.io.stdout | ||
| +alias org.eolang.txt.text | ||
| +alias org.eolang.structs.list | ||
| +package org.eolang.snippets | ||
|
|
||
| [] > foo | ||
| "abcdefghijk" > origin | ||
| origin > @ | ||
| [cont-list] > custom-map | ||
| mapped. > @ | ||
| cont-list | ||
| (text orgn).contains x >> [x] | ||
| origin > orgn! | ||
|
|
||
| [] +> test-custom-map | ||
| eq. > @ | ||
| list (* true true) | ||
| foo.custom-map (list (* "abc" "ghi")) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| # yamllint disable rule:line-length | ||
| sheets: | ||
| - /org/eolang/maven/transpile/set-locators.xsl | ||
| - /org/eolang/maven/transpile/set-original-names.xsl | ||
| - /org/eolang/maven/transpile/classes.xsl | ||
| - /org/eolang/maven/transpile/tests.xsl | ||
| - /org/eolang/maven/transpile/attrs.xsl | ||
| - /org/eolang/maven/transpile/data.xsl | ||
| - /org/eolang/maven/transpile/to-java.xsl | ||
| asserts: | ||
| - /object[not(errors)] | ||
| - //java[contains(text(), 'Φ.custom-map.ap🌵46.φ')] | ||
| - //java[contains(text(), 'Φ.custom-map.ap🌵46.φ.ρ.ρ.α0')] | ||
| - //java[contains(text(), 'Phi rrbb = Phi.Φ.take("org").take("eolang").take("text");')] | ||
| - //java[contains(text(), 'rrbb1 = new PhMethod(rrbb1, "orgn");')] | ||
| - //java[contains(text(), 'Phi rrb = new PhMethod(rrbb, "what");')] | ||
| - //java[contains(text(), 'Phi rrb1 = Phi.Φ.take("org").take("eolang").take("b");')] | ||
| - //java[contains(text(), 'Phi rr = new PhMethod(rrb, "ttt");')] | ||
| input: | | ||
| [cont-list] > custom-map | ||
| mapped. > @ | ||
| cont-list | ||
| ((text orgn).what b).ttt >> [y] | ||
| origin > orgn! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ | |
| import java.util.Iterator; | ||
| import java.util.List; | ||
| import java.util.function.Supplier; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
| import java.util.stream.Collectors; | ||
| import org.antlr.v4.runtime.ParserRuleContext; | ||
| import org.antlr.v4.runtime.Token; | ||
|
|
@@ -35,6 +37,11 @@ | |
| "PMD.GodClass" | ||
| }) | ||
| final class XeEoListener implements EoListener, Iterable<Directive> { | ||
| /** | ||
| * Last application. | ||
| */ | ||
| private static final Pattern LAST_APPLICATION = Pattern.compile("\\)\\.(\\p{L}[\\p{L}\\p{N}-]*)$"); | ||
|
|
||
| /** | ||
| * Xembly directives we are building (mutable). | ||
| */ | ||
|
|
@@ -158,7 +165,9 @@ public void exitObject(final EoParser.ObjectContext ctx) { | |
| @Override | ||
| public void enterBound(final EoParser.BoundContext ctx) { | ||
| if (ctx.just() != null && ctx.aphi() != null && ctx.just().finisher() != null) { | ||
| this.startAutoPhiFormation(ctx, ctx.just().finisher().getText()); | ||
| this.startAutoPhiFormation( | ||
| ctx, XeEoListener.eoApplicationToXmir(ctx.just().finisher().getText()) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -367,7 +376,9 @@ public void exitHapplicationExtended(final EoParser.HapplicationExtendedContext | |
|
|
||
| @Override | ||
| public void enterOnlyAphi(final EoParser.OnlyAphiContext ctx) { | ||
| this.startAutoPhiFormation(ctx, ctx.happlicationHeadExtended().getText()); | ||
| this.startAutoPhiFormation( | ||
| ctx, XeEoListener.eoApplicationToXmir(ctx.happlicationHeadExtended().getText()) | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -661,7 +672,12 @@ public void enterVapplicationArgUnbound(final EoParser.VapplicationArgUnboundCon | |
| final EoParser.VapplicationArgUnboundCurrentContext vertical = | ||
| ctx.vapplicationArgUnboundCurrent(); | ||
| if (vertical.just() != null || vertical.method() != null) { | ||
| this.startAutoPhiFormation(ctx, XeEoListener.verticalApplicationBase(vertical)); | ||
| this.startAutoPhiFormation( | ||
| ctx, | ||
| XeEoListener.eoApplicationToXmir( | ||
| XeEoListener.verticalApplicationBase(vertical) | ||
| ) | ||
| ); | ||
| } | ||
| } else { | ||
| this.objects.enter(); | ||
|
|
@@ -699,7 +715,7 @@ public void enterVapplicationArgUnboundNext( | |
| ) { | ||
| if (ctx.aphi() != null) { | ||
| this.startAutoPhiFormation( | ||
| ctx, ctx.vapplicationHead().getText() | ||
| ctx, XeEoListener.eoApplicationToXmir(ctx.vapplicationHead().getText()) | ||
| ); | ||
| } | ||
| } | ||
|
|
@@ -1210,13 +1226,44 @@ private String alphaAttr(final ParserRuleContext ctx, final String msg) { | |
| * @param application Application base | ||
| */ | ||
| private void startAutoPhiFormation(final ParserRuleContext ctx, final String application) { | ||
| final Matcher matcher = XeEoListener.LAST_APPLICATION.matcher(application); | ||
| final String abase; | ||
| if (matcher.find()) { | ||
| abase = String.format(".%s", matcher.group(1)); | ||
| } else { | ||
h1alexbel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| abase = application; | ||
| } | ||
| this.startAbstract(ctx) | ||
| .enter().prop("name", new AutoName(ctx, "p").asString()) | ||
| .start(ctx) | ||
| .prop("base", String.format("ξ.ρ.%s", application)) | ||
| .prop("base", abase) | ||
| .prop("name", "φ"); | ||
| } | ||
|
|
||
| /** | ||
| * EO application to XMIR base. | ||
| * @param application Application to transform | ||
| * @return Application base in XMIR format | ||
| */ | ||
| private static String eoApplicationToXmir(final String application) { | ||
| final String transformed = application.replace("^.", "ρ."); | ||
| final String base; | ||
| if (transformed.startsWith("QQ.")) { | ||
| base = transformed.replace("QQ", "Φ.org.eolang"); | ||
| } else if (transformed.startsWith("Q.")) { | ||
| base = transformed.replace("Q.", "Φ."); | ||
| } else { | ||
| base = transformed; | ||
| } | ||
| final String result; | ||
| if (base.startsWith("ρ.") || base.startsWith("Φ.")) { | ||
| result = base; | ||
| } else { | ||
| result = String.format("ξ.ρ.%s", base); | ||
|
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. @h1alexbel again, I strongly believe there's no need to append You'll translate it to But this is wrong, should be
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. @maxonfjvipon please check this. How about we add this test case as disabled with puzzle? |
||
| } | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Trim margin from text block. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| # yamllint disable rule:line-length | ||
| sheets: [] | ||
| asserts: | ||
| - /object[not(errors)] | ||
| - //o[not(@base) and @name='ap🌵34' and o[@name='φ' and @base='.as-j']/o[@base='.as-i']/o[@base='Φ.org.eolang.text']/o[@base='ξ.ρ.args']] | ||
| - //o[@base='.as-i' and not(@name)]/o[2][@base='Φ.org.eolang.as-bar.b'] | ||
| input: | | ||
| [args] > foo | ||
| bar > i | ||
| ((text args).as-i as-bar.b).as-j >> [x] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| # yamllint disable rule:line-length | ||
| sheets: [] | ||
| asserts: | ||
| - /object[not(errors)] | ||
| - //o[not(@base) and @name='ap🌵34' and o[@name='φ' and @base='ρ.x.ρ.y.ρ.z']] | ||
| input: | | ||
| [args] > main | ||
| a > x1 | ||
| ^.x.^.y.^.z >> [y] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| # yamllint disable rule:line-length | ||
| sheets: [] | ||
| asserts: | ||
| - /object[not(errors)] | ||
| - //o[not(@base) and @name='ap🌵34' and o[2][@name='x' and @base='∅' and not(@as)] and o[3][@name='φ' and @base='Φ.a.bca.eaa.boom']/o[1][@base='Φ.org.eolang.number']] | ||
| input: | | ||
| [] > foo | ||
| start > @ | ||
| Q.a.bca.eaa.boom 42 >> [x] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| # yamllint disable rule:line-length | ||
| sheets: [] | ||
| asserts: | ||
| - /object[not(errors)] | ||
| - //o[not(@base) and @name='ap🌵34' and o[@name='φ' and @base='.j']/o[@base='.i']/o[@base='Φ.org.eolang.txt.text']/o[@base='ξ.ρ.args']] | ||
| - //o[@base='.i' and not(@name)]/o[2][@base='Φ.org.foo.b'] | ||
| input: | | ||
| [args] > main | ||
| foo > app | ||
| ((Q.org.eolang.txt.text args).i Q.org.foo.b).j >> [y] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| # yamllint disable rule:line-length | ||
| sheets: [] | ||
| asserts: | ||
| - /object[not(errors)] | ||
| - //o[not(@base) and @name='ap🌵34' and o[2][@name='x' and @base='∅' and not(@as)] and o[3][@name='φ' and @base='Φ.org.eolang.foo.bar']/o[1][@base='Φ.org.eolang.number']] | ||
| input: | | ||
| [] > main | ||
| start > @ | ||
| QQ.foo.bar 42 >> [x] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| # yamllint disable rule:line-length | ||
| sheets: [] | ||
| asserts: | ||
| - /object[not(errors)] | ||
| - //o[not(@base) and @name='ap🌵34' and o[@name='φ' and @base='.ttt']/o[@base='.what']/o[@base='Φ.org.eolang.text']/o[@base='ξ.ρ.orgn']] | ||
| - //o[not(@base) and @name='ap🌵54' and o[@name='φ' and @base='.g']/o[@base='.e']/o[@base='.c']] | ||
| - //o[not(@base) and @name='ap🌵86' and o[@name='φ' and @base='.contains']/o[@base='Φ.org.eolang.text']/o[@base='ξ.ρ.orgn']] | ||
| - //o[not(@base) and @name='ap🌵86' and o[@name='φ' and @base='.contains']/o[@base='ξ.x']] | ||
| input: | | ||
| [cont-list] > custom-map | ||
| foo > boom | ||
| ((text orgn).what b).ttt >> [y] | ||
| bar > dummy | ||
| (((a b).c d).e f).g >> [v] | ||
| mapped. > @ | ||
| cont-list | ||
| (text orgn).contains x >> [x] | ||
| origin > orgn! |
Uh oh!
There was an error while loading. Please reload this page.