Skip to content

Commit

Permalink
Merge pull request #165 from yegor256/164
Browse files Browse the repository at this point in the history
164: new EO-to-Java compiler
  • Loading branch information
yegor256 authored Dec 23, 2020
2 parents 6b117f8 + 28e722c commit eba8b28
Show file tree
Hide file tree
Showing 119 changed files with 3,280 additions and 2,201 deletions.
6 changes: 3 additions & 3 deletions .rultor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ install: |
pdd --file=/dev/null
merge:
script: |
mvn clean install -Peo -Pqulice --errors --settings ../settings.xml
mvn clean install -Peo -Pqulice --errors --settings ../settings.xml -Dstyle.color=never
release:
script: |-
mvn versions:set "-DnewVersion=${tag}"
mvn versions:set "-DnewVersion=${tag}" -Dstyle.color=never
git commit -am "${tag}"
mvn clean deploy -Peo -Psonatype --errors --settings ../settings.xml
mvn clean deploy -Peo -Psonatype --errors --settings ../settings.xml -Dstyle.color=never
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ whether it's leap or not:
[args] > main
[y] > leap
or
and
eq (mod y 4) 0
not (eq (mod y 100) 0)
eq (mod y 400) 0
and
or.
and.
eq. (mod. y 4) 0
not. (eq. (mod. y 100) 0)
eq. (mod. y 400) 0
and. > @
stdout "Enter a year:"
stdout
concat
(scanner stdin).nextInt > !year
" is a leap year?"
leap year:y
sprintf
"%d is %sa leap year!"
(scanner stdin).nextInt > year!
if (leap year:y) "" "not "
```

More examples are [here](https://github.com/yegor256/eo/tree/master/eo-maven-plugin/src/it).
Expand Down
55 changes: 38 additions & 17 deletions eo-compiler/src/main/antlr4/org/eolang/compiler/Program.g4
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ program
license
:
(COMMENT EOL)+
EOL
;

metas
:
(META EOL)+
EOL
;

objects
Expand All @@ -46,7 +44,6 @@ objects
(COMMENT EOL)*
object
EOL
EOL?
)+
;

Expand All @@ -67,10 +64,24 @@ object

abstraction
:
(COMMENT EOL)*
LSQ
(NAME (SPACE NAME)*)?
(attribute (SPACE attribute)*)?
RSQ
suffix?
(suffix (SPACE SLASH NAME)?)?
;

attribute
:
label
;

label
:
AT
|
NAME
DOTS?
;

tail
Expand All @@ -86,8 +97,9 @@ suffix
SPACE
ARROW
SPACE
label
QUESTION?
CONST?
NAME
;

method
Expand Down Expand Up @@ -148,8 +160,12 @@ head
:
AT
|
SELF
|
NAME
|
NAME DOT
|
data
;

Expand All @@ -161,11 +177,13 @@ has

data
:
BYTES
|
BOOL
|
STRING
|
INTEGER
INT
|
FLOAT
|
Expand All @@ -177,9 +195,13 @@ data
COMMENT: HASH ~[\r\n]*;
META: PLUS NAME (SPACE ~[\r\n]+)?;

DOTS: '...';
CONST: '!';
QUESTION: '?';
SLASH: '/';
COLON: ':';
ARROW: '>';
SELF: '$';
PLUS: '+';
MINUS: '-';
SPACE: ' ';
Expand All @@ -192,7 +214,7 @@ AT: '@';
HASH: '#';
EOL
:
[\r\n]
[\r\n]+
SPACE*
{
int tabs = getText().replaceAll("[\r\n]+", "").length() / 2;
Expand All @@ -210,16 +232,15 @@ EOL
}
;

fragment BYTE: [0-9A-F][0-9A-F] MINUS;
BYTES: BYTE (BYTE* [0-9A-F][0-9A-F])?;

BOOL: 'true' | 'false';
CHAR: '\'' (LETTER | DIGIT) '\'';
CHAR: '\'' [0-9a-zA-Z] '\'';
STRING: '"' ('\\"' | ~'"')* '"';
INTEGER: (PLUS | MINUS)? DIGIT+;
FLOAT: (PLUS | MINUS)? DIGIT+ DOT DIGIT+;
HEX: '0x' (DIGIT | 'a'..'f')+;
INT: (PLUS | MINUS)? [0-9]+;
FLOAT: (PLUS | MINUS)? [0-9]+ DOT [0-9]+;
HEX: '0x' [0-9a-f]+;

NAME: LO (LETTER | DIGIT)*;
NAME: [a-z][a-z0-9_A-Z]*;

LETTER: (HI | LO);
HI: [A-Z];
LO: [a-z];
DIGIT: [0-9];
105 changes: 105 additions & 0 deletions eo-compiler/src/main/java/org/eolang/compiler/Pack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2020 Yegor Bugayenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.eolang.compiler;

import com.jcabi.xml.ClasspathSources;
import com.jcabi.xml.XSL;
import com.jcabi.xml.XSLDocument;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import org.cactoos.list.ListOf;
import org.cactoos.list.Mapped;

/**
* Pack of all XSL sheets.
*
* @since 0.1
*/
public final class Pack implements Iterable<XSL> {

/**
* All of them.
*/
private final Collection<String> sheets;

/**
* Ctor, with the default sequence of sheets.
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public Pack() {
this(
new ListOf<>(
"errors/not-empty-atoms.xsl",
"errors/middle-varargs.xsl",
"errors/duplicate-names.xsl",
"errors/broken-aliases.xsl",
"errors/duplicate-aliases.xsl",
"errors/global-nonames.xsl",
"errors/same-line-names.xsl",
"errors/self-naming.xsl",
"add-refs.xsl",
"wrap-method-calls.xsl",
"vars-float-up.xsl",
"add-refs.xsl",
"resolve-aliases.xsl",
"add-default-package.xsl",
"errors/broken-refs.xsl",
"errors/unknown-names.xsl",
"errors/noname-attributes.xsl"
)
);
}

/**
* Ctor.
*
* @param names Names of them in classpath
*/
public Pack(final Collection<String> names) {
this.sheets = Collections.unmodifiableCollection(names);
}

@Override
public Iterator<XSL> iterator() {
return new Mapped<>(
doc -> new XSLDocument(
Program.class.getResourceAsStream(doc)
).with(new ClasspathSources()),
this.sheets
).iterator();
}

/**
* Make a copy, with an additional XSL.
* @param xsl Name in classpath
* @return New pack
*/
public Pack with(final String xsl) {
final Collection<String> after = new LinkedList<>(this.sheets);
after.add(xsl);
return new Pack(after);
}
}
Loading

3 comments on commit eba8b28

@0pdd
Copy link

@0pdd 0pdd commented on eba8b28 Dec 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 104-4512cd36 disappeared from eo-compiler/src/test/java/org/eolang/compiler/syntax/ArgumentTest.java, that's why I closed #129. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link

@0pdd 0pdd commented on eba8b28 Dec 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 105-90b91742 disappeared from eo-compiler/src/main/java/org/eolang/compiler/syntax/MethodImpl.java, that's why I closed #131. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link

@0pdd 0pdd commented on eba8b28 Dec 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 95-fabf1b89 disappeared from eo-compiler/src/main/java/org/eolang/compiler/syntax/Object.java, that's why I closed #106. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.