Пример #1
0
 function testKeyword()
 {
     $keyword = edn\keyword('foo');
     $this->assertSame(Keyword::get('foo'), $keyword);
 }
Пример #2
0
function parse_token(array $token)
{
    list($type, $_, $edn) = $token;
    switch ($type) {
        case 'literal':
            return resolve_literal($edn);
        case 'string':
            return resolve_string(substr($edn, 1, -1));
        case 'character':
            return resolve_character(substr($edn, 1));
        case 'symbol':
            return Symbol::get($edn);
        case 'keyword':
            return Keyword::get(substr($edn, 1));
        case 'tag':
            return new Tag(substr($edn, 1));
        case 'int':
            return resolve_int($edn);
        case 'float':
            return resolve_float($edn);
        case 'discard':
            return new Discard();
    }
    throw new ParserException(sprintf('Could not parse input %s.', $edn));
}
Пример #3
0
 function provideNestedTagEdn()
 {
     return [[[new LinkedList([new Foo('bar')])], '(#myapp/Foo "bar")'], [[new Vector([new Foo('bar')])], '[#myapp/Foo "bar"]'], [[new Map([Keyword::get('foo'), new Foo('bar')])], '{:foo #myapp/Foo "bar"}'], [[new Map([new Foo(Keyword::get('foo')), 'bar'])], '{#myapp/Foo :foo "bar"}'], [[new Set([new Foo('bar')])], '#{#myapp/Foo "bar"}'], [[new Set([new Vector([new LinkedList([new Foo('bar')])])])], '#{[(#myapp/Foo "bar")]}']];
 }
Пример #4
0
 function provideAst()
 {
     return [['', []], ['nil', [null]], ['true', [true]], ['false', [false]], ['true false', [true, false]], ['"foobar"', ['foobar']], ['"foo" "bar"', ['foo', 'bar']], ['"foo\\nbar"', ["foo\nbar"]], ['"foo\\tbar"', ["foo\tbar"]], ['"GET /foo HTTP/1.1\\r\\n"', ["GET /foo HTTP/1.1\r\n"]], ['"foo\\""', ['foo"']], ['\\c', ['c']], ['\\newline \\tab \\space', ["\n", "\t", ' ']], ['foo', [Symbol::get('foo')]], ['foo bar', [Symbol::get('foo'), Symbol::get('bar')]], ['foo/bar', [Symbol::get('foo/bar')]], ['foo-bar', [Symbol::get('foo-bar')]], ['/', [Symbol::get('/')]], [':foo', [Keyword::get('foo')]], [':foo :bar', [Keyword::get('foo'), Keyword::get('bar')]], [':foo/bar', [Keyword::get('foo/bar')]], [':foo-bar', [Keyword::get('foo-bar')]], [':/', [Keyword::get('/')]], ['(defproject com.thortech/data.edn "0.1.0-SNAPSHOT")', [new LinkedList([Symbol::get('defproject'), Symbol::get('com.thortech/data.edn'), "0.1.0-SNAPSHOT"])]], ['1', [1]], ['-1', [-1]], ['+1', [1]], ['0', [0]], ['-0', [0]], ['+0', [0]], ['10', [10]], ['20', [20]], ['200', [200]], ['-200', [-200]], ['42', [42]], ['1.0', [1.0]], ['1.2', [1.2]], ['-1.2', [-1.2]], ['-0.0', [-0.0]], ['-0.25', [-0.25]], ['()', [new LinkedList([])]], ['(foo)', [new LinkedList([Symbol::get('foo')])]], ['(foo bar)', [new LinkedList([Symbol::get('foo'), Symbol::get('bar')])]], ['(foo bar (baz))', [new LinkedList([Symbol::get('foo'), Symbol::get('bar'), new LinkedList([Symbol::get('baz')])])]], ['(foo bar (baz) qux ((quux)))', [new LinkedList([Symbol::get('foo'), Symbol::get('bar'), new LinkedList([Symbol::get('baz')]), Symbol::get('qux'), new LinkedList([new LinkedList([Symbol::get('quux')])])])]], ['[]', [new Vector([])]], ['[foo]', [new Vector([Symbol::get('foo')])]], ['[foo bar]', [new Vector([Symbol::get('foo'), Symbol::get('bar')])]], ['[foo bar [baz]]', [new Vector([Symbol::get('foo'), Symbol::get('bar'), new Vector([Symbol::get('baz')])])]], ['{}', [new Map([])]], ['{:foo bar}', [new Map([Keyword::get('foo'), Symbol::get('bar')])]], ['{:foo (bar)}', [new Map([Keyword::get('foo'), new LinkedList([Symbol::get('bar')])])]], ['#{}', [new Set([])]], ['#{foo}', [new Set([Symbol::get('foo')])]], ['#{foo bar}', [new Set([Symbol::get('foo'), Symbol::get('bar')])]], ['#{(foo bar)}', [new Set([new LinkedList([Symbol::get('foo'), Symbol::get('bar')])])]], ['#{{:foo bar}}', [new Set([new Map([Keyword::get('foo'), Symbol::get('bar')])])]], ['#myapp/Person "foo"', [new Tagged(new Tag('myapp/Person'), 'foo')]], ['{:first "Fred" :last "Mertz"}', [new Map([Keyword::get('first'), 'Fred', Keyword::get('last'), 'Mertz'])]], ['#myapp/Person (:foo :bar)', [new Tagged(new Tag('myapp/Person'), new LinkedList([Keyword::get('foo'), Keyword::get('bar')]))]], ['#myapp/Person {:first "Fred" :last "Mertz"}', [new Tagged(new Tag('myapp/Person'), new Map([Keyword::get('first'), 'Fred', Keyword::get('last'), 'Mertz']))]]];
 }