Can we have this Syntactic sugar.

Long Chang changedalone at gmail.com
Tue Nov 24 15:07:45 PST 2009


2009/11/24 Long Chang <changedalone at gmail.com>:
>
>
> enum CompileTimeOption{
>
>     ANCHORED ,
>     AUTO_CALLOUT ,
>     CASELESS ,
>     ENDONLY  ,
>     DOTALL  ,
>     EXTENDED ,
>     EXTRA   ,
>     FIRSTLINE ,
>     MULTILINE  ,
>     NO_AUTO_CAPTURE  ,
>     UNGREEDY ,
>     UTF8 ,
>     NO_UTF8_CHECK  ,
>     DUPNAMES  ,
>     NEWLINE_CR   ,
>     NEWLINE_LF   ,
>     NEWLINE_CRLF   ,
>     NEWLINE_ANY   ,
> }
>
> public class RegExp
> {
>     enum {
>         X, Y, Z
>     }
>     this(char[] pattern, int options = 0){}
>     static RegExp opCall(char[] pattern, int option2){}
> }
>
> void main(){
>     RegExp reg1    = new RegExp("^A.+", CompileTimeOption.UTF8 |
> CompileTimeOption.MULTILINE | CompileTimeOption.DOTALL );
>     // Syntactic sugar.
>     RegExp reg2    = new RegExp("^A.+",
>             CompileTimeOption.( UTF8 | MULTILINE | DOTALL )
>         );
>     const MyRegExpOption    = CompileTimeOption.( UTF8 | MULTILINE | DOTALL
> );
>     RegExp reg3    = RegExp( "^A.+",  .(X+Y*Z) );
>
>     int X    = 33;
>
>     RegExp reg4    = RegExp( "^A.+",  .( X+ .X /* the outer X */  ) );
>
> }
>

Int Y = 3;
    const MyRegExpOption    = CompileTimeOption.( UTF8 | MULTILINE |
DOTALL  +  RegExp.(X +Y + CompileTimeOption.DOTALL   +  outer.Y  )
);

I think there should not be any ambiguity, and it should work in ctfe .

It is not With(Object){}, It 's a part of a Expressions,can be Nested。


More information about the Digitalmars-d mailing list