Skip to content

Commit

Permalink
bring rule names in line with grammar documentation (#3377)
Browse files Browse the repository at this point in the history
* bring rule names in line with grammar documentation
  • Loading branch information
ratulm authored and dhalperi committed Mar 12, 2019
1 parent 85a8e72 commit 2371e4f
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

/** Contains information on various expressions supported by this package */
public enum Grammar {
FILTER_SPECIFIER("filterSpecifier", Parser.INSTANCE.FilterExpression(), "filter-specifier"),
INTERFACE_SPECIFIER(
"interfaceSpecifier", Parser.INSTANCE.InterfaceExpression(), "interface-specifier"),
IP_SPACE_SPECIFIER("ipSpecifier", Parser.INSTANCE.IpSpaceExpression(), "ip-specifier"),
LOCATION_SPECIFIER(
"locationSpecifier", Parser.INSTANCE.LocationExpression(), "location-specifier"),
NODE_SPECIFIER("nodeSpecifier", Parser.INSTANCE.NodeExpression(), "node-specifier");
FILTER_SPECIFIER("filterSpecifier", Parser.INSTANCE.FilterSpec(), "filter-specifier"),
INTERFACE_SPECIFIER("interfaceSpecifier", Parser.INSTANCE.InterfaceSpec(), "interface-specifier"),
IP_SPACE_SPECIFIER("ipSpecifier", Parser.INSTANCE.IpSpaceSpec(), "ip-specifier"),
LOCATION_SPECIFIER("locationSpecifier", Parser.INSTANCE.LocationSpec(), "location-specifier"),
NODE_SPECIFIER("nodeSpecifier", Parser.INSTANCE.NodeSpec(), "node-specifier");

static final String BASE_URL =
"https://github.com/batfish/batfish/blob/master/questions/Parameters.md#";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import org.parboiled.parserunners.ReportingParseRunner;
import org.parboiled.support.ParsingResult;

/**
* An {@link FilterSpecifierFactory} whose grammar is encoded in {@link Parser#FilterExpression()}
*/
/** An {@link FilterSpecifierFactory} whose grammar is encoded in {@link Parser#FilterSpec()} */
@AutoService(FilterSpecifierFactory.class)
public class ParboiledFilterSpecifierFactory implements FilterSpecifierFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import org.parboiled.support.ParsingResult;

/**
* An {@link InterfaceSpecifierFactory} whose grammar is encoded in {@link
* Parser#InterfaceExpression()}
* An {@link InterfaceSpecifierFactory} whose grammar is encoded in {@link Parser#InterfaceSpec()}
*/
@AutoService(InterfaceSpecifierFactory.class)
public class ParboiledInterfaceSpecifierFactory implements InterfaceSpecifierFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.parboiled.parserunners.ReportingParseRunner;
import org.parboiled.support.ParsingResult;

/** An IpSpaceSpecifierFactory whose grammar is encoded in {@link Parser#IpSpaceExpression()} */
/** An IpSpaceSpecifierFactory whose grammar is encoded in {@link Parser#IpSpaceSpec()} */
@AutoService(IpSpaceSpecifierFactory.class)
public class ParboiledIpSpaceSpecifierFactory implements IpSpaceSpecifierFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import org.parboiled.parserunners.ReportingParseRunner;
import org.parboiled.support.ParsingResult;

/**
* An {@link LocationSpecifierFactory} whose grammar is encoded in {@link
* Parser#LocationExpression()}
*/
/** An {@link LocationSpecifierFactory} whose grammar is encoded in {@link Parser#LocationSpec()} */
@AutoService(LocationSpecifierFactory.class)
public class ParboiledLocationSpecifierFactory implements LocationSpecifierFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.parboiled.parserunners.ReportingParseRunner;
import org.parboiled.support.ParsingResult;

/** An {@link NodeSpecifierFactory} whose grammar is encoded in {@link Parser#NodeExpression()} */
/** An {@link NodeSpecifierFactory} whose grammar is encoded in {@link Parser#NodeSpec()} */
@AutoService(NodeSpecifierFactory.class)
public class ParboiledNodeSpecifierFactory implements NodeSpecifierFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ public class Parser extends CommonParser {
* Filter grammar
*
* <pre>
* filterExpr := filterTerm [{@literal &} | , | \ filterTerm]*
* filterSpec := filterTerm [{@literal &} | , | \ filterTerm]*
*
* filterTerm := @in(interfaceExpr) // inFilterOf is also supported for back compat
* | @out(interfaceExpr) // outFilterOf is also supported
* filterTerm := @in(interfaceSpec) // inFilterOf is also supported for back compat
* | @out(interfaceSpec) // outFilterOf is also supported
* | filterName
* | filterNameRegex
* | ( filterTerm )
* </pre>
*/

/* A Filter expression is one or more intersection terms separated by , or \ */
public Rule FilterExpression() {
public Rule FilterSpec() {
Var<Character> op = new Var<>();
return Sequence(
FilterIntersection(),
Expand Down Expand Up @@ -109,7 +109,7 @@ public Rule FilterDirection() {
direction.set(match()),
WhiteSpace(),
"( ",
InterfaceExpression(),
InterfaceSpec(),
WhiteSpace(),
") ",
push(DirectionFilterAstNode.create(direction.get(), pop())));
Expand All @@ -123,7 +123,7 @@ public Rule FilterDirectionDeprecated() {
direction.set(match()),
WhiteSpace(),
"( ",
InterfaceExpression(),
InterfaceSpec(),
WhiteSpace(),
") ",
push(DirectionFilterAstNode.create(direction.get(), pop())));
Expand All @@ -146,16 +146,16 @@ public Rule FilterNameRegexDeprecated() {

public Rule FilterParens() {
// Leave the stack as is -- no need to remember that this was a parenthetical term
return Sequence("( ", FilterExpression(), WhiteSpace(), ") ");
return Sequence("( ", FilterSpec(), WhiteSpace(), ") ");
}

/**
* Interface grammar
*
* <pre>
* interfaceExpr := interfaceTerm [{@literal &} | , | \ interfaceTerm]*
* interfaceSpec := interfaceTerm [{@literal &} | , | \ interfaceTerm]*
*
* interfaceTerm := @connectedTo(ipSpaceExpr) // non-@ versions also supported for back compat
* interfaceTerm := @connectedTo(ipSpaceSpec) // non-@ versions also supported for back compat
* | @interfacegroup(a, b)
* | @interfaceType(interfaceType)
* | @vrf(vrfName)
Expand All @@ -167,7 +167,7 @@ public Rule FilterParens() {
*/

/* An Interface expression is union and difference of one or more intersections */
public Rule InterfaceExpression() {
public Rule InterfaceSpec() {
Var<Character> op = new Var<>();
return Sequence(
InterfaceIntersection(),
Expand All @@ -193,7 +193,7 @@ public Rule InterfaceIntersection() {

public Rule InterfaceTerm() {
return FirstOf(
InterfaceSpecifier(),
InterfaceFunc(),
InterfaceNameRegexDeprecated(),
InterfaceNameRegex(),
InterfaceName(),
Expand All @@ -203,7 +203,7 @@ public Rule InterfaceTerm() {
/**
* To avoid ambiguity in location specification, interface and node specifiers should be distinct
*/
public Rule InterfaceSpecifier() {
public Rule InterfaceFunc() {
return FirstOf(
InterfaceConnectedTo(),
InterfaceConnectedToDeprecated(),
Expand All @@ -222,7 +222,7 @@ public Rule InterfaceConnectedTo() {
IgnoreCase("@connectedTo"),
WhiteSpace(),
"( ",
IpSpaceExpression(),
IpSpaceSpec(),
WhiteSpace(),
") ",
push(new ConnectedToInterfaceAstNode(pop())));
Expand All @@ -234,7 +234,7 @@ public Rule InterfaceConnectedToDeprecated() {
IgnoreCase("connectedTo"),
WhiteSpace(),
"( ",
IpSpaceExpression(),
IpSpaceSpec(),
WhiteSpace(),
") ",
push(new ConnectedToInterfaceAstNode(pop())));
Expand Down Expand Up @@ -279,7 +279,7 @@ public Rule InterfaceType() {
IgnoreCase("@interfaceType"),
WhiteSpace(),
"( ",
InterfaceTypeExpr(),
InterfaceTypeSpec(),
WhiteSpace(),
") ",
push(new TypeInterfaceAstNode(pop())));
Expand All @@ -291,14 +291,14 @@ public Rule InterfaceTypeDeprecated() {
IgnoreCase("type"),
WhiteSpace(),
"( ",
InterfaceTypeExpr(),
InterfaceTypeSpec(),
WhiteSpace(),
") ",
push(new TypeInterfaceAstNode(pop())));
}

@Anchor(INTERFACE_TYPE)
public Rule InterfaceTypeExpr() {
public Rule InterfaceTypeSpec() {
return Sequence(FirstOf(_interfaceTypeRules), push(new StringAstNode(match())));
}

Expand Down Expand Up @@ -375,7 +375,7 @@ public Rule InterfaceNameRegexDeprecated() {

public Rule InterfaceParens() {
// Leave the stack as is -- no need to remember that this was a parenthetical term
return Sequence("( ", InterfaceExpression(), WhiteSpace(), ") ");
return Sequence("( ", InterfaceSpec(), WhiteSpace(), ") ");
}

/**
Expand All @@ -385,8 +385,8 @@ public Rule InterfaceParens() {
* ipSpaceSpec := ipSpecTerm [, ipSpecTerm]*
*
* ipSpecTerm := @addgressgroup(groupname, bookname) //ref.addressgroup for back compat
* | locationExpr
* | ofLocation(locationExpr) // back compat
* | locationSpec
* | ofLocation(locationSpec) // back compat
* | ipPrefix (e.g., 1.1.1.0/24)
* | ipWildcard (e.g., 1.1.1.1:255.255.255.0)
* | ipRange (e.g., 1.1.1.1-1.1.1.2)
Expand All @@ -395,7 +395,7 @@ public Rule InterfaceParens() {
*/

/* An IpSpace expression is a comma-separated list of IpSpaceTerms */
public Rule IpSpaceExpression() {
public Rule IpSpaceSpec() {
return Sequence(
IpSpaceTerm(),
WhiteSpace(),
Expand Down Expand Up @@ -451,7 +451,7 @@ public Rule AddressGroupAndBook() {
}

public Rule IpSpaceLocation() {
return Sequence(LocationExpression(), push(new LocationIpSpaceAstNode(pop())));
return Sequence(LocationSpec(), push(new LocationIpSpaceAstNode(pop())));
}

@Anchor(IGNORE)
Expand All @@ -460,7 +460,7 @@ public Rule IpSpaceLocationDeprecated() {
IgnoreCase("ofLocation"),
WhiteSpace(),
"( ",
LocationExpression(),
LocationSpec(),
WhiteSpace(),
") ",
push(new LocationIpSpaceAstNode(pop())));
Expand Down Expand Up @@ -515,7 +515,7 @@ public Rule IpWildcard() {
* Location grammar
*
* <pre>
* locationExpr := locationTerm [{@literal &} | , | \ locationTerm]*
* locationSpec := locationTerm [{@literal &} | , | \ locationTerm]*
*
* locationTerm := locationInterface
* | @enter(locationInterface) // non-@ versions also supported
Expand All @@ -524,12 +524,12 @@ public Rule IpWildcard() {
*
* locationInterface := nodeTerm[interfaceTerm]
* | nodeTerm
* | interfaceSpecifier
* | interfaceFunc
* </pre>
*/

/* A Node expression is one or more intersection terms separated by + or - */
public Rule LocationExpression() {
public Rule LocationSpec() {
Var<Character> op = new Var<>();
return Sequence(
LocationIntersection(),
Expand Down Expand Up @@ -589,13 +589,13 @@ public Rule LocationInterface() {
NodeTerm(),
WhiteSpace(),
"[ ",
InterfaceExpression(),
InterfaceSpec(),
WhiteSpace(),
"] ",
push(InterfaceLocationAstNode.createFromNodeInterface(pop(1), pop()))),
Sequence(NodeTerm(), WhiteSpace(), push(InterfaceLocationAstNode.createFromNode(pop()))),
Sequence(
InterfaceSpecifier(),
InterfaceFunc(),
WhiteSpace(),
push(InterfaceLocationAstNode.createFromInterface(pop()))));
}
Expand All @@ -605,22 +605,22 @@ public Rule LocationInterfaceDeprecated() {
return Sequence(
// brackets without node expression
"[ ",
InterfaceExpression(),
InterfaceSpec(),
WhiteSpace(),
"] ",
push(InterfaceLocationAstNode.createFromInterface(pop())));
}

public Rule LocationParens() {
// Leave the stack as is -- no need to remember that this was a parenthetical term
return Sequence("( ", LocationExpression(), WhiteSpace(), ") ");
return Sequence("( ", LocationSpec(), WhiteSpace(), ") ");
}

/**
* Node grammar
*
* <pre>
* nodeExpr := nodeTerm [{@literal &} | , | \ nodeTerm]*
* nodeSpec := nodeTerm [{@literal &} | , | \ nodeTerm]*
*
* nodeTerm := @role(a, b) // ref.noderole is also supported for back compat
* | @deviceType(a)
Expand All @@ -631,7 +631,7 @@ public Rule LocationParens() {
*/

/* A Node expression is one or more intersection terms separated by + or - */
public Rule NodeExpression() {
public Rule NodeSpec() {
Var<Character> op = new Var<>();
return Sequence(
NodeIntersection(),
Expand Down Expand Up @@ -702,14 +702,14 @@ public Rule NodeType() {
IgnoreCase("@deviceType"),
WhiteSpace(),
"( ",
NodeTypeExpr(),
NodeTypeSpec(),
WhiteSpace(),
") ",
push(new TypeNodeAstNode(pop())));
}

@Anchor(NODE_TYPE)
public Rule NodeTypeExpr() {
public Rule NodeTypeSpec() {
return Sequence(FirstOf(_deviceTypeRules), push(new StringAstNode(match())));
}

Expand All @@ -730,6 +730,6 @@ public Rule NodeNameRegexDeprecated() {

public Rule NodeParens() {
// Leave the stack as is -- no need to remember that this was a parenthetical term
return Sequence("( ", NodeExpression(), WhiteSpace(), ") ");
return Sequence("( ", NodeSpec(), WhiteSpace(), ") ");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ParserFilterTest {
@Rule public ExpectedException _thrown = ExpectedException.none();

private static AbstractParseRunner<AstNode> getRunner() {
return new ReportingParseRunner<>(Parser.INSTANCE.input(Parser.INSTANCE.FilterExpression()));
return new ReportingParseRunner<>(Parser.INSTANCE.input(Parser.INSTANCE.FilterSpec()));
}

/** This testParses if we have proper completion annotations on the rules */
Expand All @@ -44,7 +44,7 @@ public void testCompletionEmpty() {
ParboiledAutoComplete pac =
new ParboiledAutoComplete(
Parser.INSTANCE,
Parser.INSTANCE.input(Parser.INSTANCE.FilterExpression()),
Parser.INSTANCE.input(Parser.INSTANCE.FilterSpec()),
Parser.ANCHORS,
"network",
"snapshot",
Expand Down Expand Up @@ -78,7 +78,7 @@ public void testCompletionPartialName() {
ParboiledAutoComplete pac =
new ParboiledAutoComplete(
Parser.INSTANCE,
Parser.INSTANCE.input(Parser.INSTANCE.FilterExpression()),
Parser.INSTANCE.input(Parser.INSTANCE.FilterSpec()),
Parser.ANCHORS,
"network",
"snapshot",
Expand Down

0 comments on commit 2371e4f

Please sign in to comment.