Class Fragment<D,T,A>

java.lang.Object
eu.bandm.tools.ramus.ogma.AbstractExpression<D,T,A>
eu.bandm.tools.ramus.ogma.Fragment<D,T,A>
Type Parameters:
D - the type of document identifiers
T - the type of token types
A - the type of parsing results

public class Fragment<D,T,A> extends AbstractExpression<D,T,A>
A syntax–semantics pair that stores the result in a variable.

Fragments are useful for recording semantic results in passing, and use them later.

See Also:
  • Constructor Details

    • Fragment

      public Fragment(Object key, Parser<D,T> baseSyntax, Data.View<A> semantics)
      Creates a new fragment.

      The initial value associated with the key is the empty optional, Data.none().

      The semantic effect of storing the result value is added implicitly to the given parser.

      Parameters:
      key - the key for the result
      baseSyntax - the parser that specifies the syntax, and leaves the result value in the accumulator
      semantics - the data view that specifies the semantic result
      Throws:
      NullPointerException - if any parameter is null
    • Fragment

      public Fragment(Object key, Data initialValue, Parser<D,T> baseSyntax, Data.View<A> semantics)
      Creates a new fragment.

      The semantic effect of storing the result value is added implicitly to the given parser.

      Parameters:
      key - the key for the result
      initialValue - the initial value associated with the key
      baseSyntax - the parser that specifies the syntax, and leaves the result value in the accumulator
      semantics - the data view that specifies the semantic result
      Throws:
      NullPointerException - if any parameter is null
  • Method Details

    • getKey

      public final Object getKey()
      Returns the key for the result of this fragment.
      Returns:
      the key for the result of this fragment
    • getInitialValue

      public final Data getInitialValue()
      Returns the initial value for the result of this fragment.
      Returns:
      the initial value for the result of this fragment
    • isImported

      public final boolean isImported()
      Checks whether this fragment imports the result from an enclosing scope.
      Returns:
      true if this fragment imports the result from an enclosing scope; false if the result is obtained by parsing
      See Also:
    • assign

      public Fragment<D,T,A> assign()
      Returns a fragment that has the syntax and semantics of this expression and assigns the result of this expression to a fresh key.

      The key used by the resulting fragment is not publicly visible. Hence its result can only be retrieved via State.project(AbstractExpression).

      Overrides:
      assign in class AbstractExpression<D,T,A>
      Returns:
      this
    • imported

      public Fragment<D,T,A> imported()
      Returns a variant of this fragment that imports the result from an enclosing scope.

      The resulting fragment has no syntax of its own; the result is retrieved from an earlier parsing.

      If this fragment is already imported, it is returned directly.

      Returns:
      a variant of this fragment that imports the result from an enclosing scope
      See Also:
    • startInterval

      public static <D, T> Fragment<D,T,Location<D>> startInterval(ParserFactory factory)
      Returns a fragment that sets the result value to the token location at the current input state.
      Type Parameters:
      D - the type of source document identifiers
      T - the type of token types; typically an enum type
      Returns:
      a fragment that sets the result value to the token location at the current input state.
    • endInterval

      public static <D, T> Fragment<D,T,Location<D>> endInterval(ParserFactory factory)
      Returns a fragment that sets the result value to the token location before the current input state.
      Type Parameters:
      D - the type of source document identifiers
      T - the type of token types; typically an enum type
      Returns:
      a fragment that sets the result value to the token location before the current input state.