You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
283 lines
8.1 KiB
283 lines
8.1 KiB
// Generated by BUCKLESCRIPT VERSION 1.9.3, PLEASE EDIT WITH CARE
|
|
'use strict';
|
|
|
|
var List = require("bs-platform/lib/js/list.js");
|
|
var Block = require("bs-platform/lib/js/block.js");
|
|
var $$String = require("bs-platform/lib/js/string.js");
|
|
var Caml_string = require("bs-platform/lib/js/caml_string.js");
|
|
var Js_primitive = require("bs-platform/lib/js/js_primitive.js");
|
|
|
|
function explode(s) {
|
|
var _i = s.length - 1 | 0;
|
|
var _l = /* [] */0;
|
|
while(true) {
|
|
var l = _l;
|
|
var i = _i;
|
|
if (i < 0) {
|
|
return l;
|
|
} else {
|
|
_l = /* :: */[
|
|
Caml_string.get(s, i),
|
|
l
|
|
];
|
|
_i = i - 1 | 0;
|
|
continue ;
|
|
|
|
}
|
|
};
|
|
}
|
|
|
|
function tokenizer(input) {
|
|
var _input = explode(input);
|
|
var _current = /* None */0;
|
|
var _tokens = /* [] */0;
|
|
while(true) {
|
|
var tokens = _tokens;
|
|
var current = _current;
|
|
var input$1 = _input;
|
|
if (input$1) {
|
|
var head = List.hd(input$1);
|
|
var tail = List.tl(input$1);
|
|
var exit = 0;
|
|
var exit$1 = 0;
|
|
var exit$2 = 0;
|
|
var switcher = head - 32 | 0;
|
|
if (switcher > 9 || switcher < 0) {
|
|
exit$2 = 3;
|
|
} else {
|
|
switch (switcher) {
|
|
case 0 :
|
|
if (current) {
|
|
var match = current[0];
|
|
if (typeof match === "number") {
|
|
exit$1 = 2;
|
|
} else {
|
|
switch (match.tag | 0) {
|
|
case 0 :
|
|
_tokens = /* :: */[
|
|
/* Number */Block.__(0, [match[0]]),
|
|
tokens
|
|
];
|
|
_current = /* None */0;
|
|
_input = tail;
|
|
continue ;
|
|
case 1 :
|
|
exit$2 = 3;
|
|
break;
|
|
case 2 :
|
|
_tokens = /* :: */[
|
|
/* Name */Block.__(2, [match[0]]),
|
|
tokens
|
|
];
|
|
_current = /* None */0;
|
|
_input = tail;
|
|
continue ;
|
|
|
|
}
|
|
}
|
|
} else {
|
|
exit$1 = 2;
|
|
}
|
|
break;
|
|
case 2 :
|
|
if (current) {
|
|
var match$1 = current[0];
|
|
if (typeof match$1 === "number") {
|
|
return List.rev(tokens);
|
|
} else if (match$1.tag === 1) {
|
|
_tokens = /* :: */[
|
|
/* String */Block.__(1, [match$1[0]]),
|
|
tokens
|
|
];
|
|
_current = /* None */0;
|
|
_input = tail;
|
|
continue ;
|
|
|
|
} else {
|
|
return List.rev(tokens);
|
|
}
|
|
} else {
|
|
_current = /* Some */[/* String */Block.__(1, [""])];
|
|
_input = tail;
|
|
continue ;
|
|
|
|
}
|
|
break;
|
|
case 1 :
|
|
case 3 :
|
|
case 4 :
|
|
case 5 :
|
|
case 6 :
|
|
case 7 :
|
|
exit$2 = 3;
|
|
break;
|
|
case 8 :
|
|
if (current) {
|
|
exit$2 = 3;
|
|
} else {
|
|
_tokens = /* :: */[
|
|
/* OpenParen */0,
|
|
tokens
|
|
];
|
|
_current = /* None */0;
|
|
_input = tail;
|
|
continue ;
|
|
|
|
}
|
|
break;
|
|
case 9 :
|
|
if (current) {
|
|
var match$2 = current[0];
|
|
if (typeof match$2 === "number") {
|
|
return List.rev(tokens);
|
|
} else {
|
|
switch (match$2.tag | 0) {
|
|
case 0 :
|
|
_tokens = /* :: */[
|
|
/* CloseParen */1,
|
|
/* :: */[
|
|
/* Number */Block.__(0, [match$2[0]]),
|
|
tokens
|
|
]
|
|
];
|
|
_current = /* None */0;
|
|
_input = tail;
|
|
continue ;
|
|
case 1 :
|
|
exit$2 = 3;
|
|
break;
|
|
case 2 :
|
|
_tokens = /* :: */[
|
|
/* CloseParen */1,
|
|
/* :: */[
|
|
/* Name */Block.__(2, [match$2[0]]),
|
|
tokens
|
|
]
|
|
];
|
|
_current = /* None */0;
|
|
_input = tail;
|
|
continue ;
|
|
|
|
}
|
|
}
|
|
} else {
|
|
_tokens = /* :: */[
|
|
/* CloseParen */1,
|
|
tokens
|
|
];
|
|
_current = /* None */0;
|
|
_input = tail;
|
|
continue ;
|
|
|
|
}
|
|
break;
|
|
|
|
}
|
|
}
|
|
if (exit$2 === 3) {
|
|
if (current) {
|
|
var match$3 = current[0];
|
|
if (typeof match$3 === "number") {
|
|
exit$1 = 2;
|
|
} else if (match$3.tag === 1) {
|
|
_current = /* Some */[/* String */Block.__(1, [match$3[0] + $$String.make(1, head)])];
|
|
_input = tail;
|
|
continue ;
|
|
|
|
} else {
|
|
exit$1 = 2;
|
|
}
|
|
} else {
|
|
exit$1 = 2;
|
|
}
|
|
}
|
|
if (exit$1 === 2) {
|
|
if (head >= 32) {
|
|
if (head < 58) {
|
|
if (head >= 33) {
|
|
if (head >= 48) {
|
|
if (current) {
|
|
var match$4 = current[0];
|
|
if (typeof match$4 === "number") {
|
|
return List.rev(tokens);
|
|
} else if (match$4.tag) {
|
|
return List.rev(tokens);
|
|
} else {
|
|
_current = /* Some */[/* Number */Block.__(0, [match$4[0] + $$String.make(1, head)])];
|
|
_input = tail;
|
|
continue ;
|
|
|
|
}
|
|
} else {
|
|
_current = /* Some */[/* Number */Block.__(0, [$$String.make(1, head)])];
|
|
_input = tail;
|
|
continue ;
|
|
|
|
}
|
|
} else {
|
|
return List.rev(tokens);
|
|
}
|
|
} else {
|
|
exit = 1;
|
|
}
|
|
} else if (head > 122 || head < 97) {
|
|
return List.rev(tokens);
|
|
} else if (current) {
|
|
var match$5 = current[0];
|
|
if (typeof match$5 === "number") {
|
|
return List.rev(tokens);
|
|
} else if (match$5.tag === 2) {
|
|
_current = /* Some */[/* Name */Block.__(2, [match$5[0] + $$String.make(1, head)])];
|
|
_input = tail;
|
|
continue ;
|
|
|
|
} else {
|
|
return List.rev(tokens);
|
|
}
|
|
} else {
|
|
_current = /* Some */[/* Name */Block.__(2, [$$String.make(1, head)])];
|
|
_input = tail;
|
|
continue ;
|
|
|
|
}
|
|
} else if (head >= 11) {
|
|
if (head !== 13) {
|
|
return List.rev(tokens);
|
|
} else {
|
|
exit = 1;
|
|
}
|
|
} else if (head >= 9) {
|
|
exit = 1;
|
|
} else {
|
|
return List.rev(tokens);
|
|
}
|
|
}
|
|
if (exit === 1) {
|
|
if (current) {
|
|
return List.rev(tokens);
|
|
} else {
|
|
_current = /* None */0;
|
|
_input = tail;
|
|
continue ;
|
|
|
|
}
|
|
}
|
|
|
|
} else {
|
|
return List.rev(tokens);
|
|
}
|
|
};
|
|
}
|
|
|
|
console.log(Js_primitive.undefined_to_opt(JSON.stringify(tokenizer("(add 2 (subtract 4 2))"))));
|
|
|
|
var machine = /* record */[
|
|
/* current : None */0,
|
|
/* parsed : [] */0
|
|
];
|
|
|
|
exports.machine = machine;
|
|
exports.explode = explode;
|
|
exports.tokenizer = tokenizer;
|
|
/* Not a pure module */
|