mirror of
https://github.com/objectionary/eo.git
synced 2024-07-14 16:00:24 +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.write
|
||||
x.plus 1
|
||||
TRUE
|
||||
true
|
||||
```
|
||||
|
||||
This code will print this:
|
||||
|
@ -29,4 +29,4 @@
|
||||
[] > ensures-equality
|
||||
eq. > @
|
||||
equality
|
||||
TRUE
|
||||
true
|
@ -81,4 +81,4 @@
|
||||
[] > blah38
|
||||
blah39 > @
|
||||
[] > blah39
|
||||
TRUE > @
|
||||
true > @
|
||||
|
@ -541,7 +541,6 @@ as : COLON (NAME | INT)
|
||||
|
||||
// Data
|
||||
data: BYTES
|
||||
| BOOL
|
||||
| TEXT
|
||||
| STRING
|
||||
| INT
|
||||
@ -638,10 +637,6 @@ BYTES
|
||||
| LINE_BYTES (MINUS EOL LINE_BYTES)*
|
||||
;
|
||||
|
||||
BOOL: 'TRUE'
|
||||
| 'FALSE'
|
||||
;
|
||||
|
||||
fragment ESCAPE_SEQUENCE
|
||||
: '\\' [btnfr"'\\]
|
||||
| '\\' ([0-3]? [0-7])? [0-7]
|
||||
|
@ -1225,14 +1225,6 @@ public final class XeEoListener implements EoListener, Iterable<Directive> {
|
||||
type = "bytes";
|
||||
base = "bytes";
|
||||
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) {
|
||||
type = "bytes";
|
||||
base = "float";
|
||||
|
@ -29,12 +29,12 @@
|
||||
# Allow to choose right options according to cases conditions.
|
||||
# Parameter cases is the array of two dimensional array, which
|
||||
# consist of condition bool value and expected value, if this
|
||||
# condition is TRUE.
|
||||
# condition is true.
|
||||
# e.g.
|
||||
# switch
|
||||
# *
|
||||
# *
|
||||
# TRUE
|
||||
# true
|
||||
# "this value will be returned"
|
||||
# *
|
||||
# FALSE
|
||||
@ -45,12 +45,12 @@
|
||||
cases.length > len!
|
||||
|
||||
# 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.
|
||||
[index] > case-at
|
||||
if > @
|
||||
index.eq ^.len
|
||||
TRUE
|
||||
true
|
||||
if
|
||||
at.
|
||||
^.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) {
|
||||
final Phi phi;
|
||||
final byte[] bytes;
|
||||
final boolean delta;
|
||||
final Phi eolang = Phi.Φ.take("org").take("eolang");
|
||||
if (obj instanceof Boolean) {
|
||||
phi = eolang.take("bool").copy();
|
||||
delta = false;
|
||||
if (obj.equals(true)) {
|
||||
bytes = new byte[] {0x01};
|
||||
phi = eolang.take("true");
|
||||
} else {
|
||||
bytes = new byte[] {0x00};
|
||||
phi = eolang.take("false");
|
||||
}
|
||||
} else if (obj instanceof byte[]) {
|
||||
phi = eolang.take("bytes").copy();
|
||||
delta = true;
|
||||
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);
|
||||
phi.attach((byte[]) obj);
|
||||
} 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();
|
||||
bts.attach(bytes);
|
||||
phi.put(0, bts);
|
||||
|
@ -134,7 +134,7 @@ public final class Main {
|
||||
/**
|
||||
* Process one 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
|
||||
*/
|
||||
private static boolean parse(final String opt) throws IOException {
|
||||
|
@ -29,18 +29,18 @@
|
||||
# Test.
|
||||
[] > compares-two-bools
|
||||
eq. > @
|
||||
TRUE
|
||||
TRUE
|
||||
true
|
||||
true
|
||||
|
||||
# Test.
|
||||
[] > true-as-bool
|
||||
TRUE.as-bool > @
|
||||
true.as-bool > @
|
||||
|
||||
# Test.
|
||||
[] > compares-two-different-types
|
||||
not. > @
|
||||
eq.
|
||||
TRUE
|
||||
true
|
||||
42
|
||||
|
||||
# Test.
|
||||
|
@ -43,7 +43,7 @@
|
||||
if
|
||||
i.as-int.lt 10
|
||||
g.backward
|
||||
TRUE
|
||||
true
|
||||
stdout "Finished!\n"
|
||||
i
|
||||
10
|
||||
@ -62,7 +62,7 @@
|
||||
*
|
||||
if
|
||||
x.eq 0
|
||||
g.forward TRUE
|
||||
g.forward true
|
||||
TRUE
|
||||
r.write (42.div x)
|
||||
(dataized r).as-bytes > result
|
||||
|
@ -112,7 +112,7 @@
|
||||
and. > @
|
||||
QQ.io.stdout e
|
||||
m.free
|
||||
TRUE
|
||||
true
|
||||
|
||||
# Test.
|
||||
[] > memory-is-strictly-typed-string-error-overflow
|
||||
|
@ -76,7 +76,7 @@
|
||||
[] > negative-infinity-lt-positive-infinity
|
||||
eq. > @
|
||||
negative-infinity.lt positive-infinity
|
||||
TRUE
|
||||
true
|
||||
|
||||
# Test.
|
||||
[] > negative-infinity-not-lt-nan
|
||||
@ -100,13 +100,13 @@
|
||||
[] > negative-infinity-lte-negative-infinity
|
||||
eq. > @
|
||||
negative-infinity.lte negative-infinity
|
||||
TRUE
|
||||
true
|
||||
|
||||
# Test.
|
||||
[] > negative-infinity-lte-positive-infinity
|
||||
eq. > @
|
||||
negative-infinity.lte positive-infinity
|
||||
TRUE
|
||||
true
|
||||
|
||||
# Test.
|
||||
[] > negative-infinity-not-lte-nan
|
||||
@ -118,13 +118,13 @@
|
||||
[] > negative-infinity-lte-int
|
||||
eq. > @
|
||||
negative-infinity.lte 42
|
||||
TRUE
|
||||
true
|
||||
|
||||
# Test.
|
||||
[] > negative-infinity-lte-float
|
||||
eq. > @
|
||||
negative-infinity.lte 42.5
|
||||
TRUE
|
||||
true
|
||||
|
||||
# Greater than.
|
||||
[] > negative-infinity-gt-negative-infinity
|
||||
|
@ -100,7 +100,7 @@
|
||||
[] > positive-infinity-lte-positive-infinity
|
||||
eq. > @
|
||||
positive-infinity.lte positive-infinity
|
||||
TRUE
|
||||
true
|
||||
|
||||
# Test.
|
||||
[] > positive-infinity-not-lte-negative-infinity
|
||||
|
@ -82,51 +82,51 @@
|
||||
# This test should have acceptable time to pass.
|
||||
[] > very-long-seq
|
||||
eq. > @
|
||||
TRUE
|
||||
true
|
||||
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.
|
||||
[] > seq-single-dataization-int-equal-to-test
|
||||
|
@ -148,7 +148,7 @@
|
||||
eq.
|
||||
"x"
|
||||
"x"
|
||||
TRUE
|
||||
true
|
||||
|
||||
# Test.
|
||||
[] > one-symbol-string-compares
|
||||
@ -240,7 +240,7 @@
|
||||
1
|
||||
[e]
|
||||
QQ.io.stdout e > @
|
||||
TRUE
|
||||
true
|
||||
|
||||
# Test.
|
||||
[] > slice-end-below-start
|
||||
@ -252,7 +252,7 @@
|
||||
-1
|
||||
[e]
|
||||
QQ.io.stdout e > @
|
||||
TRUE
|
||||
true
|
||||
|
||||
# Test.
|
||||
[] > slice-end-greater-actual
|
||||
@ -264,4 +264,4 @@
|
||||
5
|
||||
[e]
|
||||
QQ.io.stdout e > @
|
||||
TRUE
|
||||
true
|
||||
|
@ -35,7 +35,7 @@
|
||||
FALSE
|
||||
"1"
|
||||
*
|
||||
TRUE
|
||||
true
|
||||
"2"
|
||||
"2"
|
||||
|
||||
@ -62,13 +62,13 @@
|
||||
switch
|
||||
*
|
||||
*
|
||||
TRUE
|
||||
true
|
||||
"TRUE1"
|
||||
*
|
||||
FALSE
|
||||
"FALSE"
|
||||
*
|
||||
TRUE
|
||||
true
|
||||
"TRUE2"
|
||||
"TRUE1"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user