Interface InvocationMatcher


public interface InvocationMatcher
A matcher against invocations of rules that knows how to process invocations and create RuleInvocations.

Primarily used in RelationCollectorListener to match invocations in the body of predicates.

Implementation notes

See the source; there are many un-exposed classes that implement matchers for all the operators described in the grammer (cf. invocationMatchers(edu.unc.cs.comp524.parsers.prolog.PrologParser, edu.unc.cs.comp524.parsers.prolog.PrologLexer)).

We use a custom ParseTreePatternMatcher with delimiters set by ParseTreePatternMatcher.setDelimiters(java.lang.String, java.lang.String, java.lang.String) to allow the use of slashes in the patterns.

The names of classes use a bit of shorthand:

  • C: colon (:)
  • H: hyphen (-)
  • Q: question mark (?)
  • SEMI: semi-colon (;)
  • BAR: bar or pipe (|)
  • HARROW: ->
  • S: star (*)
  • EQ: equals (=)
  • NOT: prolog's not (\+)
  • LT: less-than (<)
  • LEQ: less-than-equal (=<)
  • D: dot (.)
  • AT: aerobase (@)
  • GT: greater-than (>)
  • GEQ: greater-than-equal (>=)
  • NEQ: not-equal (\=)
  • AND: and (/\)
  • OR: or (\/)
  • SLASH: slash (/)
  • CARET: caret (^)
  • BSLASH: backslash (\)
  • DOLLAR: dollar-sign ($)

Most others that are not built from this shorthand are represented by name directly (e.g., MOD for mod, DYNAMIC for dynamic).

  • Method Summary

    Modifier and Type Method Description
    List<org.antlr.v4.runtime.tree.ParseTree> getArgs​(org.antlr.v4.runtime.tree.pattern.ParseTreeMatch m)
    Computes the arguments of the invocation given a ParseTreeMatch created from pattern().
    static List<InvocationMatcher> invocationMatchers​(PrologParser p, PrologLexer l)
    The default matchers for all operators defined in the grammar.
    default List<RuleInvocation> invocations​(org.antlr.v4.runtime.tree.ParseTree tree)
    Find all invocations in tree.
    default List<RuleInvocation> invocations​(org.antlr.v4.runtime.tree.ParseTree tree, String xpath)
    Find all invocations in tree that match xpath.
    String name()
    The name of the rule the invocation matches
    org.antlr.v4.runtime.tree.pattern.ParseTreePattern pattern()
    The pattern to be used to match with
  • Method Details

    • name

      String name()
      The name of the rule the invocation matches
    • getArgs

      List<org.antlr.v4.runtime.tree.ParseTree> getArgs​(org.antlr.v4.runtime.tree.pattern.ParseTreeMatch m)
      Computes the arguments of the invocation given a ParseTreeMatch created from pattern().
    • pattern

      org.antlr.v4.runtime.tree.pattern.ParseTreePattern pattern()
      The pattern to be used to match with
    • invocations

      default List<RuleInvocation> invocations​(org.antlr.v4.runtime.tree.ParseTree tree)
      Find all invocations in tree.

      The default implementation is equivalent to invocations(ParseTree, String)(tree, "//*").

    • invocations

      default List<RuleInvocation> invocations​(org.antlr.v4.runtime.tree.ParseTree tree, String xpath)
      Find all invocations in tree that match xpath.
      See Also:
      ParseTreePattern.findAll(org.antlr.v4.runtime.tree.ParseTree, java.lang.String)
    • invocationMatchers

      static List<InvocationMatcher> invocationMatchers​(PrologParser p, PrologLexer l)
      The default matchers for all operators defined in the grammar.

      See implementation notes above and the source for their definition.