-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update JSON package to version 0.4 #3670
base: development
Are you sure you want to change the base?
Conversation
We can deal with everything by just using options to the toJSON method. In particular, we add an IndentLevel option which keeps track of the current indentation level, which was the primary purpose of the old JSONEncoder class. We also change some of the internal methods to functions. There was no multiple dispatch, so using methods was unnecessary.
Also, take a look at various json methods I had to define to deal with serializing hypertext objects and documentation nodes here. I had to resort to a hacky middle ground which you might not like, namely having I don't remember the reason for each particular entry, but once you have elapsedTime pkg = loadPackage(pkgname, Reload => true, LoadDocumentation => true)
L = new HashTable from pkg#"raw documentation";
L = selectValues(L, x -> not x#?PrimaryTag and not x#?"undocumented");
elapsedTime ("static/"|pkgname|".json") << toJSON(L, Indent => 2) << flush << close I still can't get |
Cool, I'll check it out! |
Also for mutable hash tables (like types and packages) and symbols other than "nil"
This is not valid JSON: i14 : json { "A\nB" }
o14 = ["A
B"]
i15 : fromJSON json { "A\nB" }
stdio:16:8:(3): error: syntax error at token '
', position 3
|
I added a few new |
Indeed! Good catch. |
Now try |
I think other than the newline issue this is working great. An annoying source of complexity for me was if I want |
This is mostly unrelated, but do you know what's happening here? i35 : html Saturation#"raw documentation"#"annihilator"#Inputs#0
o35 = <span><span class="tt">M</span>, $\left\{\texttt{an }\texttt{DocumentTag}\left\{\mathit{Format}\ \Rightarrow \
\texttt{Ideal},\:\mathit{Key}\ \Rightarrow \ \mathit{Ideal},\:\mathit{Package}\ \Rightarrow \
\texttt{Macaulay2Doc},\:\texttt{RawDocumentation}\ \Rightarrow \ \texttt{null}\right\}\texttt{ideal},\:\texttt{,
},\:\texttt{a }\texttt{DocumentTag}\left\{\mathit{Format}\ \Rightarrow \ \texttt{Module},\:\mathit{Key}\ \Rightarrow \
\mathit{Module},\:\mathit{Package}\ \Rightarrow \ \texttt{Macaulay2Doc},\:\texttt{RawDocumentation}\ \Rightarrow \
\texttt{null}\right\}\texttt{module},\:\texttt{, or },\:\texttt{a }\texttt{DocumentTag}\left\{\mathit{Format}\
\Rightarrow \ \texttt{RingElement},\:\mathit{Key}\ \Rightarrow \ \mathit{RingElement},\:\mathit{Package}\ \Rightarrow \
\texttt{Macaulay2Doc},\:\texttt{RawDocumentation}\ \Rightarrow \ \texttt{null}\right\}\texttt{ring element}\right\}$,
</span> |
Maybe this is overkill, but I went ahead and updated
It's still not quite right when composing with i2 : fromJSON toJSON "foo\nbar"
o2 = foo\nbar
i3 : oo == "foo\nbar"
o3 = false |
We
exportremove theJSONEncoder
class so that developers can write their owntoJSON
methods. Thanks @mahrud for the suggestion!