Module Parser.TaglessFinal

This module provides parsing APIs for downstream clients that are written in tagless-final style. See PyreAst.TaglessFinal for more explanation about this style.

An implementation note: if the client provides a tagless-final specification that contains side-effects, then the order in which various syntax constructs gets recursed into by these APIs starts to matter. This library generally adopts the following order:

val parse_module : context:Context.t -> spec:(________________'module_______) TaglessFinal.t -> ?⁠enable_type_comment:bool -> string -> ('module_Error.t) Stdlib.Result.t

parse_module ~context ~spec input takes the string input and parse it as Python module using tagless-final specification spec. See documentation of Context.t for the meaning of the context argument.

Optionally an enable_type_comment argument can be specified. If it is true, the parser will attempt to populate the type_comment section of each AST node that has it. Otherwise, contents in comments will all get ignored and type_comment will always be unset.

val parse_expression : context:Context.t -> spec:(________'expression______________) TaglessFinal.t -> string -> ('expressionError.t) Stdlib.Result.t

parse_expression ~context ~spec input takes the string input and parse it as Python expression using tagless-final specification spec. See documentation of Context.t for the meaning of the context argument.

Optionally an enable_type_comment argument can be specified. If it is true, the parser will attempt to populate the type_comment section of each AST node that has it. Otherwise, contents in comments will all get ignored and type_comment will always be unset.

val parse_function_type : context:Context.t -> spec:(__________'function_type____________) TaglessFinal.t -> string -> ('function_typeError.t) Stdlib.Result.t

parse_expression ~context ~spec input takes the string input and parse it as Python function type signature using tagless-final specification spec. See documentation of Context.t for the meaning of the context argument.

Function type signature is not a reified construct in the core Python langugage. They only appears in Python2-style typing comments for functions and are superceded by the inline annotation syntax added in Python3. This API is provided here for completeness, in case downstream clients want to support the old comment-style annotation.