Class Matcher

  • java.lang.Object
    • at.ofai.music.util.Matcher


  • public class Matcher
    extends java.lang.Object
    A simple parser for Prolog-type notation, but only handling the subset of Prolog used in "match" files.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      protected java.lang.String s
      The unparsed part of the current line of text
    • Constructor Summary

      Constructors 
      Constructor and Description
      Matcher(java.lang.String data)
      The constructor is initialised with the input line of text for parsing
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      java.lang.String get()
      Return the unparsed part of the input line
      char getChar()
      Returns and consumes the next character of unparsed data.
      double getDouble()
      Returns and consumes a double value, with two limitations: 1) exponents are ignored e.g.
      int getInt()
      Returns and consumes an int value from the head of the unparsed data.
      at.ofai.music.util.Matcher.ListTerm getList()
      Returns and consumes a comma-separated list of terms, surrounded by a matching set of parentheses, brackets or braces.
      at.ofai.music.util.Matcher.Predicate getPredicate()
      Returns and consumes a Prolog-style predicate, consisting of a functor followed by an optional list of arguments in parentheses.
      java.lang.String getString()
      Returns and consumes a string terminated by the first comma, parenthesis, bracket or brace.
      java.lang.String getString(boolean extraPunctuation)
      Returns and consumes a string terminated by various punctuation symbols.
      boolean hasData()
      Returns true if there is input data remaining
      boolean matchString(java.lang.String m)
      Matches a String with the unparsed input data.
      void set(java.lang.String data)
      Reinitialise the parser with a new line of input
      void skip(char c)
      Skips input up to and including the next instance of a given character.
      void trimSpace()
      Removes whitespace from the beginning and end of the line.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • s

        protected java.lang.String s
        The unparsed part of the current line of text
    • Constructor Detail

      • Matcher

        public Matcher(java.lang.String data)
        The constructor is initialised with the input line of text for parsing
    • Method Detail

      • set

        public void set(java.lang.String data)
        Reinitialise the parser with a new line of input
      • get

        public java.lang.String get()
        Return the unparsed part of the input line
      • hasData

        public boolean hasData()
        Returns true if there is input data remaining
      • matchString

        public boolean matchString(java.lang.String m)
        Matches a String with the unparsed input data. If the complete String occurs at the beginning of the unparsed data, the unparsed data is advanced to the end of the String; otherwise the data is left unchanged.
        Parameters:
        m - the String to match
        Returns:
        true if m matches the beginning of the unparsed data
      • skip

        public void skip(char c)
        Skips input up to and including the next instance of a given character. It is an error for the character not to occur in the data.
        Parameters:
        c - the character to skip to
      • trimSpace

        public void trimSpace()
        Removes whitespace from the beginning and end of the line.
      • getChar

        public char getChar()
        Returns and consumes the next character of unparsed data.
      • getInt

        public int getInt()
        Returns and consumes an int value from the head of the unparsed data.
      • getDouble

        public double getDouble()
        Returns and consumes a double value, with two limitations: 1) exponents are ignored e.g. 5.4e-3 is read as 5.4; 2) a value terminated by a 2nd "." causes an Exception to be thrown
      • getString

        public java.lang.String getString()
        Returns and consumes a string terminated by the first comma, parenthesis, bracket or brace. Equivalent to getString(false).
      • getString

        public java.lang.String getString(boolean extraPunctuation)
        Returns and consumes a string terminated by various punctuation symbols. Terminators include: '(', '[', '{', ',', '}', ']' and ')'. An Exception is thrown if no terminator is found.
        Parameters:
        extraPunctuation - Specifies whether '-' and '.' are terminators
      • getList

        public at.ofai.music.util.Matcher.ListTerm getList()
        Returns and consumes a comma-separated list of terms, surrounded by a matching set of parentheses, brackets or braces. The list may have any number of levels of recursion.
        Returns:
        The return value is a linked list of the terms (which themselves may be lists or String values)
      • getPredicate

        public at.ofai.music.util.Matcher.Predicate getPredicate()
        Returns and consumes a Prolog-style predicate, consisting of a functor followed by an optional list of arguments in parentheses.