<jscode> - should it be free or sanitized?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

<jscode> - should it be free or sanitized?

Herby Vojčík
Hello,

I'd like to ask for the policy on use of <inlineJs()> - for now, it is
included as-is. My question is - should this be left as-is, by which
people can create templates of sort (dislike this, too much cons, pros
are questionable):

<for (var i=1; i<100; ++i) {>
"smalltalk code"
<}>

or it should be flyweightly sanitized by putting semicolon(s) in front
and in back of them (I like this alternative; I do it in ImpCompiler)?

Herby
Reply | Threaded
Open this post in threaded view
|

Re: <jscode> - should it be free or sanitized?

Hannes Hirzel
Hello Herby

Great to see you working on a compiler alternative!

On 5/2/12, Herby Vojčík <[hidden email]> wrote:
> Hello,
>
> I'd like to ask for the policy on use of <inlineJs()> - for now, it is
> included as-is. My question is - should this be left as-is, by which
> people can create templates of sort (dislike this, too much cons, pros
> are questionable):

Could you please elaborate a bit on this? what are the cons?

> <for (var i=1; i<100; ++i) {>
> "smalltalk code"
> <}>

Looks a bit weird at the start but would be a good bridge for
JavaScript programmers to move to Smalltalk. Or to put Smalltalk into
an existing JavaScript project. However as you write this might be
questionable in terms of maintainability.

> or it should be flyweightly sanitized by putting semicolon(s) in front
> and in back of them (I like this alternative; I do it in ImpCompiler)?

Sounds good, could you give an example?


> Herby
>

--Hannes
Reply | Threaded
Open this post in threaded view
|

Re: <jscode> - should it be free or sanitized?

Herby Vojčík


H. Hirzel wrote:

> Hello Herby
>
> Great to see you working on a compiler alternative!
>
> On 5/2/12, Herby Vojčík<[hidden email]>  wrote:
>> Hello,
>>
>> I'd like to ask for the policy on use of<inlineJs()>  - for now, it is
>> included as-is. My question is - should this be left as-is, by which
>> people can create templates of sort (dislike this, too much cons, pros
>> are questionable):
>
> Could you please elaborate a bit on this? what are the cons?

As you mentioned, maintainability. Also see last issue (189) in github -
people will try to push it to the limits which may create very unhappy
situations to solve. Compiler architecture may be constrained by this.
I would like to allow inline JS only as a standalone statement at JS
level, and properly isolate it.
At the present, every other node in classical compiler is production of
value, except inline-js; and evey node in ImpCompiler is assignment of
value, except inline js. It is not precisely defined in what contexts in
can appear, and I think it should be defined.
The main goal of including inline JS was to use it as <primitive: 1> is
used in classical Smalltalk, wasn't it? So it looks like it should be
the standalone statement, anyway (either returning the right value
directly, or letting the smalltalk code take on; of course it could
appear anywhere, so it's more free than that)

>> <for (var i=1; i<100; ++i) {>
>> "smalltalk code"
>> <}>
>
> Looks a bit weird at the start but would be a good bridge for
> JavaScript programmers to move to Smalltalk. Or to put Smalltalk into
> an existing JavaScript project. However as you write this might be
> questionable in terms of maintainability.
>
>> or it should be flyweightly sanitized by putting semicolon(s) in front
>> and in back of them (I like this alternative; I do it in ImpCompiler)?
>
> Sounds good, could you give an example?

Well, in fact, to be really foolproof, it should be three semicolons at
the end.
So, if one writes

foo
|x|
x:=3.
<x+=1>
^x

its fine, since it produces
var x=nil;
x=3;
;x+=1;;;
return x;

but it fails when

bar
|x|
<for(>
x:=1.
x<10.
<x++){console.log(x);}>

since it isolates the pieces and produces

var x=nil;
;for(;;;
x=1;
(/*class check*/?x<10:send(x,'__lt',10));
;x++){console.log(x):};;;

which is clearly syntax error.

Herby
Reply | Threaded
Open this post in threaded view
|

Re: <jscode> - should it be free or sanitized?

Nicolas Petton
Hi!

I don't really care :) 

The reason is simply that Amber should be able to play well with the JavaScript ecosystem, and that means being able to embed JS code. That's what Amber already do. 

Now using it as some kind of template is of course a bad idea, but it's not how it's indented to be used.
What I like with your proposal is that it would allow pragmas in Amber. But I hate the triple ;;; syntax.

Cheers,
Nico

On May 3, 2012, at 3:43 PM, Herby Vojčík wrote:



H. Hirzel wrote:
Hello Herby

Great to see you working on a compiler alternative!

On 5/2/12, Herby Vojčík<[hidden email]>  wrote:
Hello,

I'd like to ask for the policy on use of<inlineJs()>  - for now, it is
included as-is. My question is - should this be left as-is, by which
people can create templates of sort (dislike this, too much cons, pros
are questionable):

Could you please elaborate a bit on this? what are the cons?

As you mentioned, maintainability. Also see last issue (189) in github - people will try to push it to the limits which may create very unhappy situations to solve. Compiler architecture may be constrained by this.
I would like to allow inline JS only as a standalone statement at JS level, and properly isolate it.
At the present, every other node in classical compiler is production of value, except inline-js; and evey node in ImpCompiler is assignment of value, except inline js. It is not precisely defined in what contexts in can appear, and I think it should be defined.
The main goal of including inline JS was to use it as <primitive: 1> is used in classical Smalltalk, wasn't it? So it looks like it should be the standalone statement, anyway (either returning the right value directly, or letting the smalltalk code take on; of course it could appear anywhere, so it's more free than that)

<for (var i=1; i<100; ++i) {>
"smalltalk code"
<}>

Looks a bit weird at the start but would be a good bridge for
JavaScript programmers to move to Smalltalk. Or to put Smalltalk into
an existing JavaScript project. However as you write this might be
questionable in terms of maintainability.

or it should be flyweightly sanitized by putting semicolon(s) in front
and in back of them (I like this alternative; I do it in ImpCompiler)?

Sounds good, could you give an example?

Well, in fact, to be really foolproof, it should be three semicolons at the end.
So, if one writes

foo
|x|
x:=3.
<x+=1>
^x

its fine, since it produces
var x=nil;
x=3;
;x+=1;;;
return x;

but it fails when

bar
|x|
<for(>
x:=1.
x<10.
<x++){console.log(x);}>

since it isolates the pieces and produces

var x=nil;
;for(;;;
x=1;
(/*class check*/?x<10:send(x,'__lt',10));
;x++){console.log(x):};;;

which is clearly syntax error.

Herby


Reply | Threaded
Open this post in threaded view
|

Re: <jscode> - should it be free or sanitized?

Amber Milan Eskridge
Oh noes, pragmas. I dislike them.

On Thu, May 3, 2012 at 4:01 PM, Nicolas Petton <[hidden email]> wrote:
Hi!

I don't really care :) 

The reason is simply that Amber should be able to play well with the JavaScript ecosystem, and that means being able to embed JS code. That's what Amber already do. 

Now using it as some kind of template is of course a bad idea, but it's not how it's indented to be used.
What I like with your proposal is that it would allow pragmas in Amber. But I hate the triple ;;; syntax.

Cheers,
Nico

On May 3, 2012, at 3:43 PM, Herby Vojčík wrote:



H. Hirzel wrote:
Hello Herby

Great to see you working on a compiler alternative!

On 5/2/12, Herby Vojčík<[hidden email]>  wrote:
Hello,

I'd like to ask for the policy on use of<inlineJs()>  - for now, it is
included as-is. My question is - should this be left as-is, by which
people can create templates of sort (dislike this, too much cons, pros
are questionable):

Could you please elaborate a bit on this? what are the cons?

As you mentioned, maintainability. Also see last issue (189) in github - people will try to push it to the limits which may create very unhappy situations to solve. Compiler architecture may be constrained by this.
I would like to allow inline JS only as a standalone statement at JS level, and properly isolate it.
At the present, every other node in classical compiler is production of value, except inline-js; and evey node in ImpCompiler is assignment of value, except inline js. It is not precisely defined in what contexts in can appear, and I think it should be defined.
The main goal of including inline JS was to use it as <primitive: 1> is used in classical Smalltalk, wasn't it? So it looks like it should be the standalone statement, anyway (either returning the right value directly, or letting the smalltalk code take on; of course it could appear anywhere, so it's more free than that)

<for (var i=1; i<100; ++i) {>
"smalltalk code"
<}>

Looks a bit weird at the start but would be a good bridge for
JavaScript programmers to move to Smalltalk. Or to put Smalltalk into
an existing JavaScript project. However as you write this might be
questionable in terms of maintainability.

or it should be flyweightly sanitized by putting semicolon(s) in front
and in back of them (I like this alternative; I do it in ImpCompiler)?

Sounds good, could you give an example?

Well, in fact, to be really foolproof, it should be three semicolons at the end.
So, if one writes

foo
|x|
x:=3.
<x+=1>
^x

its fine, since it produces
var x=nil;
x=3;
;x+=1;;;
return x;

but it fails when

bar
|x|
<for(>
x:=1.
x<10.
<x++){console.log(x);}>

since it isolates the pieces and produces

var x=nil;
;for(;;;
x=1;
(/*class check*/?x<10:send(x,'__lt',10));
;x++){console.log(x):};;;

which is clearly syntax error.

Herby



Reply | Threaded
Open this post in threaded view
|

Re: <jscode> - should it be free or sanitized?

Herby Vojčík
In reply to this post by Nicolas Petton


Nicolas Petton wrote:

> Hi!
>
> I don't really care :)
>
> The reason is simply that Amber should be able to play well with the
> JavaScript ecosystem, and that means being able to embed JS code. That's
> what Amber already do.
>
> Now using it as some kind of template is of course a bad idea, but it's
> not how it's indented to be used.

That's what I wanted to hear! ;-)

> What I like with your proposal is that it would allow pragmas in Amber.
> But I hate the triple ;;; syntax.

;{ ...code... }

is better (you may not like the leading ;, but it is used to sanitize
external JS regularly; builders that concatenate JS scripts very often
put it at the beginning of every element to fail early and not to allow
some kind of breach)?

>
> Cheers,
> Nico

Herby
Reply | Threaded
Open this post in threaded view
|

Re: <jscode> - should it be free or sanitized?

Herby Vojčík
In reply to this post by Nicolas Petton
Nicolas Petton wrote:

> Hi!
>
> I don't really care :)
>
> The reason is simply that Amber should be able to play well with the
> JavaScript ecosystem, and that means being able to embed JS code. That's
> what Amber already do.
>
> Now using it as some kind of template is of course a bad idea, but it's
> not how it's indented to be used.
> What I like with your proposal is that it would allow pragmas in Amber.
> But I hate the triple ;;; syntax.

Well, I just realized I should sanitized dangling ". ', / and also many
subblocks could be open with {... this is not the way to go.

Then I came up with totally different and bulletproof (and needing no
mengling in code): add this method to String:

isProperJS
        <try{new Function(self); return true;} catch(e) {if (e instanceof
SyntaxError) return false; throw e}>

and use it to check.

> Cheers,
> Nico

Herby