Skip to content

Commit

Permalink
feat(#3164): extended syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed May 4, 2024
1 parent fd8407f commit 3db334f
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 92 deletions.
43 changes: 23 additions & 20 deletions eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ vapplicationArgUnbound
vapplicationArgUnboundCurrent
: vapplicationArgHapplicationUnbound // horizontal application
| vapplicationArgHanonymUnbound // horizontal anonym object
| onlyphiNamed // unnamed abstract object with only @-bound attribute
| justNamed // just an object reference
| methodNamed // method
;
Expand All @@ -297,7 +296,7 @@ vapplicationArgHapplicationUnbound
;

formationNameless
: attributes autoOname? innersOrEol
: attributes aname? innersOrEol
;

// Formation with or without name
Expand All @@ -310,7 +309,7 @@ formationNamedOrNameless
// Ends on the next line
vapplicationArgVanonymBound
: commentOptional attributesAs oname innersOrEol
| attributesAs autoOname? innersOrEol
| attributesAs aname? innersOrEol
;

attributesAs
Expand All @@ -324,35 +323,39 @@ vapplicationArgHanonymBoundBody
// Horizontal anonym abstract object as argument of vertical application
vapplicationArgHanonymBound
: commentOptional vapplicationArgHanonymBoundBody oname
| vapplicationArgHanonymBoundBody
| vapplicationArgHanonymBoundBody aname?
;

vapplicationArgHanonymUnbound
: commentOptional hanonym oname
| hanonym
| hanonym aname?
;

// Horizontal formation
hformation
: attributes hanonymInner+
;

// Horizontal anonym object
hanonym
: attributes hanonymInner+
: hformation
| onlyphi
;

// Unnamed abstract object with only @-bound attribute
// x.y.z > [i] -> [i] (x.y.z > @)
// x y z > [i] -> [i] (x y z > @)
// [a] (b > c) > [i] -> [i] ([a] (b > c) > @)
// a > [i] > [j] -> [j] ([i] (a > @) > @)
// x > [i] -> [i] (x > @)
onlyphi
: (hmethod | happlication | hanonym | just) onlyphiTail
;

// Only-@-bound object with name
onlyphiNamed
: onlyphi oname?
: (hmethod | happlication | hformation | just) onlyphiTail
| onlyphi onlyphiTail
;

// Tail of the unnamed abstract object with only @-bound attribute
onlyphiTail: spacedArrow attributes
onlyphiTail
: spacedArrow attributes
;

// Inner object of horizontal anonym object
Expand Down Expand Up @@ -448,7 +451,7 @@ vmethodOptional
vmethodHead
: vmethodHead methodTailOptional vmethodHeadApplicationTail
| vmethodHeadVapplication
| (justNamed | onlyphiNamed) EOL
| (justNamed | hanonym (oname | aname)?) EOL
| formationNamedOrNameless
;

Expand Down Expand Up @@ -514,16 +517,16 @@ reversed
: finisher DOT
;

// Automatic name of the object
autoOname
: SPACE ARROW ARROW
;

// Object name
oname
: suffix CONST?
;

// Automatic name of the object
aname
: SPACE ARROW ARROW
;

// Suffix
suffix
: spacedArrow (PHI | NAME)
Expand All @@ -537,7 +540,7 @@ spacedArrow
// Does not contain elements in vertical notation
// Is used in happlicationArg, hmethodHead
scope
: LB (happlication | hanonym | onlyphi) RB
: LB (happlication | hanonym) RB
;

// Version
Expand Down
20 changes: 10 additions & 10 deletions eo-parser/src/main/java/org/eolang/parser/XeEoListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -772,32 +772,32 @@ public void exitVapplicationArgHanonymUnbound(
}

@Override
public void enterHanonym(final EoParser.HanonymContext ctx) {
public void enterHformation(final EoParser.HformationContext ctx) {
this.startAbstract(ctx);
}

@Override
public void exitHanonym(final EoParser.HanonymContext ctx) {
public void exitHformation(final EoParser.HformationContext ctx) {
// Nothing here
}

@Override
public void enterOnlyphi(final EoParser.OnlyphiContext ctx) {
this.startAbstract(ctx).enter();
public void enterHanonym(final EoParser.HanonymContext ctx) {
// Nothing here
}

@Override
public void exitOnlyphi(final EoParser.OnlyphiContext ctx) {
public void exitHanonym(final EoParser.HanonymContext ctx) {
// Nothing here
}

@Override
public void enterOnlyphiNamed(final EoParser.OnlyphiNamedContext ctx) {
// Nothing here
public void enterOnlyphi(final EoParser.OnlyphiContext ctx) {
this.startAbstract(ctx).enter();
}

@Override
public void exitOnlyphiNamed(final EoParser.OnlyphiNamedContext ctx) {
public void exitOnlyphi(final EoParser.OnlyphiContext ctx) {
// Nothing here
}

Expand Down Expand Up @@ -1098,7 +1098,7 @@ public void exitReversed(final EoParser.ReversedContext ctx) {
}

@Override
public void enterAutoOname(final EoParser.AutoOnameContext ctx) {
public void enterAname(final EoParser.AnameContext ctx) {
this.objects
.enter()
.prop(
Expand All @@ -1109,7 +1109,7 @@ public void enterAutoOname(final EoParser.AutoOnameContext ctx) {
}

@Override
public void exitAutoOname(final EoParser.AutoOnameContext ctx) {
public void exitAname(final EoParser.AnameContext ctx) {
// Nothing here
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
xsls: [ ]
tests:
- //o[@base='a']/o[@abstract and not(@name) and o[@name='@' and @base='.b'] and o[not(@base) and @name='i']]
- //o[@base='a']/o[@abstract and not(@name) and o[@name='@' and @base='a' and o[@base='b']]]
- //o[@base='a']/o[@abstract and not(@name) and o[@abstract and @name='@' and o[@base='a' and @name='b']] and o[@name='c']]
- //o[@base='a']/o[@abstract and not(@name) and o[@base='d' and @name='@']]
- //o[@base='p']/o[@abstract and @name='first' and o[@name='@' and @base='.b'] and o[not(@base) and @name='i']]
- //o[@base='p']/o[@abstract and not(@name) and o[@name='@' and @base='a' and o[@base='b']]]
- //o[@base='p']/o[@abstract and @name='second' and o[@abstract and @name='@' and o[@base='a' and @name='b']] and o[@name='c']]
- //o[@base='p']/o[@abstract and not(@name) and o[@base='d' and @name='@']]
- //o[@abstract and o[@base='z' and @name='@']]/following-sibling::o[@base='.x' and @method]
- //o[@base='m']/o[@abstract and not(@name) and o[@name='q' and not(@base)] and o[@base='q' and @name='@']]
eo: |
a > x
a.b > [i]
p > x
a.b > [i] > first
a b > []
[o] (a > b) > [c]
[o] (a > b) > [c] > second
d > []
z > []
.x
Expand Down
16 changes: 6 additions & 10 deletions eo-runtime/src/main/eo/org/eolang/bytes.eo
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

# Bytes.
[] > bytes
# Return itself.
$ > as-bytes

# Equals to another object.
[b] > eq /bool

Expand All @@ -38,8 +41,7 @@
[start len] > slice /bytes

# Turn this chain of bytes into a string in UTF-8.
[] > as-string
string ^ > @
string ^ > [] > as-string

# Turn this chain of eight bytes into an integer.
# If there are less or more than eight bytes, there will
Expand Down Expand Up @@ -72,19 +74,13 @@
[] > not /bytes

# Calculate bitwise left shift.
[x] > left
^.right x.neg > @
^.right x.neg > [x] > left

# Calculate bitwise right shift.
[x] > right /bytes

# Converts to bool.
[] > as-bool
^.eq 01- > @

# Return itself.
[] > as-bytes
^ > @
^.eq 01- > [] > as-bool

# Concatenation of two byte sequences:
# the current and the provided one,
Expand Down
3 changes: 1 addition & 2 deletions eo-runtime/src/main/eo/org/eolang/cti.eo
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@

# Compile Time Instruction.
# Make possible to highlight deprecated methods.
[delegate level message] > cti
delegate > @
delegate > [delegate level message] > cti
9 changes: 3 additions & 6 deletions eo-runtime/src/main/eo/org/eolang/false.eo
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@

# Control structure that allows for conditional execution of code.
# Since $ is FALSE - behaves as `right` object.
[left right] > if
right > @
right > [left right] > if

# And.
[x] > and
^ > @
^ > [x] > and

# Or.
[x] > or
01-.eq x > @
01-.eq x > [x] > or
6 changes: 2 additions & 4 deletions eo-runtime/src/main/eo/org/eolang/float.eo
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@
[x] > plus /float

# Negation of $.
[] > neg
^.times -1.0 > @
^.times -1.0 > [] > neg

# Difference between $ and x.
[x] > minus
^.plus x.neg > @
^.plus x.neg > [x] > minus

# Quotient of the division of $ by x.
[x] > div /float
6 changes: 2 additions & 4 deletions eo-runtime/src/main/eo/org/eolang/int.eo
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@
x > value!

# Change the sign of the number.
[] > neg
^.times -1 > @
^.times -1 > [] > neg

# Add to the current one.
[x] > plus /int

# Subtract from the current one.
[x] > minus
^.plus x.neg > @
^.plus x.neg > [x] > minus

# Multiplication this one by another int.
[x] > times /int
Expand Down
2 changes: 1 addition & 1 deletion eo-runtime/src/main/eo/org/eolang/io/stdout.eo
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
+version 0.0.0

# Stdout.
[text] > stdout /bool
[text] > stdout /true
3 changes: 1 addition & 2 deletions eo-runtime/src/main/eo/org/eolang/malloc.eo
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@
[offset data] > write /true

# Just get all the data from the allocated block in memory.
[] > get
^.read 0 ^.size > @
^.read 0 ^.size > [] > get

# Put `object` into the allocated block in memory. The `object` is supposed to be dataizable.
[object] > put
Expand Down
30 changes: 10 additions & 20 deletions eo-runtime/src/main/eo/org/eolang/nan.eo
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,31 @@
0.0.div 0.0 > @

# Tests that $ = x.
[x] > eq
false > @
false > [x] > eq

# Tests that $ < x.
[x] > lt
false > @
false > [x] > lt

# Tests that $ ≤ x.
[x] > lte
false > @
false > [x] > lte

# Tests that $ > x.
[x] > gt
false > @
false > [x] > gt

# Tests that $ ≥ x.
[x] > gte
false > @
false > [x] > gte

# Multiplication of $ and x.
[x] > times
& > @
& > [x] > times

# Sum of $ and x.
[x] > plus
& > @
& > [x] > plus

# Negation of $.
[] > neg
& > @
& > [] > neg

# Difference between $ and x.
[x] > minus
& > @
& > [x] > minus

# Quotient of the division of $ by x.
[x] > div
& > @
& > [x] > div
9 changes: 3 additions & 6 deletions eo-runtime/src/main/eo/org/eolang/true.eo
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@

# Control structure that allows for conditional execution of code.
# Since $ is TRUE - behaves as `left` object.
[left right] > if
left > @
left > [left right] > if

# And.
[x] > and
01-.eq x > @
01-.eq x > [x] > and

# Or.
[x] > or
^ > @
^ > [x] > or

0 comments on commit 3db334f

Please sign in to comment.