Header menu logo F# Compiler Guide

ParsedInput Module

Holds operations for working with the untyped abstract syntax tree (ParsedInput).

Functions and values

Function or value Description

ParsedInput.exists predicate position parsedInput

Full Usage: ParsedInput.exists predicate position parsedInput

Parameters:
    predicate : SyntaxVisitorPath -> SyntaxNode -> bool - The predicate to match each node against.
    position : pos - The position in the input file down to which to apply the function.
    parsedInput : ParsedInput - The AST to search.

Returns: bool True if a matching node is found, or false if no matching node is found.

Applies the given predicate to each node of the AST and its context (path) down to a given position, returning true if a matching node is found, otherwise false. Traversal is short-circuited if no matching node is found through the given position.

predicate : SyntaxVisitorPath -> SyntaxNode -> bool

The predicate to match each node against.

position : pos

The position in the input file down to which to apply the function.

parsedInput : ParsedInput

The AST to search.

Returns: bool

True if a matching node is found, or false if no matching node is found.

Example

 let isInTypeDefn =
     (pos, parsedInput)
     ||> ParsedInput.exists (fun _path node ->
         match node with
         | SyntaxNode.SynTypeDefn _ -> true
         | _ -> false)
val isInTypeDefn: obj

ParsedInput.fold folder state parsedInput

Full Usage: ParsedInput.fold folder state parsedInput

Parameters:
    folder : 'State -> SyntaxVisitorPath -> SyntaxNode -> 'State - The function to use to update the state given each node and its context.
    state : 'State - The initial state.
    parsedInput : ParsedInput - The AST to fold over.

Returns: 'State The final state.

Applies a function to each node of the AST and its context (path), threading an accumulator through the computation.

folder : 'State -> SyntaxVisitorPath -> SyntaxNode -> 'State

The function to use to update the state given each node and its context.

state : 'State

The initial state.

parsedInput : ParsedInput

The AST to fold over.

Returns: 'State

The final state.

Example

 let unnecessaryParentheses =
    (HashSet Range.comparer, parsedInput) ||> ParsedInput.fold (fun acc path node ->
        match node with
        | SyntaxNode.SynExpr (SynExpr.Paren (expr = inner; rightParenRange = Some _; range = range)) when
            not (SynExpr.shouldBeParenthesizedInContext getLineString path inner)
            ->
            ignore (acc.Add range)
            acc

        | SyntaxNode.SynPat (SynPat.Paren (inner, range)) when
            not (SynPat.shouldBeParenthesizedInContext path inner)
            ->
            ignore (acc.Add range)
            acc

        | _ -> acc)
val unnecessaryParentheses: obj
union case Option.Some: Value: 'T -> Option<'T>
val ignore: value: 'T -> unit

ParsedInput.foldWhile folder state parsedInput

Full Usage: ParsedInput.foldWhile folder state parsedInput

Parameters:
    folder : 'State -> SyntaxVisitorPath -> SyntaxNode -> 'State option - The function to use to update the state given each node and its context, or to stop traversal by returning None.
    state : 'State - The initial state.
    parsedInput : ParsedInput - The AST to fold over.

Returns: 'State The final state.

Applies a function to each node of the AST and its context (path) until the folder returns None, threading an accumulator through the computation.

folder : 'State -> SyntaxVisitorPath -> SyntaxNode -> 'State option

The function to use to update the state given each node and its context, or to stop traversal by returning None.

state : 'State

The initial state.

parsedInput : ParsedInput

The AST to fold over.

Returns: 'State

The final state.

ParsedInput.tryNode position parsedInput

Full Usage: ParsedInput.tryNode position parsedInput

Parameters:
    position : pos - The position in the input file down to which to dive.
    parsedInput : ParsedInput - The AST to search.

Returns: (SyntaxNode * SyntaxVisitorPath) option The deepest node containing the given position, along with the path taken through the node's ancestors to find it.

Dives to the deepest node that contains the given position, returning the node and its path if found, or None if no node contains the position.

position : pos

The position in the input file down to which to dive.

parsedInput : ParsedInput

The AST to search.

Returns: (SyntaxNode * SyntaxVisitorPath) option

The deepest node containing the given position, along with the path taken through the node's ancestors to find it.

ParsedInput.tryPick chooser position parsedInput

Full Usage: ParsedInput.tryPick chooser position parsedInput

Parameters:
    chooser : SyntaxVisitorPath -> SyntaxNode -> 'T option - The function to apply to each node and its context to derive an optional value.
    position : pos - The position in the input file down to which to apply the function.
    parsedInput : ParsedInput - The AST to search.

Returns: 'T option The first value for which the function returns Some, or None if no matching node is found.

Applies the given function to each node of the AST and its context (path) down to a given position, returning Some x for the first node for which the function returns Some x for some value x, otherwise None. Traversal is short-circuited if no matching node is found through the given position.

chooser : SyntaxVisitorPath -> SyntaxNode -> 'T option

The function to apply to each node and its context to derive an optional value.

position : pos

The position in the input file down to which to apply the function.

parsedInput : ParsedInput

The AST to search.

Returns: 'T option

The first value for which the function returns Some, or None if no matching node is found.

Example

 let range =
     (pos, parsedInput) ||> ParsedInput.tryPick (fun _path node ->
       match node with
       | SyntaxNode.SynExpr (SynExpr.InterpolatedString (range = range)) when
           rangeContainsPos range pos
           -> Some range
       | _ -> None)
val range: obj
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>

ParsedInput.tryPickLast chooser position parsedInput

Full Usage: ParsedInput.tryPickLast chooser position parsedInput

Parameters:
    chooser : SyntaxVisitorPath -> SyntaxNode -> 'T option - The function to apply to each node and its context to derive an optional value.
    position : pos - The position in the input file down to which to apply the function.
    parsedInput : ParsedInput - The AST to search.

Returns: 'T option The last (deepest) value for which the function returns Some, or None if no matching node is found.

Applies the given function to each node of the AST and its context (path) down to a given position, returning Some x for the last (deepest) node for which the function returns Some x for some value x, otherwise None. Traversal is short-circuited if no matching node is found through the given position.

chooser : SyntaxVisitorPath -> SyntaxNode -> 'T option

The function to apply to each node and its context to derive an optional value.

position : pos

The position in the input file down to which to apply the function.

parsedInput : ParsedInput

The AST to search.

Returns: 'T option

The last (deepest) value for which the function returns Some, or None if no matching node is found.

Example

 let range =
     (pos, parsedInput)
     ||> ParsedInput.tryPickLast (fun path node ->
         match node, path with
         | FuncIdent range -> Some range
         | _ -> None)
val range: obj
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>

Type something to start searching.