dfh.treepath
Class MatchPath

java.lang.Object
  extended by dfh.treepath.Forester<N>
      extended by dfh.treepath.FunctionalForester<Match>
          extended by dfh.treepath.MatchPath
All Implemented Interfaces:
Serializable

public class MatchPath
extends FunctionalForester<Match>

A Forester adaptor for Match trees.

Author:
David F. Houghton - Apr 28, 2012
See Also:
Serialized Form

Field Summary
static NodeTest<Match> assertionNT
          NodeTest matching nodes generated by assertions.
static NodeTest<Match> barrierNT
          NodeTest matching nodes generated by backtracking barriers.
static NodeTest<Match> hiddenSpaceNT
          NodeTest matches whitespace nodes in rules such as
static NodeTest<Match> visibleSpaceNT
          NodeTest matching nodes generated by '.' in rules such as
static NodeTest<Match> whitespaceNT
          NodeTest matching nodes whose group contains only whitespace.
static NodeTest<Match> zeroNT
          NodeTest matching all zero-width nodes in the parse tree.
 
Fields inherited from class dfh.treepath.Forester
attributeCache, attributes, pathMt
 
Constructor Summary
MatchPath(NodeTest<Match>... ignore)
          Delegates to FunctionalForester.FunctionalForester(NodeTest...).
 
Method Summary
 boolean assertion(Match m, Collection<Match> c, Index<Match> i)
          Returns whether the match node was generated by an Assertion
protected  List<Match> children(Match n, Index<Match> i)
          Returns Match#children() as a list.
 boolean explicit(Match m, Collection<Match> c, Index<Match> i)
          Returns the match was generated by an explit rule.
 String group(Match m, Collection<Match> c, Index<Match> i)
          Returns Match#group().
protected  boolean hasTag(Match n, String tag)
          Calls Match#hasLabel(String).
 String label(Match m, Collection<Match> c, Index<Match> i)
          Returns the label of the Rule generating the Match.
 int length(Match m, Collection<Match> c, Index<Match> i)
          Calls Match#length().
static void main(String[] args)
          Prints out all attributes MatchPath can handle.
protected  boolean matchesTag(Match n, Pattern p)
          Calls Match#hasLabel(Pattern).
protected  Match parent(Match n, Index<Match> i)
          Calls Match#parent().
static MatchPath standard()
          Returns as a singleton instance a MatchPath Forester that will ignore all zero-width or whitespace nodes.
 boolean zero(Match m, Collection<Match> c, Index<Match> i)
          Returns {@link Match#length()} == 0.
 
Methods inherited from class dfh.treepath.FunctionalForester
abs, ceil, compare, concatenate, contains, defined, endsWith, find, floor, index, integralPortion, join, length, lookingAt, lowercase, matches, max, millis, min, normalizeWhitespace, product, replace, replaceAll, replaceFirst, round, startsWith, substring, sum, trim, ucFirst, uppercase
 
Methods inherited from class dfh.treepath.Forester
ancestors, attribToBoolean, attribute, attribute, attributes, axis, children, closest, depth, descendants, echo, False, following, followingSiblings, getAttributes, getLoggingStream, height, id, index, index, init, isLeaf, isRoot, kids, leaves, log, mixin, Null, path, pick, preceding, precedingSiblings, root, setLoggingStream, siblings, siblings, siblingsOrSelf, size, This, True, tsize, uid, width
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

zeroNT

public static final NodeTest<Match> zeroNT
NodeTest matching all zero-width nodes in the parse tree. This will exclude empty quantified lists, assertions, zero-width regular expressions, and so on.


whitespaceNT

public static final NodeTest<Match> whitespaceNT
NodeTest matching nodes whose group contains only whitespace.


barrierNT

public static final NodeTest<Match> barrierNT
NodeTest matching nodes generated by backtracking barriers. This is a subset of zero-width nodes.


assertionNT

public static final NodeTest<Match> assertionNT
NodeTest matching nodes generated by assertions. This is a subset of zero-width nodes. Note, this does not include regex assertions like (?=sue); these are only nodes generated by Assertion rules.


visibleSpaceNT

public static final NodeTest<Match> visibleSpaceNT
NodeTest matching nodes generated by '.' in rules such as
 rule := [ 'la' . ]+ 'di' 'da'
 
This is a subset whitespace nodes. This test will match faster than whitespaceNT because it doesn't require pattern matching.


hiddenSpaceNT

public static final NodeTest<Match> hiddenSpaceNT
NodeTest matches whitespace nodes in rules such as
 rule := 'la' 'di' 'da'
 
or
 rule .= 'la' 'di' 'da'
 
This is a subset whitespace nodes. This test will match faster than whitespaceNT because it doesn't require pattern matching.

Constructor Detail

MatchPath

public MatchPath(NodeTest<Match>... ignore)
Delegates to FunctionalForester.FunctionalForester(NodeTest...).

Parameters:
ignore - node types to ignore
Method Detail

standard

public static MatchPath standard()
Returns as a singleton instance a MatchPath Forester that will ignore all zero-width or whitespace nodes. This forester uses the visibleSpaceNT, hiddenSpaceNT, zeroNT, and whitespaceNT node tests to determine which nodes are ignorable. This gets rid of nodes generated by assertions, backtracking barriers, repeating patterns with zero repetitions, empty string literals, zero-width regular expressions -- more or less everything you likely want to ignore anyway.

Returns:
MatchPath forester that ignores zero-width and whitespace nodes

children

protected List<Match> children(Match n,
                               Index<Match> i)
Returns Match#children() as a list.

Specified by:
children in class Forester<Match>
Parameters:
n - context node
i - tree index
Returns:
the children of n

hasTag

protected boolean hasTag(Match n,
                         String tag)
Calls Match#hasLabel(String).

Specified by:
hasTag in class Forester<Match>
Parameters:
n - context node
tag - tag
Returns:
whether the node bears the given tag

matchesTag

protected boolean matchesTag(Match n,
                             Pattern p)
Calls Match#hasLabel(Pattern).

Specified by:
matchesTag in class Forester<Match>
Parameters:
n - context node
p - tag pattern
Returns:
whether the pattern matches the node's tag or tags

parent

protected Match parent(Match n,
                       Index<Match> i)
Calls Match#parent().

Specified by:
parent in class Forester<Match>
Parameters:
n - context node
i - tree index
Returns:
the parent of n

zero

@Attribute(description="whether node is zero-width")
public boolean zero(Match m,
                                         Collection<Match> c,
                                         Index<Match> i)
Returns {@link Match#length()} == 0.

Parameters:
m - context node
c - context collection; required by method signature but ignored
i - match tree index; required by method signature but ignored
Returns:
whether the length of the character sequence matched is zero

assertion

@Attribute(description="whether node is an assertion")
public boolean assertion(Match m,
                                              Collection<Match> c,
                                              Index<Match> i)
Returns whether the match node was generated by an Assertion

Parameters:
m - context node
c - context collection; required by method signature but ignored
i - match tree index; required by method signature but ignored
Returns:
whether the match node was generated by an Assertion

length

@Attribute(description="length of group matched")
public int length(Match m,
                                       Collection<Match> c,
                                       Index<Match> i)
Calls Match#length().

Parameters:
m - context node
c - context collection; required by method signature but ignored
i - match tree index; required by method signature but ignored
Returns:
the length of the character sequence matched

explicit

@Attribute(description="whether the rule generating this node is explicitly defined")
public boolean explicit(Match m,
                                             Collection<Match> c,
                                             Index<Match> i)
Returns the match was generated by an explit rule. This is a rule which has its own definition line and label in the grammar.

Parameters:
m - context node
c - context collection; required by method signature but ignored
i - match tree index; required by method signature but ignored
Returns:
whether the match is the result of an explicit rule

group

@Attribute(description="group matched")
public String group(Match m,
                                         Collection<Match> c,
                                         Index<Match> i)
Returns Match#group().

Parameters:
m - context node
c - context collection; required by method signature but ignored
i - match tree index; required by method signature but ignored
Returns:
the character sequence matched by the Match

label

@Attribute(description="rule generating match")
public String label(Match m,
                                         Collection<Match> c,
                                         Index<Match> i)
Returns the label of the Rule generating the Match. For example, if the match was generated by
 foo = [{quux} 'bar']
 
the value of this attribute will be "foo", though it also bears the label "quux".

Parameters:
m - context node
c - context collection; required by method signature but ignored
i - match tree index; required by method signature but ignored
Returns:
id of Rule generating the Match

main

public static void main(String[] args)
Prints out all attributes MatchPath can handle.

Parameters:
args -