Apex AST in JSON Blob - salesforce

I am trying to work on a code formatter for Apex. I need the AST to plug it into a popular Javascript formatter (prettier). Is there by any chance I can get the Apex AST and put it in JSON blob format?

My best guess would be to use apex-jorje (see this to learn how to use the jars from Maven) to parse the code into a Java AST, and then transverse the tree to convert each node to JS in whichever way you find fitting.
Parsing the code is straight-forward enough (see an example here), and once you have a Compilation, you can transverse the AST.
Since this is not really a PMD issue, you can use the AST provided by Jorje, you don't need the adaptation to PMD's AST structures.

Related

Is it possible to build One AST for a entire React Project by Babel?

I am learning Babel now.
And I wonder if is possible to use #babel/parser to build One AST for an entire react project.
The docs I have searched are all about one file, and I want to find a way how to recursively parse file in a project and merge AST into a single one.
An AST is an abstract representation of source code, so this question doesn't really make sense. If you have multiple files, then you get multiple independent ASTs. If you want a single AST representing all of your files, then something would need to process all the independent files and then merge them all together in some way.
That merging is well outside the scope of Babel and is what Webpack, Rollup, ESBuild and such perform during their build process, so depending on your goals, I suppose you could use one of those to generate a single file first, and then create an AST from that single file.

Can shake generate dependency graph in graphviz format?

Using --profile makes shake generate a report.html file from which one can run queries and generate a dependency graph of build rules. Would it be possible to get that graph in graphviz format instead of needing a browser to display it?
If you run --profile=report.json then you get a JSON file containing all the data that goes into the profiling. From that, it should be quite easy to generate a GraphViz output. If there is demand, a GraphViz generation mode could be added to --profile.
However, past experience suggests that a GraphViz file of all dependencies is just too large to be practically viewed. To make the graph view practical you either need to group/filter the graph, or use a better graph viewer.

LaTex notation in Database (e.g. PostgreSQL) - but rendered for human readability

How can LaTex syntax in database cells (e.g. PostgreSQL) be made human readable as mathematical notation (symbols, greek letters, etc.) on the client-side, maybe with a web-interface? How can this be achieved on client-side?
Scenario:
The human user writes LaTex strings in the database. The objective is, that someone else (who does not know LaTex) can read mathematical notation on the web-browser that retrieves the entries from the database (CRUD).
Example for web-based mathematical notation of LaTex:
For example like this one (but which does not relate to an underlying own database): http://cdn.mathjax.org/mathjax/latest/test/sample-dynamic-2.html . Example: The system gets the LaTex string "$\alpha$" (which would be stored in the database cell) and immedately prints out the nicely formated greek letter.
Example for web-based database application (CRUD): Such a webbrowser-based client-interface is e.g. "Portofino"; but it does not render LaTex for mathematical notation. Though, the Portofino interface can be customized using the Groovy scripting language, but I do not know how. Does anyone know how Groovy could be used to implement MathJax or KaTex?
So the basic idea is to "merge" the concepts of these two examples into one solution. Or would you propose a different strategy?
As far as I know, there are no PostgreSQL client applications that support rendering of LaTeX, let alone render mathematical formulas in LaTeX format.
In a web environment MathJax seems the way to go. Since it is based on JavaScript it runs in all modern browsers (that do not have JavaScript blocked).
You would query the PostgreSQL database for your LaTeX formatted formula, just like you would for any other text data, and then feed that to the MathJax processor.
I don't know MathJax and KaTeX, but them being JavaScript libraries, you can integrate them in your web application. Specifically, in Portofino all forms are rendered with a library called Elements, which ensures that all form fields have a HTML id and a fixed HTML structure and CSS class, jQuery is included, so it is very easy to replace a given field's content with a TeX-rendered formula. You have to know JavaScript, of course.
Groovy has nothing to do with the above stuff, because Groovy is server-side, while the aforementioned technologies are client-side.
That said, this is only one side of the question. The other side is, how are values input into the database? Does the user (or the software) insert TeX strings directly? More broadly, what do you want to achieve? Because, as it is, your question is a bit vague.

Using X3D and Javascript

I'm supposed to develop a project using X3D. I have an idea to create a conversor of DXf file to X3D. however, to do that, I have to use Javascript to manage this properly, but I haven't found a way to integrate Javascript with X3D. Does someone know some way to do that?
Previously, I though in loading the dxf file, get the data I need, and save this as a X3D file, like writing the XML.
thanks in advance
X3D supports JavaScript natively in the Script node (and it is sometimes referred to via the standardization name EcmaScript). Script events are connected to a scene via ROUTE statements. This provides a bridge between declarative 3D models and programmatic events/computation. Lots more online:
http://x3dgraphics.com/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting
http://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30Scripts
http://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html#Scripts
http://www.web3d.org/x3d/content/X3dTooltips.html#Script
http://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/scripting.html#Script
In VRML you can integrate javascript using the Script node.
Here's an example:
DEF SCRIPT Script {
url ["javascript:
here goes your javascript code
"]
}
Considering that X3D started as the XML representation of VRML then I suppose there is support in X3D for the Script node.
Edit: Yes I can confirm the above.

Recommended JSON parser in C? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Best Way To Parse JSON in C?
I need to parse, validate and query JSON data in a C application, and I am looking for recommendations for the best C JSON library.
The data will be input as strings (char* UTF-8 data), which I first need to validate to ensure the input is valid JSON, and then I will need to perform some simple queries (iterating over the data).
I do not need to produce JSON, I only need to consume it. I also would prefer a parser that will load the whole document into memory rather than a SAX-style parser.
Can anyone recommend a good library, or does anyone have any experience or had problems with libraries?
I have seen the list of libraries in C on JSON.org - are there any good libraries missing from this list?
My requirements are for a small library with as little code / runtime size as possible, and a permissive BSD/MIT style license, since my library will be embedded in other applications.
Thanks,
Marc
I'm recommending Jansson, which I find quite easy to use (and which loads the JSON in memory at once). However, I don't know well all the alternatives, and I don't have a working experience of all of them.
I would choose json-c which is a fast and easy to use JSON parser written in C.

Resources