Skip to content

Commit

Permalink
Merge pull request #3746 from michaellilltokiwa/issue/3678
Browse files Browse the repository at this point in the history
parser: do not parse single dot as operator
  • Loading branch information
michaellilltokiwa authored Sep 12, 2024
2 parents ab85494 + 25b3d2b commit 3893f43
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 22 deletions.
16 changes: 4 additions & 12 deletions src/dev/flang/parser/OpExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,12 @@ public class OpExpr extends ANY
*
* @param o
*/
void add(Operator o)
void add(Object o)
{
_els.add(o);
}

if (PRECONDITIONS) require
(o instanceof Expr || o instanceof Operator);

/**
* add
*
* @param e
*/
void add(Expr e)
{
_els.add(e);
_els.add(o);
}


Expand Down
29 changes: 19 additions & 10 deletions src/dev/flang/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1902,20 +1902,20 @@ Expr opExpr()
/**
* Parse ops
*
* @param oe OpExpr instance the op()s should be added to
* @param oe OpExpr instance the dotCallOrOp()s should be added to
*
* @return true iff ops was parsed and op()s were added to oe
* @return true iff ops was parsed and dotCallOrOp()s were added to oe
*
ops : op ops
| op
ops : dotCallOrOp ops
| dotCallOrOp
;
*/
boolean skipOps(OpExpr oe)
{
var oldcount = oe.size();
while (current() == Token.t_op)
{
oe.add(op());
oe.add(dotCallOrOp());
}
return oldcount < oe.size();
}
Expand Down Expand Up @@ -2242,18 +2242,27 @@ boolean isTermPrefix()


/**
* Parse op
* Parse dotCallOrOp
*
op : OPERATOR
dotCallOrOp : dot call
| OPERATOR
;
*/
Operator op()
Object dotCallOrOp()
{
if (PRECONDITIONS) require
(current() == Token.t_op);

Operator result = new Operator(tokenSourceRange(), operator(), ignoredTokenBefore(), ignoredTokenAfter());
match(Token.t_op, "op");
Object result; // Function or Operator
if (skipDot())
{
result = Partial.dotCall(tokenSourcePos(), a->pureCall(a));
}
else
{
result = new Operator(tokenSourceRange(), operator(), ignoredTokenBefore(), ignoredTokenAfter());
match(Token.t_op, "op");
}
return result;
}

Expand Down
25 changes: 25 additions & 0 deletions tests/reg_issue2515/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation. If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion test Makefile
#
# -----------------------------------------------------------------------

override NAME = reg_issue2515
include ../simple.mk
28 changes: 28 additions & 0 deletions tests/reg_issue2515/reg_issue2515.fz
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation. If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion test reg_issue2515
#
# -----------------------------------------------------------------------


# infix |-> as alternative to Sequence.map
Sequence.infix |-> (f T->B) => map f

say (0..10 |-> .as_f64)
Empty file.
1 change: 1 addition & 0 deletions tests/reg_issue2515/reg_issue2515.fz.expected_out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, …]
25 changes: 25 additions & 0 deletions tests/reg_issue3678/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation. If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion test Makefile
#
# -----------------------------------------------------------------------

override NAME = reg_issue3678
include ../simple.mk
30 changes: 30 additions & 0 deletions tests/reg_issue3678/reg_issue3678.fz
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation. If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion test reg_issue3678
#
# -----------------------------------------------------------------------


x => 42 |> .as_string |> say
x2 => 42 |> (.as_string) |> say
x3 => 42 |> .as_string|> say
x4 => 42 |>(.as_string)|> say

x; x2; x3; x4
Empty file.
4 changes: 4 additions & 0 deletions tests/reg_issue3678/reg_issue3678.fz.expected_out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
42
42
42
42

0 comments on commit 3893f43

Please sign in to comment.