forked from madrobby/semicolon.js
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allows us to support popular languages, now, and far into the future. * Translates to JavaScript and CoffeeScript, but is modular enough to easily be extended to support other languages.
- Loading branch information
Showing
6 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.o | ||
.*.sw? | ||
semiscriptc | ||
distbuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
break; | ||
} | ||
} | ||
fclose(file); | ||
} else { | ||
printf("Unable to read semiscript source file `%s'.\n", source_file); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# This source file is available under the GPL license. | ||
; |