Giter Club home page Giter Club logo

Comments (7)

bovine avatar bovine commented on August 15, 2024 1

If you would just like a cleaner syntax for quickly parsing snippets, you could of course create a helper proc:

proc yajl_parse {json} {
    set object [yajl create #auto]
    set parsed [$object parse $json]
    $object delete
    return $parsed
}

from yajl-tcl.

bradennapier avatar bradennapier commented on August 15, 2024

Once this happens it actually breaks the object forever as well so that all future parse calls (including those that would have succeeded before this) fail.

Update: It fails when [$j parse] is called twice on a single instance without starting over and resetting from scratch. This is a pretty bad situation when you are passing it around to various procs that need to handle things.

Here is an example of it dying if you call it twice with the generated value itself:

% set j [yajl create #auto]
yajl12
% $j map_open map_key persist number 1 map_close
% set json [$j get]
{"persist":1}
% $j parse $json
map_open map_key persist number 1 map_close
% $j parse $json
parse error: trailing garbage
                                       {"persist":1}
                     (right here) ------^

So I guess the [parse] command is actually adding to the final $json object? not sure what is happening here to cause it.

calling [yajl reset] does fix it but that kills the data being built which essentially requires multiple yajl objects to reliably parse anything without worry of errors from other procs since you can only ever parse one time per object.

from yajl-tcl.

bovine avatar bovine commented on August 15, 2024

I don't think using the same object simultaneously for parsing and generation activities is really a use-case that was intended. I haven't looked deep enough to determine if it is feasible to make work as you intend yet, but at the moment I'd probably lean towards making any of the "parse" methods generate an error if it is still being used for generation without an intervening "reset".

from yajl-tcl.

bradennapier avatar bradennapier commented on August 15, 2024

I mean if that is the case, it kind of backs up the concept of making the [parse] command a static method and removing it from the object all together - otherwise it simply creates confusion and conflicts since they are 100% different at that point if they are not ever meant to be used together without breaking each other.

from yajl-tcl.

bovine avatar bovine commented on August 15, 2024

It cannot be easily static for the previously stated reasons of needing to store substantial state and callback data during the process of the parse (additionally we allow for incremental parsing of large messages over multiple statements). If you need to do two unrelated operations simultaneously, then you need to create two separate objects.

from yajl-tcl.

bovine avatar bovine commented on August 15, 2024

The above example probably needs a catch to handle errors during the parse, in order to avoid leaking the object without deleting it.

from yajl-tcl.

bradennapier avatar bradennapier commented on August 15, 2024

I ended with the following: https://github.com/Dash-OS/tcl-modules/blob/master/json_tools-1.3.0.tm#L412-L420

try/catch is the responsibility in this case of the caller since that is a lib. Since it is using a single object in this case it ends up working well - let me knwo fi there is a problem with my logic there but it appears to work (ignore description mentioning it is a bug, that was before your replies above :-P)

from yajl-tcl.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.