Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Sep 30, 2023
2 parents 2cd7bc7 + 5841d87 commit 493ff57
Show file tree
Hide file tree
Showing 21 changed files with 105 additions and 335 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void stopsOnCritical(@TempDir final Path temp) throws IOException {
.result()
.get(
String.format(
"target/%s/foo/x/main/28-duplicate-names.xml",
"target/%s/foo/x/main/27-duplicate-names.xml",
OptimizeMojo.STEPS
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Current test shows optimization and transpilation chain for simple program.
# The aim of this test is to check that entire pipeline with
# synthetic-referenses.xsl transformation works as expected without creating
# any warnings or errors.
# Pay attention to scopes.xsl and to-java.xsl transformations.
# scoped objects works as expected without creating any warnings or errors.
# Pay attention and to-java.xsl transformations.
xsls:
- /org/eolang/parser/errors/not-empty-atoms.xsl
- /org/eolang/parser/critical-errors/duplicate-names.xsl
Expand All @@ -25,7 +24,6 @@ xsls:
- /org/eolang/parser/warnings/incorrect-version.xsl
- /org/eolang/parser/expand-aliases.xsl
- /org/eolang/parser/resolve-aliases.xsl
- /org/eolang/parser/scopes.xsl
- /org/eolang/parser/add-default-package.xsl
- /org/eolang/parser/errors/broken-refs.xsl
- /org/eolang/parser/errors/unknown-names.xsl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Current test shows optimization and transpilation chain for simple program.
# The aim of this test is to check that entire pipeline with
# synthetic-referenses.xsl transformation works as expected without creating
# any warnings or errors.
# Pay attention to scopes.xsl and to-java.xsl transformations.
# scoped objects works as expected without creating any warnings or errors.
# Pay attention to to-java.xsl transformations.
xsls:
- /org/eolang/parser/errors/not-empty-atoms.xsl
- /org/eolang/parser/critical-errors/duplicate-names.xsl
Expand All @@ -25,7 +24,6 @@ xsls:
- /org/eolang/parser/warnings/incorrect-version.xsl
- /org/eolang/parser/expand-aliases.xsl
- /org/eolang/parser/resolve-aliases.xsl
- /org/eolang/parser/scopes.xsl
- /org/eolang/parser/add-default-package.xsl
- /org/eolang/parser/errors/broken-refs.xsl
- /org/eolang/parser/errors/unknown-names.xsl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ xsls:
- /org/eolang/maven/pre/to-java.xsl
tests:
- /program/errors[count(*)=0]
- //java[contains(text(), 'Phi ret_a2_a1 = new EOorg.EOeolang.EOint(')]
- //java[contains(text(), 'Phi ret_a0 = new EOorg.EOeolang.EOint(')]
- //java[contains(text(), 'Phi ret_a1 = new EOorg.EOeolang.EOint(')]
- //java[contains(text(), 'Phi[] ret_2_a = new Phi[0]')]
- //java[contains(text(), 'new String(new byte[]')]
eo: |
Expand Down
2 changes: 0 additions & 2 deletions eo-parser/src/main/antlr4/org/eolang/parser/Program.g4
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ happlicationExtended
happlicationHead
: hmethod
| applicable
| scope
;

// Extended head of horizontal application
Expand All @@ -123,7 +122,6 @@ happlicationHeadExtended
: vmethod
| hmethodExtended
| applicable
| scopeExtended
;

// Simple statements that can be used as head of application
Expand Down
82 changes: 28 additions & 54 deletions eo-parser/src/main/java/org/eolang/parser/Objects.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
*/
package org.eolang.parser;

import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.UUID;
import org.xembly.Directive;
import org.xembly.Directives;

Expand All @@ -40,55 +37,51 @@ interface Objects extends Iterable<Directive> {
* Start new object.
* @param line At line.
* @param pos At position.
* @return Self.
*/
void start(int line, int pos);
Objects start(int line, int pos);

/**
* Add data.
* @param data Data.
* @return Self.
*/
void data(String data);
Objects data(String data);

/**
* Property.
* @param key Key.
* @param value Value.
* @return Self.
*/
void prop(String key, Object value);
Objects prop(String key, Object value);

/**
* Empty propery.
* @param key Key.
* @return Self.
*/
void prop(String key);
Objects prop(String key);

/**
* Change property by given xpath.
* @param key Key.
* @param xpath Xpath.
* @return Self.
*/
void xprop(String key, Object xpath);
Objects xprop(String key, Object xpath);

/**
* Enter last object.
* @return Self.
*/
void enter();
Objects enter();

/**
* Leave current object.
* @return Self.
*/
void leave();

/**
* Mark the next object for scoping.
*/
void scope();

/**
* Mark the current object as last inside the scope.
* Last object that relates to the scope.
*/
void closeScope();
Objects leave();

/**
* Xembly object tree.
Expand All @@ -101,64 +94,45 @@ final class ObjXembly implements Objects {
*/
private final Directives dirs = new Directives();

/**
* Generated aliases.
*/
private final Deque<String> scopes = new LinkedList<>();

@Override
public void start(final int line, final int pos) {
public Objects start(final int line, final int pos) {
this.dirs.add("o");
this.prop("line", line);
this.prop("pos", pos);
if (!this.scopes.isEmpty()) {
this.prop("scope", String.join("-", this.scopes));
}
return this.prop("line", line).prop("pos", pos);
}

@Override
public void data(final String data) {
public Objects data(final String data) {
this.dirs.set(data);
return this;
}

@Override
public void prop(final String key, final Object type) {
public Objects prop(final String key, final Object type) {
this.dirs.attr(key, type);
return this;
}

@Override
public void prop(final String key) {
this.prop(key, "");
public Objects prop(final String key) {
return this.prop(key, "");
}

@Override
public void xprop(final String key, final Object xpath) {
public Objects xprop(final String key, final Object xpath) {
this.dirs.xattr(key, xpath);
return this;
}

@Override
public void enter() {
public Objects enter() {
this.dirs.xpath("o[last()]").strict(1);
return this;
}

@Override
public void leave() {
public Objects leave() {
this.dirs.up();
}

@Override
public void scope() {
this.scopes.push(
String.format(
"scope-%s",
UUID.randomUUID()
)
);
}

@Override
public void closeScope() {
this.scopes.remove();
return this;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public final class ParsingTrain extends TrEnvelope {
"/org/eolang/parser/warnings/incorrect-version.xsl",
"/org/eolang/parser/expand-aliases.xsl",
"/org/eolang/parser/resolve-aliases.xsl",
"/org/eolang/parser/scopes.xsl",
"/org/eolang/parser/add-refs.xsl",
"/org/eolang/parser/add-default-package.xsl",
"/org/eolang/parser/errors/broken-refs.xsl",
Expand Down
Loading

0 comments on commit 493ff57

Please sign in to comment.