Parse.Term : term quotation -> term
The first phase converts the quotation argument into abstract syntax, a relatively simple parse tree datatype, with the following datatype definition (from Absyn):
datatype vstruct = VAQ of term | VIDENT of string | VPAIR of vstruct * vstruct | VTYPED of vstruct * pretype datatype absyn = AQ of term | IDENT of string | APP of absyn * absyn | LAM of vstruct * absyn | TYPED of absyn * pretype
This first phase converts infixes, mixfixes and all the other categories of syntactic rule from the global grammar into simple structures built up using APP. For example, `x op y` (where op is an infix) will turn into
APP(APP(IDENT "op", IDENT "x"), IDENT "y")
APP(APP(IDENT "f", IDENT "x"), IDENT "y")
The second phase of parsing consists of the resolution of names, identifying what were just VARs as constants or genuine variables (whether free or bound). This phase also annotates all leaves of the data structure (given in the entry for Preterm) with type information.
The third phase of parsing works over the Preterm datatype and does type-checking, though ignoring overloaded values. The datatype being operated over uses reference variables to allow for efficiency, and the type-checking is done “in place”. If type-checking is successful, the resulting value has consistent type annotations.
The final phase of parsing resolves overloaded constants. The type-checking done to this point may completely determine which choice of overloaded constant is appropriate, but if not, the choice may still be completely determined by the interaction of the possible types for the overloaded possibilities.
Finally, depending on the value of the global flags guessing_tyvars and guessing_overloads, the parser will make choices about how to resolve any remaining ambiguities.
The parsing process is entirely driven by the global grammar. This value can be inspected with the term_grammar function.