mirror of
https://github.com/objectionary/eo.git
synced 2024-10-26 20:30:44 +03:00
feat(#3108): true
This commit is contained in:
parent
93cf383ffc
commit
7ca6646c30
@ -165,7 +165,7 @@ This is how you iterate:
|
|||||||
x.times x
|
x.times x
|
||||||
x.write
|
x.write
|
||||||
x.plus 1
|
x.plus 1
|
||||||
TRUE
|
true
|
||||||
```
|
```
|
||||||
|
|
||||||
This code will print this:
|
This code will print this:
|
||||||
|
@ -29,4 +29,4 @@
|
|||||||
[] > ensures-equality
|
[] > ensures-equality
|
||||||
eq. > @
|
eq. > @
|
||||||
equality
|
equality
|
||||||
TRUE
|
true
|
@ -81,4 +81,4 @@
|
|||||||
[] > blah38
|
[] > blah38
|
||||||
blah39 > @
|
blah39 > @
|
||||||
[] > blah39
|
[] > blah39
|
||||||
TRUE > @
|
true > @
|
||||||
|
@ -541,7 +541,6 @@ as : COLON (NAME | INT)
|
|||||||
|
|
||||||
// Data
|
// Data
|
||||||
data: BYTES
|
data: BYTES
|
||||||
| BOOL
|
|
||||||
| TEXT
|
| TEXT
|
||||||
| STRING
|
| STRING
|
||||||
| INT
|
| INT
|
||||||
@ -638,10 +637,6 @@ BYTES
|
|||||||
| LINE_BYTES (MINUS EOL LINE_BYTES)*
|
| LINE_BYTES (MINUS EOL LINE_BYTES)*
|
||||||
;
|
;
|
||||||
|
|
||||||
BOOL: 'TRUE'
|
|
||||||
| 'FALSE'
|
|
||||||
;
|
|
||||||
|
|
||||||
fragment ESCAPE_SEQUENCE
|
fragment ESCAPE_SEQUENCE
|
||||||
: '\\' [btnfr"'\\]
|
: '\\' [btnfr"'\\]
|
||||||
| '\\' ([0-3]? [0-7])? [0-7]
|
| '\\' ([0-3]? [0-7])? [0-7]
|
||||||
|
@ -1225,14 +1225,6 @@ public final class XeEoListener implements EoListener, Iterable<Directive> {
|
|||||||
type = "bytes";
|
type = "bytes";
|
||||||
base = "bytes";
|
base = "bytes";
|
||||||
data = text.replaceAll("\\s+", "").replace("-", " ").trim();
|
data = text.replaceAll("\\s+", "").replace("-", " ").trim();
|
||||||
} else if (ctx.BOOL() != null) {
|
|
||||||
type = "bytes";
|
|
||||||
base = "bool";
|
|
||||||
if (Boolean.parseBoolean(text)) {
|
|
||||||
data = XeEoListener.bytesToHex((byte) 0x01);
|
|
||||||
} else {
|
|
||||||
data = XeEoListener.bytesToHex((byte) 0x00);
|
|
||||||
}
|
|
||||||
} else if (ctx.FLOAT() != null) {
|
} else if (ctx.FLOAT() != null) {
|
||||||
type = "bytes";
|
type = "bytes";
|
||||||
base = "float";
|
base = "float";
|
||||||
|
@ -29,12 +29,12 @@
|
|||||||
# Allow to choose right options according to cases conditions.
|
# Allow to choose right options according to cases conditions.
|
||||||
# Parameter cases is the array of two dimensional array, which
|
# Parameter cases is the array of two dimensional array, which
|
||||||
# consist of condition bool value and expected value, if this
|
# consist of condition bool value and expected value, if this
|
||||||
# condition is TRUE.
|
# condition is true.
|
||||||
# e.g.
|
# e.g.
|
||||||
# switch
|
# switch
|
||||||
# *
|
# *
|
||||||
# *
|
# *
|
||||||
# TRUE
|
# true
|
||||||
# "this value will be returned"
|
# "this value will be returned"
|
||||||
# *
|
# *
|
||||||
# FALSE
|
# FALSE
|
||||||
@ -45,12 +45,12 @@
|
|||||||
cases.length > len!
|
cases.length > len!
|
||||||
|
|
||||||
# Take case by given index.
|
# Take case by given index.
|
||||||
# If case key is TRUE, return case value.
|
# If case key is true, return case value.
|
||||||
# Otherwise take next case.
|
# Otherwise take next case.
|
||||||
[index] > case-at
|
[index] > case-at
|
||||||
if > @
|
if > @
|
||||||
index.eq ^.len
|
index.eq ^.len
|
||||||
TRUE
|
true
|
||||||
if
|
if
|
||||||
at.
|
at.
|
||||||
^.cases.at index > case
|
^.cases.at index > case
|
||||||
|
@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* The MIT License (MIT)
|
|
||||||
*
|
|
||||||
* Copyright (c) 2016-2024 Objectionary.com
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @checkstyle PackageNameCheck (4 lines)
|
|
||||||
*/
|
|
||||||
package EOorg.EOeolang;
|
|
||||||
|
|
||||||
import org.eolang.AtVoid;
|
|
||||||
import org.eolang.Atom;
|
|
||||||
import org.eolang.Param;
|
|
||||||
import org.eolang.PhDefault;
|
|
||||||
import org.eolang.Phi;
|
|
||||||
import org.eolang.Versionized;
|
|
||||||
import org.eolang.XmirObject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* IF.
|
|
||||||
*
|
|
||||||
* @since 0.36.0
|
|
||||||
* @checkstyle TypeNameCheck (5 lines)
|
|
||||||
*/
|
|
||||||
@Versionized
|
|
||||||
@XmirObject(oname = "if")
|
|
||||||
public final class EOif extends PhDefault implements Atom {
|
|
||||||
/**
|
|
||||||
* Ctor.
|
|
||||||
* @param sigma Sigma
|
|
||||||
*/
|
|
||||||
public EOif(final Phi sigma) {
|
|
||||||
super(sigma);
|
|
||||||
this.add("condition", new AtVoid("condition"));
|
|
||||||
this.add("left", new AtVoid("left"));
|
|
||||||
this.add("right", new AtVoid("right"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Phi lambda() {
|
|
||||||
final Phi out;
|
|
||||||
if (new Param(this, "condition").strong(Boolean.class)) {
|
|
||||||
out = this.take("left");
|
|
||||||
} else {
|
|
||||||
out = this.take("right");
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
}
|
|
@ -146,46 +146,37 @@ public interface Data {
|
|||||||
*/
|
*/
|
||||||
private static Phi toPhi(final Object obj) {
|
private static Phi toPhi(final Object obj) {
|
||||||
final Phi phi;
|
final Phi phi;
|
||||||
final byte[] bytes;
|
|
||||||
final boolean delta;
|
|
||||||
final Phi eolang = Phi.Φ.take("org").take("eolang");
|
final Phi eolang = Phi.Φ.take("org").take("eolang");
|
||||||
if (obj instanceof Boolean) {
|
if (obj instanceof Boolean) {
|
||||||
phi = eolang.take("bool").copy();
|
|
||||||
delta = false;
|
|
||||||
if (obj.equals(true)) {
|
if (obj.equals(true)) {
|
||||||
bytes = new byte[] {0x01};
|
phi = eolang.take("true");
|
||||||
} else {
|
} else {
|
||||||
bytes = new byte[] {0x00};
|
phi = eolang.take("false");
|
||||||
}
|
}
|
||||||
} else if (obj instanceof byte[]) {
|
} else if (obj instanceof byte[]) {
|
||||||
phi = eolang.take("bytes").copy();
|
phi = eolang.take("bytes").copy();
|
||||||
delta = true;
|
phi.attach((byte[]) obj);
|
||||||
bytes = (byte[]) obj;
|
|
||||||
} else if (obj instanceof Long) {
|
|
||||||
phi = eolang.take("int").copy();
|
|
||||||
delta = false;
|
|
||||||
bytes = new BytesOf((Long) obj).take();
|
|
||||||
} else if (obj instanceof String) {
|
|
||||||
phi = eolang.take("string").copy();
|
|
||||||
delta = false;
|
|
||||||
bytes = Data.ToPhi.unescapeJavaString(
|
|
||||||
(String) obj
|
|
||||||
).getBytes(StandardCharsets.UTF_8);
|
|
||||||
} else if (obj instanceof Double) {
|
|
||||||
phi = eolang.take("float").copy();
|
|
||||||
delta = false;
|
|
||||||
bytes = new BytesOf((Double) obj).take();
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
String.format(
|
|
||||||
"Unknown type of data: %s",
|
|
||||||
obj.getClass().getCanonicalName()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (delta) {
|
|
||||||
phi.attach(bytes);
|
|
||||||
} else {
|
} else {
|
||||||
|
final byte[] bytes;
|
||||||
|
if (obj instanceof Long) {
|
||||||
|
phi = eolang.take("int").copy();
|
||||||
|
bytes = new BytesOf((Long) obj).take();
|
||||||
|
} else if (obj instanceof String) {
|
||||||
|
phi = eolang.take("string").copy();
|
||||||
|
bytes = Data.ToPhi.unescapeJavaString(
|
||||||
|
(String) obj
|
||||||
|
).getBytes(StandardCharsets.UTF_8);
|
||||||
|
} else if (obj instanceof Double) {
|
||||||
|
phi = eolang.take("float").copy();
|
||||||
|
bytes = new BytesOf((Double) obj).take();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"Unknown type of data: %s",
|
||||||
|
obj.getClass().getCanonicalName()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
final Phi bts = eolang.take("bytes").copy();
|
final Phi bts = eolang.take("bytes").copy();
|
||||||
bts.attach(bytes);
|
bts.attach(bytes);
|
||||||
phi.put(0, bts);
|
phi.put(0, bts);
|
||||||
|
@ -134,7 +134,7 @@ public final class Main {
|
|||||||
/**
|
/**
|
||||||
* Process one option.
|
* Process one option.
|
||||||
* @param opt The option
|
* @param opt The option
|
||||||
* @return TRUE if it's time to exit
|
* @return True if it's time to exit
|
||||||
* @throws IOException If fails
|
* @throws IOException If fails
|
||||||
*/
|
*/
|
||||||
private static boolean parse(final String opt) throws IOException {
|
private static boolean parse(final String opt) throws IOException {
|
||||||
|
@ -29,18 +29,18 @@
|
|||||||
# Test.
|
# Test.
|
||||||
[] > compares-two-bools
|
[] > compares-two-bools
|
||||||
eq. > @
|
eq. > @
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
|
|
||||||
# Test.
|
# Test.
|
||||||
[] > true-as-bool
|
[] > true-as-bool
|
||||||
TRUE.as-bool > @
|
true.as-bool > @
|
||||||
|
|
||||||
# Test.
|
# Test.
|
||||||
[] > compares-two-different-types
|
[] > compares-two-different-types
|
||||||
not. > @
|
not. > @
|
||||||
eq.
|
eq.
|
||||||
TRUE
|
true
|
||||||
42
|
42
|
||||||
|
|
||||||
# Test.
|
# Test.
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
if
|
if
|
||||||
i.as-int.lt 10
|
i.as-int.lt 10
|
||||||
g.backward
|
g.backward
|
||||||
TRUE
|
true
|
||||||
stdout "Finished!\n"
|
stdout "Finished!\n"
|
||||||
i
|
i
|
||||||
10
|
10
|
||||||
@ -62,7 +62,7 @@
|
|||||||
*
|
*
|
||||||
if
|
if
|
||||||
x.eq 0
|
x.eq 0
|
||||||
g.forward TRUE
|
g.forward true
|
||||||
TRUE
|
TRUE
|
||||||
r.write (42.div x)
|
r.write (42.div x)
|
||||||
(dataized r).as-bytes > result
|
(dataized r).as-bytes > result
|
||||||
|
@ -112,7 +112,7 @@
|
|||||||
and. > @
|
and. > @
|
||||||
QQ.io.stdout e
|
QQ.io.stdout e
|
||||||
m.free
|
m.free
|
||||||
TRUE
|
true
|
||||||
|
|
||||||
# Test.
|
# Test.
|
||||||
[] > memory-is-strictly-typed-string-error-overflow
|
[] > memory-is-strictly-typed-string-error-overflow
|
||||||
|
@ -76,7 +76,7 @@
|
|||||||
[] > negative-infinity-lt-positive-infinity
|
[] > negative-infinity-lt-positive-infinity
|
||||||
eq. > @
|
eq. > @
|
||||||
negative-infinity.lt positive-infinity
|
negative-infinity.lt positive-infinity
|
||||||
TRUE
|
true
|
||||||
|
|
||||||
# Test.
|
# Test.
|
||||||
[] > negative-infinity-not-lt-nan
|
[] > negative-infinity-not-lt-nan
|
||||||
@ -100,13 +100,13 @@
|
|||||||
[] > negative-infinity-lte-negative-infinity
|
[] > negative-infinity-lte-negative-infinity
|
||||||
eq. > @
|
eq. > @
|
||||||
negative-infinity.lte negative-infinity
|
negative-infinity.lte negative-infinity
|
||||||
TRUE
|
true
|
||||||
|
|
||||||
# Test.
|
# Test.
|
||||||
[] > negative-infinity-lte-positive-infinity
|
[] > negative-infinity-lte-positive-infinity
|
||||||
eq. > @
|
eq. > @
|
||||||
negative-infinity.lte positive-infinity
|
negative-infinity.lte positive-infinity
|
||||||
TRUE
|
true
|
||||||
|
|
||||||
# Test.
|
# Test.
|
||||||
[] > negative-infinity-not-lte-nan
|
[] > negative-infinity-not-lte-nan
|
||||||
@ -118,13 +118,13 @@
|
|||||||
[] > negative-infinity-lte-int
|
[] > negative-infinity-lte-int
|
||||||
eq. > @
|
eq. > @
|
||||||
negative-infinity.lte 42
|
negative-infinity.lte 42
|
||||||
TRUE
|
true
|
||||||
|
|
||||||
# Test.
|
# Test.
|
||||||
[] > negative-infinity-lte-float
|
[] > negative-infinity-lte-float
|
||||||
eq. > @
|
eq. > @
|
||||||
negative-infinity.lte 42.5
|
negative-infinity.lte 42.5
|
||||||
TRUE
|
true
|
||||||
|
|
||||||
# Greater than.
|
# Greater than.
|
||||||
[] > negative-infinity-gt-negative-infinity
|
[] > negative-infinity-gt-negative-infinity
|
||||||
|
@ -100,7 +100,7 @@
|
|||||||
[] > positive-infinity-lte-positive-infinity
|
[] > positive-infinity-lte-positive-infinity
|
||||||
eq. > @
|
eq. > @
|
||||||
positive-infinity.lte positive-infinity
|
positive-infinity.lte positive-infinity
|
||||||
TRUE
|
true
|
||||||
|
|
||||||
# Test.
|
# Test.
|
||||||
[] > positive-infinity-not-lte-negative-infinity
|
[] > positive-infinity-not-lte-negative-infinity
|
||||||
|
@ -82,51 +82,51 @@
|
|||||||
# This test should have acceptable time to pass.
|
# This test should have acceptable time to pass.
|
||||||
[] > very-long-seq
|
[] > very-long-seq
|
||||||
eq. > @
|
eq. > @
|
||||||
TRUE
|
true
|
||||||
seq
|
seq
|
||||||
*
|
*
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
TRUE
|
true
|
||||||
|
|
||||||
# Test.
|
# Test.
|
||||||
[] > seq-single-dataization-int-equal-to-test
|
[] > seq-single-dataization-int-equal-to-test
|
||||||
|
@ -148,7 +148,7 @@
|
|||||||
eq.
|
eq.
|
||||||
"x"
|
"x"
|
||||||
"x"
|
"x"
|
||||||
TRUE
|
true
|
||||||
|
|
||||||
# Test.
|
# Test.
|
||||||
[] > one-symbol-string-compares
|
[] > one-symbol-string-compares
|
||||||
@ -240,7 +240,7 @@
|
|||||||
1
|
1
|
||||||
[e]
|
[e]
|
||||||
QQ.io.stdout e > @
|
QQ.io.stdout e > @
|
||||||
TRUE
|
true
|
||||||
|
|
||||||
# Test.
|
# Test.
|
||||||
[] > slice-end-below-start
|
[] > slice-end-below-start
|
||||||
@ -252,7 +252,7 @@
|
|||||||
-1
|
-1
|
||||||
[e]
|
[e]
|
||||||
QQ.io.stdout e > @
|
QQ.io.stdout e > @
|
||||||
TRUE
|
true
|
||||||
|
|
||||||
# Test.
|
# Test.
|
||||||
[] > slice-end-greater-actual
|
[] > slice-end-greater-actual
|
||||||
@ -264,4 +264,4 @@
|
|||||||
5
|
5
|
||||||
[e]
|
[e]
|
||||||
QQ.io.stdout e > @
|
QQ.io.stdout e > @
|
||||||
TRUE
|
true
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
FALSE
|
FALSE
|
||||||
"1"
|
"1"
|
||||||
*
|
*
|
||||||
TRUE
|
true
|
||||||
"2"
|
"2"
|
||||||
"2"
|
"2"
|
||||||
|
|
||||||
@ -62,13 +62,13 @@
|
|||||||
switch
|
switch
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
TRUE
|
true
|
||||||
"TRUE1"
|
"TRUE1"
|
||||||
*
|
*
|
||||||
FALSE
|
FALSE
|
||||||
"FALSE"
|
"FALSE"
|
||||||
*
|
*
|
||||||
TRUE
|
true
|
||||||
"TRUE2"
|
"TRUE2"
|
||||||
"TRUE1"
|
"TRUE1"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user