factor/extra/peg/javascript/parser/parser-tests.factor

53 lines
1.1 KiB
Factor
Raw Normal View History

2008-06-18 08:42:11 -04:00
! Copyright (C) 2008 Chris Double.
! See http://factorcode.org/license.txt for BSD license.
2018-02-15 11:45:08 -05:00
USING: kernel tools.test peg peg.javascript.ast
peg.javascript.parser accessors sequences math peg.ebnf
peg.ebnf.private ;
2008-06-18 08:42:11 -04:00
{
T{
ast-begin
f
V{
T{ ast-number f 123 }
T{ ast-string f "hello" }
T{
ast-call
f
T{ ast-get f "foo" }
V{ T{ ast-get f "x" } }
}
}
}
} [
2008-07-03 23:48:52 -04:00
"123; 'hello'; foo(x);" javascript
2008-06-18 09:24:17 -04:00
] unit-test
{ t } [
"
2008-06-18 09:45:09 -04:00
var x=5
var y=10
" main \ javascript rule (parse) remaining>> length zero?
2008-06-18 09:45:09 -04:00
] unit-test
{ t } [
"
2008-06-18 09:24:17 -04:00
function foldl(f, initial, seq) {
for(var i=0; i< seq.length; ++i)
initial = f(initial, seq[i]);
return initial;
}" main \ javascript rule (parse) remaining>> length zero?
2008-06-18 09:24:17 -04:00
] unit-test
{ t } [
"
ParseState.prototype.from = function(index) {
var r = new ParseState(this.input, this.index + index);
r.cache = this.cache;
r.length = this.length - index;
return r;
}" main \ javascript rule (parse) remaining>> length zero?
] unit-test