Class StreamParser

java.lang.Object
org.infosmid.stream.dsl.AppParser
org.infosmid.stream.dsl.StreamParser

public class StreamParser extends AppParser
Parser for stream DSL that generates StreamNode.
  • Constructor Details

    • StreamParser

      public StreamParser()
      Construct a default StreamParser.
    • StreamParser

      public StreamParser(String dsl)
      Construct a StreamParser without supplying the stream name up front. The stream name may be embedded in the definition; for example: mystream = http | file.
      Parameters:
      dsl - the stream definition DSL text
    • StreamParser

      public StreamParser(String name, String description, String dsl)
      Construct a StreamParser for a stream with the provided name.
      Parameters:
      name - stream name
      dsl - stream dsl text
  • Method Details

    • parse

      public StreamNode parse(String name, String description, String dsl)
      Parse a stream definition with the provided name and DSL.
      Parameters:
      name - stream name
      dsl - stream DSL text
      Returns:
      the AST for the parsed stream
      Throws:
      ParseException - thrown if expression fails parsing.
    • parse

      public StreamNode parse()
      Parse a stream definition.
      Returns:
      the AST for the parsed stream
      Throws:
      ParseException - thrown if expression fails parsing.
    • eatStreamName

      protected String eatStreamName()
      If a stream name is present, return it and advance the token position - otherwise return null.

      Expected format: name =

      Returns:
      stream name if present
    • eatStream

      protected StreamNode eatStream()
      Return a StreamNode based on the tokens resulting from the parsed DSL.

      Expected format: stream: (streamName) (sourceDestination) appList (sinkDestination)

      Returns:
      StreamNode based on parsed DSL
    • noMorePipes

      protected boolean noMorePipes()
      Return true if no more pipes are present from the current token position.
      Returns:
      true if no more pipes are present from the current token position
    • noMorePipes

      protected boolean noMorePipes(int position)
      Return true if no more pipes are present from the given position.
      Parameters:
      position - token position from which to check for the presence of pipes
      Returns:
      true if no more pipes are present from the given position
    • looksLikeDestination

      protected boolean looksLikeDestination()
      Return true if the current token position appears to be pointing at a destination.
      Returns:
      true if the current token position appears to be pointing at a destination
    • looksLikeDestination

      protected boolean looksLikeDestination(int position)
      Return true if the indicated position appears to be pointing at a destination.
      Parameters:
      position - token position to check
      Returns:
      true if the indicated position appears to be pointing at a destination.
    • eatSourceDestination

      protected SourceDestinationNode eatSourceDestination()
      If the current token position contains a source destination, return a SourceDestinationNode and advance the token position; otherwise return null.

      Expected format: ':' identifier > ':' identifier '.' identifier >

      Returns:
      a SourceDestinationNode or null if the token position is not pointing at a source destination
    • eatSinkDestination

      protected SinkDestinationNode eatSinkDestination()
      If the current token position contains a sink destination, return a SinkDestinationNode and advance the token position; otherwise return null.

      Expected format: '>' ':' identifier

      Returns:
      a SinkDestinationNode or null if the token position is not pointing at a sink destination
    • peekDestinationComponentToken

      protected Token peekDestinationComponentToken()
    • getTokenData

      protected String getTokenData(Token token)
    • eatDestinationReference

      protected DestinationNode eatDestinationReference(boolean canDefault)
      Return a DestinationNode for the token at the current position.

      A destination reference is the label component when referencing a specific app/label in a stream definition.

      Expected format: ':' identifier [ '.' identifier ]*

      Parameters:
      canDefault - allows the user to peek ahead to parse a reference when working with colons in the syntax.
      Returns:
      DestinationNode representing the destination reference
    • eatAppList

      protected List<AppNode> eatAppList(boolean preceedingSourceChannelSpecified)
      Return a list of AppNode starting from the current token position.

      Expected formats: appList: app (| app)* A stream may end in an app (if it is a sink) or be followed by a sink destination.

      Parameters:
      preceedingSourceChannelSpecified - indicator to parser about state of stream.
      Returns:
      a list of AppNode
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • makeDestinationNode

      protected DestinationNode makeDestinationNode(int startpos, int endPos, String destinationName, ArgumentNode[] argumentNodes)
    • makeStreamNode

      protected StreamNode makeStreamNode(String streamText, String streamName, String streamDescription, List<AppNode> appNodes, SourceDestinationNode sourceDestinationNode, SinkDestinationNode sinkDestinationNode)