more list formatting adjustments
This commit is contained in:
parent
efcea75c43
commit
608b05876c
1 changed files with 155 additions and 152 deletions
|
@ -304,7 +304,7 @@ however, it is important to recognize that jsx is greedy by default. jsx will co
|
|||
## exports ##
|
||||
|
||||
|
||||
### encoder/3, decoder/3 and parser/3 ###
|
||||
* ### encoder/3, decoder/3 and parser/3 ###
|
||||
|
||||
```erlang
|
||||
decoder(Module, Args, Opts) -> Fun((JSONText) -> any())
|
||||
|
@ -331,8 +331,7 @@ all three functions return an anonymous function that takes the appropriate type
|
|||
|
||||
see [below](#callback_exports) for details on the callback module
|
||||
|
||||
|
||||
### decode/1,2 ###
|
||||
* ### decode/1,2 ###
|
||||
|
||||
```erlang
|
||||
decode(JSON) -> Term
|
||||
|
@ -362,7 +361,7 @@ declaring more than one post-decoder will result in a `badarg` error exception
|
|||
raises a `badarg` error exception if input is not valid json
|
||||
|
||||
|
||||
### encode/1,2 ###
|
||||
* ### encode/1,2 ###
|
||||
|
||||
```erlang
|
||||
encode(Term) -> JSON
|
||||
|
@ -377,6 +376,10 @@ encode(Term, Opts) -> JSON
|
|||
|
||||
`encode` parses a json text (a `utf8` encoded binary) and produces an erlang term (see [json <-> erlang mapping](#json---erlang-mapping))
|
||||
|
||||
the option `{space, N}` inserts `N` spaces after every comma and colon in your json output. `space` is an alias for `{space, 1}`. the default is `{space, 0}`
|
||||
|
||||
the option `{indent, N}` inserts a newline and `N` spaces for each level of indentation in your json output. note that this overrides spaces inserted after a comma. `indent` is an alias for `{indent, 1}`. the default is `{indent, 0}`
|
||||
|
||||
`{pre_encode, F}` is a user defined function of arity 1 that is called on each input value. it may return any valid json value to be substituted in the returned json. for example:
|
||||
|
||||
```erlang
|
||||
|
@ -387,14 +390,10 @@ encode(Term, Opts) -> JSON
|
|||
|
||||
declaring more than one pre-encoder will result in a `badarg` error exception
|
||||
|
||||
the option `{space, N}` inserts `N` spaces after every comma and colon in your json output. `space` is an alias for `{space, 1}`. the default is `{space, 0}`
|
||||
|
||||
the option `{indent, N}` inserts a newline and `N` spaces for each level of indentation in your json output. note that this overrides spaces inserted after a comma. `indent` is an alias for `{indent, 1}`. the default is `{indent, 0}`
|
||||
|
||||
raises a `badarg` error exception if input is not a valid erlang representation of json
|
||||
|
||||
|
||||
### format/1,2 ###
|
||||
* ### format/1,2 ###
|
||||
|
||||
```erlang
|
||||
format(JSON) -> JSON
|
||||
|
@ -414,7 +413,7 @@ the option `{indent, N}` inserts a newline and `N` spaces for each level of inde
|
|||
raises a `badarg` error exception if input is not valid json
|
||||
|
||||
|
||||
### minify/1 ###
|
||||
* ### minify/1 ###
|
||||
|
||||
```erlang
|
||||
minify(JSON) -> JSON
|
||||
|
@ -427,7 +426,7 @@ minify(JSON) -> JSON
|
|||
raises a `badarg` error exception if input is not valid json
|
||||
|
||||
|
||||
### prettify/1 ###
|
||||
* ### prettify/1 ###
|
||||
|
||||
```erlang
|
||||
prettify(JSON) -> JSON
|
||||
|
@ -440,7 +439,7 @@ prettify(JSON) -> JSON
|
|||
raises a `badarg` error exception if input is not valid json
|
||||
|
||||
|
||||
### is_json/1,2 ###
|
||||
* ### is_json/1,2 ###
|
||||
|
||||
```erlang
|
||||
is_json(MaybeJSON) -> true | false
|
||||
|
@ -455,7 +454,7 @@ returns true if input is a valid json text, false if not
|
|||
what exactly constitutes valid json may be altered per [options](#data_types)
|
||||
|
||||
|
||||
### is_term/1,2 ###
|
||||
* ### is_term/1,2 ###
|
||||
|
||||
```erlang
|
||||
is_term(MaybeJSON) -> true | false
|
||||
|
@ -474,7 +473,7 @@ what exactly constitutes valid json may be altered per [options](#data_types)
|
|||
|
||||
the following functions should be exported from a jsx callback module
|
||||
|
||||
### Module:init/1 ###
|
||||
* ### Module:init/1 ###
|
||||
|
||||
```erlang
|
||||
Module:init(Args) -> InitialState
|
||||
|
@ -485,7 +484,7 @@ Module:init(Args) -> InitialState
|
|||
|
||||
whenever any of `encoder/3`, `decoder/3` or `parser/3` are called, this function is called with the `Args` argument provided in the calling function to obtain `InitialState`
|
||||
|
||||
### Module:handle_event/2 ###
|
||||
* ### Module:handle_event/2 ###
|
||||
|
||||
```erlang
|
||||
Module:handle_event(Event, State) -> NewState
|
||||
|
@ -497,47 +496,51 @@ Module:handle_event(Event, State) -> NewState
|
|||
|
||||
semantic analysis is performed by repeatedly calling `handle_event/2` with a stream of events emitted by the tokenizer and the current state. the new state returned is used as the input to the next call to `handle_event/2`. the following events must be handled:
|
||||
|
||||
* `start_object`<p>the start of a json object</p>
|
||||
- `start_object`
|
||||
|
||||
* `end_object`<p>the end of a json object</p>
|
||||
the start of a json object
|
||||
|
||||
* `start_array`
|
||||
- `end_object`
|
||||
|
||||
the end of a json object
|
||||
|
||||
- `start_array`
|
||||
|
||||
the start of a json array
|
||||
|
||||
* `end_array`
|
||||
- `end_array`
|
||||
|
||||
the end of a json array
|
||||
|
||||
* `{key, binary()}`
|
||||
- `{key, binary()}`
|
||||
|
||||
a key in a json object. this is guaranteed to follow either `start_object` or a json value. it will usually be a `utf8` encoded binary. see [options](#data_types) for possible exceptions
|
||||
|
||||
* `{string, binary()}`
|
||||
- `{string, binary()}`
|
||||
|
||||
a json string. it will usually be a `utf8` encoded binary. see [options](#data_types) for possible exceptions
|
||||
|
||||
* `{integer, integer()}`
|
||||
- `{integer, integer()}`
|
||||
|
||||
an erlang integer (bignum)
|
||||
|
||||
* `{float, float()}`
|
||||
- `{float, float()}`
|
||||
|
||||
an erlang float
|
||||
|
||||
* `{literal, true}`
|
||||
- `{literal, true}`
|
||||
|
||||
the atom `true`
|
||||
|
||||
* `{literal, false}`
|
||||
- `{literal, false}`
|
||||
|
||||
the atom `false`
|
||||
|
||||
* `{literal, null}`
|
||||
- `{literal, null}`
|
||||
|
||||
the atom `null`
|
||||
|
||||
* `end_json`
|
||||
- `end_json`
|
||||
|
||||
this event is emitted when syntactic analysis is completed. you should do any cleanup and return the result of your semantic analysis
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue