Skip to content

Commit

Permalink
Merge pull request #3654 from maxonfjvipon/fix/#3649/pretty-braces-in…
Browse files Browse the repository at this point in the history
…-phi

fix(#3649): pretty braces in phi + lambda function grammar
  • Loading branch information
yegor256 authored Dec 12, 2024
2 parents de9d416 + ed6b5e6 commit b17fad5
Show file tree
Hide file tree
Showing 33 changed files with 297 additions and 346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ SOFTWARE.
</xsl:when>
<xsl:otherwise>
<xsl:text>.</xsl:text>
<xsl:value-of select="."/>
<xsl:choose>
<xsl:when test=".='φ'">
<xsl:text>@</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
# SOFTWARE.
---
asserts:
- //o[@base='org.eolang.io.stdout' and not(@abstract) and @name='x']
- //o[@base='org.eolang.io.stdout' and not(@abstract) and @name='x']/o[@as='text' and @base='.bytes']
- //o[@base='org.eolang.io.stdout' and not(@abstract) and @name='x']/o[@as='size' and @base='.int']
- //o[@base='org.eolang.io.stdout' and @name='x']/o[@as='text' and @base='.bytes']
- //o[@base='org.eolang.io.stdout' and @name='x']/o[@as='size' and @base='.int']
- //o[@base='org.eolang.malloc.@' and @name='y']/o[@as='arg' and @base='.nan']
phi: |
{
Expand All @@ -37,6 +37,10 @@ phi: |
),
λ ⤍ Lorg_eolang_io_stdout
⟧,
y ↦ ⟦
arg ↦ Φ.org.eolang.nan,
λ ⤍ Lorg_eolang_malloc_φ
⟧,
λ ⤍ Package
⟧,
λ ⤍ Package
Expand Down
2 changes: 1 addition & 1 deletion eo-parser/src/main/antlr4/org/eolang/parser/Phi.g4
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ lambdaBinding
;

FUNCTION
: [A-Z] ~[ \r\n\t,.|':;!\-?\][}{)(⟧⟦]*
: [A-Z][A-Za-z_φ]*
;

application
Expand Down
8 changes: 3 additions & 5 deletions eo-parser/src/main/resources/org/eolang/parser/phi/to-phi.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,9 @@ SOFTWARE.
<xsl:copy-of select="./errors"/>
<phi>
<xsl:text>{</xsl:text>
<xsl:variable name="tabs" select="2"/>
<xsl:value-of select="eo:eol(1)"/>
<xsl:value-of select="$lb"/>
<xsl:value-of select="eo:eol(2)"/>
<xsl:variable name="tabs" select="1"/>
<xsl:value-of select="eo:eol(1)"/>
<xsl:variable name="has-package" select="metas/meta/head[text()='package']"/>
<xsl:variable name="package" select="metas/meta[head[text()='package']]/tail[1]"/>
<xsl:variable name="parts" select="tokenize($package,'\.')"/>
Expand Down Expand Up @@ -310,9 +309,8 @@ SOFTWARE.
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="eo:eol(1)"/>
<xsl:value-of select="$rb"/>
<xsl:value-of select="eo:eol(0)"/>
<xsl:value-of select="$rb"/>
<xsl:text>}</xsl:text>
</phi>
</program>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ input: |
as-phi $
$.greater-than 0
with-sugar: |-
{
prints-itself ↦ ⟦
φ ↦ Φ̇.assert-that(Φ̇.as-phi(ξ).length, ξ.greater-than(0))
{⟦
prints-itself ↦ ⟦
φ ↦ Φ̇.assert-that(Φ̇.as-phi(ξ).length, ξ.greater-than(0))
}
}
no-sugar: |-
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,16 @@ input: |
# No comments.
[] > inner /bytes
with-sugar: |-
{
main ↦ ⟦
λ ⤍ Lmain
⟧,
outer ↦ ⟦
inner ↦ ⟦
λ ⤍ Louter_inner
{⟦
main ↦ ⟦
λ ⤍ Lmain
⟧,
outer ↦ ⟦
inner ↦ ⟦
λ ⤍ Louter_inner
}
}
no-sugar: |-
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ input: |
[] >>
01- > b
with-sugar: |-
{
object ↦ ⟦
first ↦ Φ̇.x(ξ.auto-named-attr-at-4-6),
auto-named-attr-at-4-6 ↦ ⟦
b ↦ Φ̇.bytes(⟦ Δ ⤍ 01- ⟧)
{⟦
object ↦ ⟦
first ↦ Φ̇.x(ξ.auto-named-attr-at-4-6),
auto-named-attr-at-4-6 ↦ ⟦
b ↦ Φ̇.bytes(⟦ Δ ⤍ 01- ⟧)
}
}
no-sugar: |-
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,17 @@ input: |
5:five
"hello":3
with-sugar: |-
{
xyz ↦ Φ̇.x(
attr ↦ Φ̇.y,
abs ↦ ⟦
z ↦ ∅,
φ ↦ Φ̇.w
⟧,
five ↦ 5,
α3 ↦ "hello"
)
}
{⟦
xyz ↦ Φ̇.x(
attr ↦ Φ̇.y,
abs ↦ ⟦
z ↦ ∅,
φ ↦ Φ̇.w
⟧,
five ↦ 5,
α3 ↦ "hello"
)
⟧}
no-sugar: |-
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,38 +85,36 @@ input: |
00-.as-bytes.eq false
with-sugar: |-
{
org ↦ ⟦
eolang ↦ ⟦
compares-two-bools ↦ ⟦
φ ↦ Φ̇.true.eq(Φ̇.true)
⟧,
true-as-bool ↦ ⟦
φ ↦ Φ̇.true.as-bool
⟧,
compares-two-different-types ↦ ⟦
φ ↦ Φ̇.true.eq(42).not
⟧,
compares-bool-to-bytes ↦ ⟦
φ ↦ Φ̇.true.eq(Φ̇.bytes(⟦ Δ ⤍ 01- ⟧)).and(
Φ̇.false.eq(Φ̇.bytes(⟦ Δ ⤍ 00- ⟧))
)
⟧,
compares-bool-to-string ↦ ⟦
φ ↦ Φ̇.true.eq("\u0001").and(Φ̇.false.eq("\u0000"))
⟧,
compares-bool-to-bytes-reverse ↦ ⟦
φ ↦ Φ̇.bytes(⟦ Δ ⤍ 01- ⟧).as-bytes.eq(Φ̇.true).and(
Φ̇.bytes(⟦ Δ ⤍ 00- ⟧).as-bytes.eq(Φ̇.false)
)
⟧,
λ ⤍ Package
{⟦
org ↦ ⟦
eolang ↦ ⟦
compares-two-bools ↦ ⟦
φ ↦ Φ̇.true.eq(Φ̇.true)
⟧,
true-as-bool ↦ ⟦
φ ↦ Φ̇.true.as-bool
⟧,
compares-two-different-types ↦ ⟦
φ ↦ Φ̇.true.eq(42).not
⟧,
compares-bool-to-bytes ↦ ⟦
φ ↦ Φ̇.true.eq(Φ̇.bytes(⟦ Δ ⤍ 01- ⟧)).and(
Φ̇.false.eq(Φ̇.bytes(⟦ Δ ⤍ 00- ⟧))
)
⟧,
compares-bool-to-string ↦ ⟦
φ ↦ Φ̇.true.eq("\u0001").and(Φ̇.false.eq("\u0000"))
⟧,
compares-bool-to-bytes-reverse ↦ ⟦
φ ↦ Φ̇.bytes(⟦ Δ ⤍ 01- ⟧).as-bytes.eq(Φ̇.true).and(
Φ̇.bytes(⟦ Δ ⤍ 00- ⟧).as-bytes.eq(Φ̇.false)
)
⟧,
λ ⤍ Package
⟧,
λ ⤍ Package
}
}
no-sugar: |-
{
Expand Down
124 changes: 61 additions & 63 deletions eo-parser/src/test/resources/org/eolang/parser/phi-packs/bytes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,73 +83,71 @@ input: |
# as a new sequence.
[b] > concat /bytes
with-sugar: |-
{
org ↦ ⟦
eolang ↦ ⟦
bytes ↦ ⟦
data ↦ ∅,
eq ↦ ⟦
λ ⤍ Lorg_eolang_bytes_eq,
x ↦ ∅
⟧,
size ↦ ⟦
λ ⤍ Lorg_eolang_bytes_size
⟧,
slice ↦ ⟦
λ ⤍ Lorg_eolang_bytes_slice,
start ↦ ∅,
len ↦ ∅
⟧,
as-string ↦ ⟦
λ ⤍ Lorg_eolang_bytes_as_string
⟧,
as-int ↦ ⟦
λ ⤍ Lorg_eolang_bytes_as_int
⟧,
as-float ↦ ⟦
λ ⤍ Lorg_eolang_bytes_as_float
⟧,
and ↦ ⟦
λ ⤍ Lorg_eolang_bytes_and,
b ↦ ∅
⟧,
or ↦ ⟦
λ ⤍ Lorg_eolang_bytes_or,
b ↦ ∅
⟧,
xor ↦ ⟦
λ ⤍ Lorg_eolang_bytes_xor,
b ↦ ∅
⟧,
not ↦ ⟦
λ ⤍ Lorg_eolang_bytes_not
⟧,
left ↦ ⟦
x ↦ ∅,
φ ↦ ξ.ρ.right(ξ.x.neg)
⟧,
right ↦ ⟦
λ ⤍ Lorg_eolang_bytes_right,
x ↦ ∅
⟧,
as-bool ↦ ⟦
φ ↦ ξ.ρ.eq(Φ̇.bytes(⟦ Δ ⤍ 01- ⟧))
⟧,
as-bytes ↦ ⟦
φ ↦ ξ.ρ
⟧,
concat ↦ ⟦
λ ⤍ Lorg_eolang_bytes_concat,
b ↦ ∅
{⟦
org ↦ ⟦
eolang ↦ ⟦
bytes ↦ ⟦
data ↦ ∅,
eq ↦ ⟦
λ ⤍ Lorg_eolang_bytes_eq,
x ↦ ∅
⟧,
λ ⤍ Package
size ↦ ⟦
λ ⤍ Lorg_eolang_bytes_size
⟧,
slice ↦ ⟦
λ ⤍ Lorg_eolang_bytes_slice,
start ↦ ∅,
len ↦ ∅
⟧,
as-string ↦ ⟦
λ ⤍ Lorg_eolang_bytes_as_string
⟧,
as-int ↦ ⟦
λ ⤍ Lorg_eolang_bytes_as_int
⟧,
as-float ↦ ⟦
λ ⤍ Lorg_eolang_bytes_as_float
⟧,
and ↦ ⟦
λ ⤍ Lorg_eolang_bytes_and,
b ↦ ∅
⟧,
or ↦ ⟦
λ ⤍ Lorg_eolang_bytes_or,
b ↦ ∅
⟧,
xor ↦ ⟦
λ ⤍ Lorg_eolang_bytes_xor,
b ↦ ∅
⟧,
not ↦ ⟦
λ ⤍ Lorg_eolang_bytes_not
⟧,
left ↦ ⟦
x ↦ ∅,
φ ↦ ξ.ρ.right(ξ.x.neg)
⟧,
right ↦ ⟦
λ ⤍ Lorg_eolang_bytes_right,
x ↦ ∅
⟧,
as-bool ↦ ⟦
φ ↦ ξ.ρ.eq(Φ̇.bytes(⟦ Δ ⤍ 01- ⟧))
⟧,
as-bytes ↦ ⟦
φ ↦ ξ.ρ
⟧,
concat ↦ ⟦
λ ⤍ Lorg_eolang_bytes_concat,
b ↦ ∅
⟧,
λ ⤍ Package
⟧,
λ ⤍ Package
}
}
no-sugar: |-
{
Expand Down
Loading

0 comments on commit b17fad5

Please sign in to comment.