Goose  Diff

Differences From Artifact [f7de8a1f2a]:

  • File bs/builtins/operators/comma.cpp — part of check-in [39f2220e39] at 2019-07-31 22:40:59 on branch trunk — builtins: implemented some helpers to easily create builtin operators with overloadable extension points. (user: achavasse size: 590)

To Artifact [b955cb2641]:

  • File bs/builtins/operators/comma.cpp — part of check-in [035cf4826c] at 2019-08-06 00:33:17 on branch trunk —
    • Improved the operator parsing rules construction helpers to support both an unary and an infix operators sharing the same identifier.
    • Updated the comma operator implementation to use the same helpers as other operators, which makes it possible to overload it.
    (user: achavasse size: 1060)

1
2
3
4
5
6
7
8
9
10
11
12

13


14
15
16
17
18
19






20


21
22
#include "builtins/builtins.h"
#include "precedence.h"
#include "helpers.h"

using namespace empathy;
using namespace empathy::ir;
using namespace empathy::parse;

namespace empathy::builtins
{
    void SetupCommaOp( Env& e )
    {

        RegisterLeftAssInfixOp( e, ","_sid, precedence::CommaOp,


            []( auto&& parser, auto&& lhs, auto&& rhs ) -> optional< Value >
            {
                if( IsOpenTuple( lhs ) )
                    return AppendToTuple( lhs, rhs );

                return AppendToTuple( AppendToTuple( EmptyTuple(), lhs ), rhs );






            } );


    }
}












>
|
>
>
|
|
|
|

|
>
>
>
>
>
>
|
>
>


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "builtins/builtins.h"
#include "precedence.h"
#include "helpers.h"

using namespace empathy;
using namespace empathy::ir;
using namespace empathy::parse;

namespace empathy::builtins
{
    void SetupCommaOp( Env& e )
    {
        BuildParseRule( e, ","_sid,
            LeftAssInfixOp( "operator_comma"_sid, precedence::CommaOp,
                // Overload: any tuple, anything
                ForTypes< CustomPattern< Value, TuplePattern >, Value >(
                []( auto&& lhs, auto&& rhs ) -> optional< Value >
                {
                    if( IsOpenTuple( lhs ) )
                        return AppendToTuple( lhs, rhs );

                    return AppendToTuple( AppendToTuple( EmptyTuple(), lhs ), rhs );
                } ),
                // Overload: anything, anything
                ForType< Value >(
                []( auto&& lhs, auto&& rhs ) -> optional< Value >
                {
                    return AppendToTuple( AppendToTuple( EmptyTuple(), lhs ), rhs );
                } )
            )
         );
    }
}