JavaScript:SpiderMonkey:Parser API: Difference between revisions

Jump to navigation Jump to search
a couple more notes
(JS API design notes)
(a couple more notes)
Line 16: Line 16:
<pre>
<pre>
class Parser<A, Visitor> {
class Parser<A, Visitor> {
     Parser(Visitor<A>? factory);
     Parser(factory : Visitor<A>?);


     parse(src : string,
     parse(src : string,
           [filename : string | null,
           [filename : string | null,
           startLine : number >= 1 | null,
           startLine : (number >= 1)?,
           startColumn : number >= 0 | null])
           startColumn : (number >= 0)?])
         : A;
         : A;
}
}
Line 27: Line 27:


This would allow the <code>parse</code> method to use the visitor as a way of injecting the parsed nodes into whatever type ''A'' the client wants. Making the argument optional makes it easy to default to the JsonMLAST format.
This would allow the <code>parse</code> method to use the visitor as a way of injecting the parsed nodes into whatever type ''A'' the client wants. Making the argument optional makes it easy to default to the JsonMLAST format.
It's a little messy (wrt types) to reuse the visitor interface for this, since the JsonMLAST visitor expects JsonMLAST values as arguments, whereas this use expects the type ''A'' as arguments. So it's maybe better to have a parallel "Factory" interface that's the same as the visitor interface but with createXXXX methods instead.


Should also implement a JsonMLAST processor that takes a visitor:
Should also implement a JsonMLAST processor that takes a visitor:
Line 36: Line 38:


This could be implemented in pure JS, at least initially. (It'll be ugly without pattern matching, though.)
This could be implemented in pure JS, at least initially. (It'll be ugly without pattern matching, though.)
I dislike the verbosity of the JsonMLAST name. Maybe just AST is good enough.


=== Plan ===
=== Plan ===
34

edits

Navigation menu