Ejemplo n.º 1
0
 function testSymbol()
 {
     $symbol = edn\symbol('foo');
     $this->assertSame(Symbol::get('foo'), $symbol);
 }
Ejemplo n.º 2
0
Archivo: parser.php Proyecto: igorw/edn
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));
}
Ejemplo n.º 3
0
 function provideEdn()
 {
     return [[[], ''], [[], ' '], [[], '   '], [[], ','], [[], ',,,'], [[], ',,, '], [[], ', ,,'], [[], ' , '], [[null], 'nil'], [[true], 'true'], [[false], 'false'], [[true, false], 'true 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\\""'], [['foo\\'], '"foo\\\\"'], [['c'], '\\c'], [["\n", "\t", ' '], '\\newline \\tab \\space'], [[Symbol::get('foo')], 'foo'], [[Symbol::get('foo'), Symbol::get('bar')], 'foo bar'], [[Symbol::get('foo/bar')], 'foo/bar'], [[Symbol::get('foo-bar')], 'foo-bar'], [[Symbol::get('/')], '/'], [[Symbol::get('ab#:cde')], 'ab#:cde'], [[Symbol::get('+')], '+'], [[Symbol::get('truefalse')], 'truefalse'], [[Symbol::get('true.')], 'true.'], [[Symbol::get('.true')], '.true'], [[Keyword::get('foo')], ':foo'], [[Keyword::get('foo'), Keyword::get('bar')], ':foo :bar'], [[Keyword::get('foo/bar')], ':foo/bar'], [[Keyword::get('foo-bar')], ':foo-bar'], [[Keyword::get('/')], ':/'], [[Keyword::get('ab#:cde')], ':ab#:cde'], [[Keyword::get('+')], ':+'], [[Keyword::get('truefalse')], ':truefalse'], [[Keyword::get('true.')], ':true.'], [[Keyword::get('.true')], ':.true'], [[new LinkedList([Symbol::get('defproject'), Symbol::get('com.thortech/data.edn'), "0.1.0-SNAPSHOT"])], '(defproject 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([])], '()'], [[new LinkedList([Symbol::get('foo')])], '(foo)'], [[new LinkedList([Symbol::get('foo'), Symbol::get('bar')])], '(foo bar)'], [[new LinkedList([Symbol::get('foo'), Symbol::get('bar'), new LinkedList([Symbol::get('baz')])])], '(foo bar (baz))'], [[new LinkedList([Symbol::get('foo'), Symbol::get('bar'), new LinkedList([Symbol::get('baz')]), Symbol::get('qux'), new LinkedList([new LinkedList([Symbol::get('quux')])])])], '(foo bar (baz) qux ((quux)))'], [[new Vector([])], '[]'], [[new Vector([Symbol::get('foo')])], '[foo]'], [[new Vector([Symbol::get('foo'), Symbol::get('bar')])], '[foo bar]'], [[new Vector([Symbol::get('foo'), Symbol::get('bar'), new Vector([Symbol::get('baz')])])], '[foo bar [baz]]'], [[new Map([])], '{}'], [[new Map([Keyword::get('foo'), Symbol::get('bar')])], '{:foo bar}'], [[new Map([Keyword::get('foo'), new LinkedList([Symbol::get('bar')])])], '{:foo (bar)}'], [[new Set([])], '#{}'], [[new Set([Symbol::get('foo')])], '#{foo}'], [[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')])])], '#{{:foo bar}}'], [[new Tagged(new Tag('myapp/Person'), 'foo')], '#myapp/Person "foo"'], [[new Map([Keyword::get('first'), 'Fred', Keyword::get('last'), 'Mertz'])], '{:first "Fred" :last "Mertz"}'], [[new Tagged(new Tag('myapp/Person'), new LinkedList([Keyword::get('foo'), Keyword::get('bar')]))], '#myapp/Person (:foo :bar)'], [[new Tagged(new Tag('myapp/Person'), new Map([Keyword::get('first'), 'Fred', Keyword::get('last'), 'Mertz']))], '#myapp/Person {:first "Fred" :last "Mertz"}'], [[new Tagged(new Tag('ab#:cde'), 'foo')], '#ab#:cde "foo"'], [[], ';'], [[], '; foo'], [[Symbol::get('foo')], "; foo\nfoo"], [[Symbol::get('foo'), Symbol::get('bar')], "; foo\nfoo; bar\nbar"], [[], "; foo bar baz qux"], [[], "; foo bar baz qux\n"], [[], "; foo bar baz qux\n\n"], [[Symbol::get('quux')], "; foo bar baz qux\n\nquux\n\n"], [[], '#_foo'], [[new Vector([Symbol::get('a'), Symbol::get('b'), 42])], '[a b #_foo 42]'], [[], '#_ foo'], [[new Vector([Symbol::get('a'), Symbol::get('b'), 42])], '[a b #_ foo 42]'], [['#_ foo'], '"#_ foo"']];
 }
Ejemplo n.º 4
0
 /** @test */
 function nonRootAstShouldWrapAsArrayImplicitly()
 {
     $data = Symbol::get('foo');
     $this->assertEquals('foo', igorw\edn\encode($data));
 }