alienscript / alienscript.jison

%lex
%%

\s+        /* whitespace */
";"[^\n]+  /* comments */

"!"  { return '!'; }
"["  { return '['; }
"]"  { return ']'; }
"("  { return '('; }
")"  { return ')'; }
"{"  { return 'OPCURLY'; }
"}"  { return 'CLCURLY'; }

\"(\\.|[^"])*\"  yytext = yytext.substr(1,yyleng-2); return 'STRING';

"-"?[0-9]+"."[0-9]+ { return 'FLOAT'; }
"-"?[0-9]+          { return 'INT'; }

nil  { return 'NIL'; }
true  { return 'TRUE'; }
false  { return 'FALSE'; }

[-+/*_<>=a-zA-Z.]+  { return 'SYMBOL'; }

<<EOF>>    { return 'EOF'; }

/lex

%{

function Symbol(name) {
    this.name = name;
}

Symbol.prototype.inspect = function() {
    return "Symbol(\"" + this.name + "\")";
}
Symbol.prototype.__alienscript_tag = "S";


%}

%%

file
  : sexps EOF
    { return $sexps; }
  ;

sexps
  : sexp
    { $$ = [$sexp]; }
  | sexp sexps
    { $$ = [$sexp].concat($sexps); }
  ;

sexp
  : atom
    { $$ = $atom; }
  | list
    { $$ = $list; }
  | rawlist
    { $$ = $rawlist; }
  | hash
    { $$ = $hash; }
  ;

hash
  : 'OPCURLY' 'CLCURLY'
    { $$ = ['hash']; }
  | 'OPCURLY' pairs 'CLCURLY'
    { $$ = ['hash'].concat($pairs); }
  ;

pairs
  : pair
    { $$ = [$pair]; }
  | pair pairs
    { $$ = [$pair].concat($pairs); }
  ;

pair
  : sexp sexp
    { $$ = [$sexp1, $sexp2]; }
  ;

list
  : '(' ')'
    { $$ = []; }
  | '(' items ')'
    { $$ = $items; }
  ;

rawlist
  : '[' ']'
    { $$ = [new Symbol('list')]; }
  | '[' items ']'
    { $$ = [new Symbol('list')].concat($items); }
  ;

items
  : sexp
    { $$ = [$sexp]; }
  | sexp items
    { $$ = [$sexp].concat($items); }
  ;

boolean
  : TRUE
    { $$ = true; }
  | FALSE
    { $$ = false; }
  ;

atom
  : INT
    { $$ = parseInt($INT, 10); }
  | FLOAT
    { $$ = parseFloat($FLOAT); }
  | STRING
    { $$ = $STRING; }
  | boolean
    { $$ = $boolean; }
  | SYMBOL
    { $$ = new Symbol($SYMBOL); }
  | NIL
    { $$ = null; }
  ;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.