Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce SemiScript. #11

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
*.o
.*.sw?
semiscriptc
distbuild
9 changes: 9 additions & 0 deletions Makefile
@@ -0,0 +1,9 @@
semiscriptc: compiler.o
gcc compiler.c -o semiscriptc

distbuild: semiscriptc
mkdir -p distbuild/JS && ./semiscriptc -js semicolon.semi > distbuild/JS/semicolon.js
mkdir -p distbuild/CoffeeScript && ./semiscriptc -cs semicolon.semi > distbuild/CoffeeScript/semicolon.coffee

clean:
rm -rf semiscriptc *.o distbuild
46 changes: 45 additions & 1 deletion README.md
Expand Up @@ -3,6 +3,49 @@
Semicolon.js is a much more secure, stable and reliable alternative to
<a href="http://vaporjs.com/">Vapor.js</a>.


## Build:

After much discussion, it became clear that to support this library far into the
future, we would need to abstract the requirements into its own language, which
can be compiled down to different languages.

Currently the compiler generates valid code for JavaScript and CoffeeScript, but
could easily be extended to support additional languages.

The compiler can be build with:

```
make
```

It produces the `semiscriptc` tool, which can then be used to compile SemiScript
source. These source files typically have the `.semi` extension.

JavaScript:

```
./semiscriptc -js semicolon.semi
;
```

CoffeeScript:

```
./semiscriptc -cs semicolon.semi

```

Beatiful.

Finally, a convenience task is available to produce products for both JavaScript
_and_ CoffeeScript:

```
make distbuild
```


## Usage:
```html
<script src="semicolon.js"></script>
Expand All @@ -20,6 +63,7 @@ Thanks to @alloy for pointing out the inherent code security and
interoperability problems with Vapor.js; and suggesting to
leverage the semicolon solution to address the underlying issues.


### License

(c) Copyright 2012 Thomas Fuchs
Expand All @@ -35,4 +79,4 @@ 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 this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <http://www.gnu.org/licenses/>.
60 changes: 60 additions & 0 deletions compiler.c
@@ -0,0 +1,60 @@
#include <stdio.h>
#include <string.h>

int main (int argc, char *argv[])
{
if (argc != 3) {
printf("Usage: %s [-js|-cs] FILE\n", argv[0]);
return 1;
}

unsigned char javascript = 0;
if (strcmp(argv[1], "-js") == 0) {
javascript = 1;
}

char *source_file = argv[2];

FILE *file = fopen(source_file, "r");
if (file != NULL) {
unsigned char comment = 0;
while (1) {
char c = fgetc(file);
if (c == EOF) {
break;
}
switch (c) {
// This is where the language translation magic happens.
case ';':
if (!comment) {
if (javascript) {
// JavaScript translation.
putc(';', stdout);
} else {
// CoffeeScript translation.
}
}
break;

// Pass-through new-lines, unless in a comment.
case '\n':
if (!comment) {
putc('\n', stdout);
}
comment = 0;
break;

// Comment, ignore the rest of the line.
case '#':
comment = 1;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably not going to work if the sharp character is used in a string (or properly escaped), right? It might be a better idea to tokenize the file contents first. As performance is an issue here I recommend using the Amazon Mechanical Turk.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it's not going to work due to it only considering one character at a time (with too little state info) and therefor not parsing the grammar for comments properly; I'd normally recommend using a more elaborate finite state automaton for the latter, but crowdsourcing is definitely more cloud 3.0. Beware of using jquery files though, the excessive use of dollar signs might influence the tokenizer in thinking you might be part of a billion dollar photo filter company and could drive up pricing per token parsed.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, you make a valid point, @prototype. It would probably be safer to perform a DSE optimization pass (dollar sign elimination) on the js code before submitting it to Amazon. I believe there was a paper recently published in The Journal of Machine Learning Research about this technique.

I would recommend writing the optimization pass using LLVM, since it provides all the necessary foundations.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guys, I suggest you create a fork if you want to add support for strings, or anything else than a semicolon or sharp character. As it is, there is no support for them and as such your code would be at fault.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is how you thank people working on your code? This is open source, we have the right to open meaningful discussions about any project. I can see that you are trying to create a culture of exclusion here. I do hope that you will properly apologize for this atrocious behavior.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do no such thing. Open source means that I get to dictate what you will be using, not some democratic model from your hippy lala-world.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vigorously protest against this dictatorial behavior. You should be open to our concerns day and night. I am going to write a blog post about this story and submit it to hacker news.

This said, you are contradicting yourself. In your previous comment you proudly state that the code only supports semicolon or sharp characters, or you are deliberately checking for \n. I suspect you have bigger plans about the code and that you already started working on our suggestions, with the goal of delivering a proprietary product and selling it to facebook.

break;
}
}
fclose(file);
} else {
printf("Unable to read semiscript source file `%s'.\n", source_file);
return 1;
}

return 0;
}
1 change: 0 additions & 1 deletion semicolon.js

This file was deleted.

2 changes: 2 additions & 0 deletions semicolon.semi
@@ -0,0 +1,2 @@
# This source file is available under the GPL license.
;