class_docstr: A filter that can be applied to an object
  
  A filter returns a value when applied to an object such as a string
  which is evaluated as either True (accept it) or False (reject it).
  
  The setting value is composed of tokens with a scheme-like syntax:
  
  (and (filename contains "_w1_") (extension is "tif"))
  
  Each predicate has a symbolic name which is used to find it. The predicate
  has an evaluation function and a display name. Predicates also have lists
  of the predicates that they operate on. The leftmost predicate takes two
  arguments. Other predicates, it is up to the developer. Predicates
  are called with the object of interest as the first argument and the
  evaluation value of the predicate to the right as the second argument.
  
  For something like "filename contains "foo"", "contains" returns a function
  that returns true if the first argument is "foo" and "filename" parses
  the first of its arguments to get the filename and returns the result of
  applying the result of "contains" to the filename.
  
  There are three special predicates:
  "and", "or" and "literal".
class_docstr_tok: ["A","filter","that","can","be","applied","to","an","object","A","filter","returns","a","value","when","applied","to","an","object","such","as","a","string","which","is","evaluated","as","either","True","(","accept","it",")","or","False","(","reject","it",")",".","The","setting","value","is","composed","of","tokens","with","a","scheme-like","syntax",":","(","and","(","filename","contains","``","_w1_","''",")","(","extension","is","``","tif","''",")",")","Each","predicate","has","a","symbolic","name","which","is","used","to","find","it",".","The","predicate","has","an","evaluation","function","and","a","display","name",".","Predicates","also","have","lists","of","the","predicates","that","they","operate","on",".","The","leftmost","predicate","takes","two","arguments",".","Other","predicates",",","it","is","up","to","the","developer",".","Predicates","are","called","with","the","object","of","interest","as","the","first","argument","and","the","evaluation","value","of","the","predicate","to","the","right","as","the","second","argument",".","For","something","like","``","filename","contains","``","foo","''","''",",","``","contains","''","returns","a","function","that","returns","true","if","the","first","argument","is","``","foo","''","and","``","filename","''","parses","the","first","of","its","arguments","to","get","the","filename","and","returns","the","result","of","applying","the","result","of","``","contains","''","to","the","filename",".","There","are","three","special","predicates",":","''","and","''",",","``","or","''","and","``","literal","''","."]
docstr: Parse a token out of the front of the string
  
  Returns the next token in the string, the rest of the string
  and the acceptable tokens for the rest of the string.
docstr_tok: ["Parse","a","token","out","of","the","front","of","the","string","Returns","the","next","token","in","the","string",",","the","rest","of","the","string","and","the","acceptable","tokens","for","the","rest","of","the","string","."]
code: def parse_token(cls, s, predicates):
      """Parse a token out of the front of the string
  
      Returns the next token in the string, the rest of the string
      and the acceptable tokens for the rest of the string.
      """
      orig_predicates = predicates
      if list in predicates:
          needs_list = True
          predicates = list(predicates)
          predicates.remove(list)
      else:
          needs_list = False
      if s[0] == "(":
          if not needs_list:
              raise ValueError("List not allowed in current context")
          s = s[1:]
          result = []
          while s[0] != ")":
              token, s, predicates = cls.parse_token(s, predicates)
              result.append(token)
          if len(s) > 1 and s[1] == " ":
              return result, s[2:], orig_predicates
          return result, s[1:], orig_predicates
      elif needs_list:
          raise ValueError("List required in current context")
      if s[0] == '"':
          if LITERAL_PREDICATE not in predicates:
              raise ValueError("Literal not allowed in current context")
          escape_next = False
          result = ""
          for i in range(1, len(s)):
              if escape_next:
                  result += s[i]
                  escape_next = False
              elif s[i] == "\\":
                  escape_next = True
              elif s[i] == '"':
                  return result, s[(i + 1) :], []
              else:
                  result += s[i]
          raise ValueError("Unterminated literal")
      #
      # (?:\\.|[^ )]) matches either backslash-anything or anything but
      # space and parentheses. So you can have variable names with spaces
      # and that's needed for arbitrary metadata names
      #
      match = re.match(r"^((?:\\.|[^ )])+) ?(.*)$", s)
      if match is None:
          kwd = s
          rest = ""
      else:
          kwd, rest = match.groups()
      kwd = FilterPredicate.decode_symbol(kwd)
      if kwd == AND_PREDICATE.symbol:
          match = AND_PREDICATE
      elif kwd == OR_PREDICATE.symbol:
          match = OR_PREDICATE
      else:
          matches = [
              x for x in predicates if x is not list and x.symbol == kwd
          ]
          if len(matches) == 0:
              raise ValueError(
                  'The filter predicate, "%s", was not in the list of allowed predicates ("%s")'
                  % (kwd, '","'.join([x.symbol for x in predicates]))
              )
          match = matches[0]
      if match.subpredicates is list:
          predicates = [list] + predicates
      elif match.subpredicates is not None:
          predicates = match.subpredicates
      return match, rest, predicates
  
imports: import re
  from cellprofiler_core.setting import _setting
  from cellprofiler_core.setting._validation_error import ValidationError
  from ._compound_filter_predicate import CompoundFilterPredicate
  from ._filter_predicate import FilterPredicate
  from ._regexp_filter_predicate import RegexpFilterPredicate
label_desc: Use image node_id 6 for calling the Filter obj's underlying member method code with example usage: obj.parse_token(cls, s, predicates) and returns: match,  rest,  predicates, result,  s,  orig_predicates, result,  s,  orig_predicates, result,  s,  list