[Ur] How to design JSON interface?

Marc Weber marco-oweber at gmx.de
Wed Dec 1 10:53:08 EST 2010


Excerpts from Adam Chlipala's message of Wed Dec 01 16:29:46 +0100 2010:
> I'm thinking that the most pragmatic way forward is to build a 
> parsing/pretty-printing tool that takes as input a description of a 
> protocol and then outputs (as text) the Ur/Web code for participating in 
> it.  Alternatively, you could even output C/JavaScript code for 
> efficiency.  How does that sound?  It requires no knowledge of any 
> existing compiler's implementation.
Have a look at this implementation: line 28 to 53
https://github.com/MarcWeber/vim-addon-json-encoding/blob/master/autoload/json_encoding.vim
This simple code is used in three projects now: vim <->
(ensime,codefellomw,scion) communication and is working fine.

I'm fine with simple code being replaced by more general code later.

General encoding / decoding or pretty printing code would work and would
be nicer.  But it would also take much more time to write and test and
learn.

Can you provide an example which only encodes a string - (forget about
quoting - I know how to write escaping functions) - I'd be glad. Then I
could add missing implementations by copy pasting and replacing string
by int, list, option, ... etc.

I'm also fine with adding warnings like "This code will be replaced by more
generic code in the future ..."
 
> I feel that time spent on that would be even better spent writing a 
> tutorial, which I'm still putting off.  So, if I feel like doing this 
> kind of thing, it will be in the latter form.
:) You're correct. However test cases never hurt. This way you make sure
that you don't break anything. That's why they exist. And test cases
usually contain more corner cases than tutorials do.

Yours
Marc Weber



More information about the Ur mailing list