Browse Source

fix bug where defops were not being included by the tokenizer properly, fixed precedence order mixup in prelude.jl

pull/22/head
nisstyre56 11 years ago
parent
commit
c34fd71244
  1. 3
      free_vars.js
  2. 2
      parse.js
  3. 34
      prelude.jl
  4. 7
      tokenize.js

3
free_vars.js

@ -150,10 +150,9 @@ function annotate_fvs_all(stx) {
function test(src) { function test(src) {
var ast = parser.parse(src); var ast = parser.parse(src);
console.log(JSON.stringify(ast.map(annotate_fvs_all), null, 4));
} }
console.log(test("if something then if a then if b then c else d else rtrrt else some_other_thing")); //console.log(test("if something then if a then if b then c else d else rtrrt else some_other_thing"));
module.export = { module.export = {
test : test, test : test,
annotate_fvs: annotate_fvs_all annotate_fvs: annotate_fvs_all

2
parse.js

@ -811,9 +811,7 @@ function parseFull(tokenized) {
try { try {
while (tokenized.length > 0) { while (tokenized.length > 0) {
ast.push(desugarer.desugar(parse(tokenized), typeBindings)); ast.push(desugarer.desugar(parse(tokenized), typeBindings));
console.log(ast);
} }
console.log(ast);
return [ast, typeBindings]; return [ast, typeBindings];
} catch (e) { } catch (e) {
if (e.stxerror !== undefined) { if (e.stxerror !== undefined) {

34
prelude.jl

@ -63,56 +63,56 @@ deftype (Either a b)
;; Operator definitions ;; Operator definitions
defop 3 Left (a + b) defop 1 Left (a + b)
(add a b) (add a b)
defop 3 Left (a - b) defop 1 Left (a - b)
(minus a b) (minus a b)
defop 4 Left (a * b) defop 2 Left (a * b)
(mul a b) (mul a b)
defop 4 Left (a / b) defop 2 Left (a / b)
(div a b) (div a b)
defop 5 Right (a ^ b) defop 2 Right (a ^ b)
(pow a b) (pow a b)
defop 3 Left (a ++ b) defop 3 Left (a ++ b)
(listConcat a b) (listConcat a b)
defop 2 Left (a == b) defop 3 Left (a == b)
(eq a b) (eq a b)
defop 2 Left (a > b) defop 3 Left (a > b)
(gt a b) (gt a b)
defop 2 Left (a >= b) defop 3 Left (a >= b)
(gte a b) (gte a b)
defop 2 Left (a < b) defop 3 Left (a < b)
(lt a b) (lt a b)
defop 2 Left (a <= b) defop 3 Left (a <= b)
(lte a b) (lte a b)
defop 2 Left (a && b) defop 3 Left (a && b)
(and a b) (and a b)
defop 2 Left (a || b) defop 3 Left (a || b)
(or a b) (or a b)
defop 1 Left (x : xs) defop 4 Left (x : xs)
(cons x xs) (cons x xs)
defop 1 Left (f $ x) defop 5 Left (f $ x)
(fapply f x) (fapply f x)
defop 1 Left (f . g) defop 5 Left (f . g)
(compose f g) (compose f g)
defop 1 Left (a | b) defop 3 Left (a | b)
(bitwiseOr a b) (bitwiseOr a b)
defop 1 Left (a & b) defop 3 Left (a & b)
(bitwiseAnd a b) (bitwiseAnd a b)

7
tokenize.js

@ -14,7 +14,10 @@ function isDigit(c) {
if (isNaN(code)) { if (isNaN(code)) {
return false; return false;
} }
return (47 < code && code < 58); if ((47 < code) && (code < 58)) {
return true;
}
return false;
} }
function isWhitespace(c) { function isWhitespace(c) {
@ -411,9 +414,9 @@ function checkPattern(x, i) {
function tokenizeFull(input) { function tokenizeFull(input) {
var preludeSrc = fs.readFileSync("./prelude.jl"); var preludeSrc = fs.readFileSync("./prelude.jl");
var matchop; var matchop;
input = [preludeSrc, input].join("");
var initialPass = tokenizeHelp(input, _.constant(false), true).reverse(); var initialPass = tokenizeHelp(input, _.constant(false), true).reverse();
input = [preludeSrc, input].join("");
for (var i = 0; i < initialPass.length; i++) { for (var i = 0; i < initialPass.length; i++) {
if (initialPass.slice(i, i+8). if (initialPass.slice(i, i+8).
map(_.first). map(_.first).

Loading…
Cancel
Save