Syntax Reference
CSTParser._do_kw_convert
CSTParser._kw_convert
CSTParser.can_become_chain
CSTParser.can_become_comparison
CSTParser.check_span
CSTParser.closer
CSTParser.compare
CSTParser.convertsigtotuple
CSTParser.disallowednumberjuxt
CSTParser.docable
CSTParser.find_arg_at
CSTParser.firstdiff
CSTParser.get_sig
CSTParser.has_error
CSTParser.is_getfield
CSTParser.is_range
CSTParser.is_wrapped_assignment
CSTParser.parse
CSTParser.parse_array
CSTParser.parse_block
CSTParser.parse_blockexpr
CSTParser.parse_blockexpr_sig
CSTParser.parse_call
CSTParser.parse_comma_sep
CSTParser.parse_compound
CSTParser.parse_curly
CSTParser.parse_doc
CSTParser.parse_dot_mod
CSTParser.parse_expression
CSTParser.parse_filter
CSTParser.parse_generator
CSTParser.parse_if
CSTParser.parse_iterator
CSTParser.parse_iterators
CSTParser.parse_kw
CSTParser.parse_macrocall
CSTParser.parse_parameters
CSTParser.parse_paren
CSTParser.parse_prefixed_string_cmd
CSTParser.parse_ref
CSTParser.parse_string_or_cmd
CSTParser.parse_tuple
CSTParser.parse_unary
CSTParser.read_ws_comment
CSTParser.remlineinfo!
CSTParser.revfirstdiff
CSTParser.str_value
CSTParser.@closer
CSTParser.@default
CSTParser.@nocloser
CSTParser.@precedence
Main
CSTParser.parse
— Functionparse(str, cont = false)
Parses the passed string. If cont
is true then will continue parsing until the end of the string returning the resulting expressions in a TOPLEVEL block.
CSTParser.parse_compound
— Methodparse_compound(ps::ParseState, ret::EXPR)
Attempts to parse a compound expression given the preceding expression ret
.
CSTParser.parse_doc
— Methodparse_doc(ps::ParseState)
Used for top-level parsing - attaches documentation (such as this) to expressions.
CSTParser.parse_expression
— Methodparse_expression(ps)
Parses an expression until closer(ps) == true
. Expects to enter the ParseState
the token before the the beginning of the expression and ends on the last token.
Acceptable starting tokens are:
- A keyword
- An opening parentheses or brace.
- An operator.
- An instance (e.g. identifier, number, etc.)
- An
@
.
CSTParser.parse_paren
— Methodparse_paren(ps, ret)
Parses an expression starting with a (
.
CSTParser.remlineinfo!
— Methodremlineinfo!(x)
Removes line info expressions. (i.e. Expr(:line, 1))
CSTParser.get_sig
— Methodget_sig(x)
Returns the full signature of function, macro and datatype definitions. Should only be called when has_sig(x) == true.
CSTParser.is_getfield
— Methodis_getfield(x::EXPR)
Is this an expression of the form a.b
.
CSTParser.is_wrapped_assignment
— Methodis_wrapped_assignment(x::EXPR)
Is x
an assignment expression, ignoring any surrounding parentheses.
CSTParser.read_ws_comment
— Methodlex_ws_comment(l::Lexer, c)
Having hit an initial whitespace/comment/semicolon continues collecting similar Chars
until they end. Returns a WS token with an indication of newlines/ semicolons. Indicating a semicolons takes precedence over line breaks as the former is equivalent to the former in most cases.
CSTParser._do_kw_convert
— Method_do_kw_convert(ps::ParseState, a::EXPR)
Should a
be converted to a keyword-argument expression?
CSTParser._kw_convert
— Method_kw_convert(ps::ParseState, a::EXPR)
Converted an assignment expression to a keyword-argument expression.
CSTParser.can_become_chain
— Methodcan_become_chain(x::EXPR, op::EXPR)
Is x
a binary call for +
or *
that can be extended to include more arguments?
CSTParser.can_become_comparison
— Methodcan_become_comparison(x::EXPR)
Is x
a binary comparison call (e.g. a < b
) that can be extended to include more arguments?
CSTParser.check_span
— Functioncheck_span(x, neq = [])
Recursively checks whether the span of an expression equals the sum of the span of its components. Returns a vector of failing expressions.
CSTParser.closer
— Methodcloser(ps::ParseState)
A magical function determining whether the parsing of an expression should continue or stop.
CSTParser.compare
— Methodcompare(x,y)
Recursively checks whether two Base.Expr are the same. Returns unequal sub- expressions.
CSTParser.convertsigtotuple
— Methodconvertsigtotuple(sig::EXPR)
When parsing a function or macro signature, should it be converted to a tuple?
CSTParser.disallowednumberjuxt
— Methoddisallowednumberjuxt(ret::EXPR)
Does this number literal end in a decimal and so cannot precede a paren for implicit multiplication?
CSTParser.docable
— Methoddocable(head)
When parsing a block of expressions, can documentation be attached? Prefixed docs at the top-level are handled within parse(ps::ParseState, cont = false)
.
CSTParser.find_arg_at
— Methodfind_arg_at(x, i)
Returns the index of the node of x
within which the byte offset i
falls.
CSTParser.firstdiff
— Methodfirstdiff(s0::AbstractString, s1::AbstractString)
Returns the last byte index, i, for which s0 and s1 are the same such that: s0[1:i] == s1[1:i]
CSTParser.has_error
— Methodhas_error(ps::ParseState)
has_error(x::EXPR)
Determine whether a parsing error occured while processing text with the given ParseState
, or exists as a (sub) expression of x
.
CSTParser.revfirstdiff
— Methodrevfirstdiff(s0::AbstractString, s1::AbstractString)
Reversed version of firstdiff but returns two indices, one for each string.
CSTParser.str_value
— Methodstr_value(x)
Attempt to get a string representation of a nodeless expression.
CSTParser.@closer
— Macro@closer ps rule body
Continues parsing closing on rule
.
CSTParser.@default
— Macro@default ps body
Parses the next expression using default closure rules.
CSTParser.@nocloser
— Macro@nocloser ps rule body
Continues parsing not closing on rule
.
CSTParser.@precedence
— Macro@precedence ps prec body
Continues parsing binary operators until it hits a more loosely binding operator (with precdence lower than prec
).
Components
CSTParser.is_range
— Methodis_range(x::EXPR)
Is x
a valid iterator for use in for
loops or generators?
CSTParser.parse_block
— FunctionContinue parsing statements until an element of closers
is hit (usually end
). Statements are grouped in a Block
EXPR.
CSTParser.parse_call
— Functionparse_call(ps, ret)
Parses a function call. Expects to start before the opening parentheses and is passed the expression declaring the function name, ret
.
CSTParser.parse_comma_sep
— FunctionParses a comma separated list, optionally allowing for conversion of assignment (=
) expressions to Kw
.
CSTParser.parse_dot_mod
— FunctionHelper function for parsing import/using statements.
CSTParser.parse_filter
— Methodparse_filter(ps::ParseState, arg)
Parse a conditional filter following a generator.
CSTParser.parse_generator
— Methodparse_generator(ps)
Having hit for
not at the beginning of an expression return a generator. Comprehensions are parsed as SQUAREs containing a generator.
CSTParser.parse_iterator
— FunctionParses an iterator, allowing for the preceding keyword outer
. Returns an error expression if an invalid expression is parsed (anything other than =
, in
, ∈
).
CSTParser.parse_iterators
— Methodparse_iterators(ps::ParseState, allowfilter = false)
Parses a group of iterators e.g. used in a for
loop or generator. Can allow for a succeeding Filter
expression.
CSTParser.parse_macrocall
— Methodparse_macrocall(ps)
Parses a macro call. Expects to start on the @
.
CSTParser.parse_parameters
— Functionparse_parameters(ps::ParseState, args::Vector{EXPR}, args1::Vector{EXPR} = EXPR[]; usekw = true)
Parses parameter arguments for a function call (e.g. following a semicolon).
CSTParser.parse_blockexpr
— Methodparse_blockexpr(ps::ParseState, head)
General function for parsing block expressions comprised of a series of statements terminated by an end
.
CSTParser.parse_blockexpr_sig
— Methodparse_blockexpr_sig(ps::ParseState, head)
Utility function to parse the signature of a block statement (i.e. any statement preceding the main body of the block). Returns nothing
in some cases (e.g. begin end
)
CSTParser.parse_if
— Functionparse_if(ps, nested=false)
Parse an if
block.
CSTParser.parse_kw
— Methodparse_kw(ps::ParseState)
Dispatch function for when the parser has reached a keyword.
CSTParser.parse_array
— Functionparse_array(ps)
Having hit '[' return either:
- A vect
- A vcat
- A comprehension
- An array (vcat of hcats)
CSTParser.parse_curly
— Methodparse_curly(ps, ret)
Parses the juxtaposition of ret
with an opening brace. Parses a comma seperated list.
CSTParser.parse_ref
— Methodparse_ref(ps, ret)
Handles cases where an expression - ret
- is followed by [
. Parses the following bracketed expression and modifies it's .head
appropriately.
CSTParser.parse_tuple
— Functionparse_tuple(ps, ret)
ret
is followed by a comma so tries to parse the rest of the tuple.
CSTParser.parse_unary
— Methodparse_unary(ps)
Having hit a unary operator at the start of an expression return a call.
CSTParser.parse_prefixed_string_cmd
— Methodparse_prefixed_string_cmd(ps::ParseState, ret::EXPR)
Parse prefixed strings and commands such as pre"text"
.
CSTParser.parse_string_or_cmd
— Functionparsestringor_cmd(ps)
When trying to make an INSTANCE
from a string token we must check for interpolating opoerators.