/** * This visitor methods extracts the list of booleans specified. It creates a token * type <code>BoolList</code> to be added to <code>TokenGroup</code>. */ @Override public RecipeSymbol.Builder visitBoolList(DirectivesParser.BoolListContext ctx) { List<TerminalNode> bools = ctx.Bool(); List<Boolean> booleans = new ArrayList<>(); for (TerminalNode bool : bools) { booleans.add(Boolean.parseBoolean(bool.getText())); } builder.addToken(new BoolList(booleans)); return builder; }
/** * This visitor methods extracts the list of columns specified. It creates a token * type <code>ColumnNameList</code> to be added to <code>TokenGroup</code>. */ @Override public RecipeSymbol.Builder visitColList(DirectivesParser.ColListContext ctx) { List<TerminalNode> columns = ctx.Column(); List<String> names = new ArrayList<>(); for (TerminalNode column : columns) { names.add(column.getText().substring(1)); } builder.addToken(new ColumnNameList(names)); return builder; }
/** * A Directive can include a expression or a condition to be evaluated. When * such a token type is found, the visitor extracts the expression and generates * a token type <code>Expression</code> to be added to the <code>TokenGroup</code> */ @Override public RecipeSymbol.Builder visitCondition(DirectivesParser.ConditionContext ctx) { int childCount = ctx.getChildCount(); StringBuilder sb = new StringBuilder(); for (int i = 1; i < childCount - 1; ++i) { ParseTree child = ctx.getChild(i); sb.append(child.getText()).append(" "); } builder.addToken(new Expression(sb.toString())); return builder; }
/** * A Directive can include number ranges like start:end=value[,start:end=value]*. This * visitor method allows you to collect all the number ranges and create a token type * <code>Ranges</code>. */ @Override public RecipeSymbol.Builder visitNumberRanges(DirectivesParser.NumberRangesContext ctx) { List<Triplet<Numeric, Numeric,String>> output = new ArrayList<>(); List<DirectivesParser.NumberRangeContext> ranges = ctx.numberRange(); for(DirectivesParser.NumberRangeContext range : ranges) { List<TerminalNode> numbers = range.Number(); String text = range.value().getText(); if (text.startsWith("'") && text.endsWith("'")) { text = text.substring(1, text.length() - 1); } Triplet<Numeric, Numeric, String> val = new Triplet<>(new Numeric(new LazyNumber(numbers.get(0).getText())), new Numeric(new LazyNumber(numbers.get(1).getText())), text ); output.add(val); } builder.addToken(new Ranges(output)); return builder; }
/** * A Directive can include properties (which are a collection of key and value pairs), * this method extracts that token that is being identified as token of type <code>Properties</code>. */ @Override public RecipeSymbol.Builder visitPropertyList(DirectivesParser.PropertyListContext ctx) { Map<String, Token> props = new HashMap<>(); List<DirectivesParser.PropertyContext> properties = ctx.property(); for(DirectivesParser.PropertyContext property : properties) { String identifier = property.Identifier().getText(); Token token; if (property.number() != null) { token = new Numeric(new LazyNumber(property.number().getText())); } else if (property.bool() != null) { token = new Bool(Boolean.valueOf(property.bool().getText())); } else { String text = property.text().getText(); token = new Text(text.substring(1, text.length()-1)); } props.put(identifier, token); } builder.addToken(new Properties(props)); return builder; }
/** * This visitor methods extracts the list of numeric specified. It creates a token * type <code>NumericList</code> to be added to <code>TokenGroup</code>. */ @Override public RecipeSymbol.Builder visitNumberList(DirectivesParser.NumberListContext ctx) { List<TerminalNode> numbers = ctx.Number(); List<LazyNumber> numerics = new ArrayList<>(); for (TerminalNode number : numbers) { numerics.add(new LazyNumber(number.getText())); } builder.addToken(new NumericList(numerics)); return builder; }
/** * This visitor methods extracts the list of strings specified. It creates a token * type <code>StringList</code> to be added to <code>TokenGroup</code>. */ @Override public RecipeSymbol.Builder visitStringList(DirectivesParser.StringListContext ctx) { List<TerminalNode> strings = ctx.String(); List<String> strs = new ArrayList<>(); for (TerminalNode string : strings) { strs.add(string.getText()); } builder.addToken(new TextList(strs)); return builder; }
/** * A Directive can consist of numeric field. This visitor method extracts the * numeric value <code>Numeric</code>. */ @Override public RecipeSymbol.Builder visitNumber(DirectivesParser.NumberContext ctx) { LazyNumber number = new LazyNumber(ctx.Number().getText()); builder.addToken(new Numeric(number)); return builder; }
/** * A Directive can consist of text field. These type of fields are enclosed within * a single-quote or a double-quote. This visitor method extracts the string value * within the quotes and creates a token type <code>Text</code>. */ @Override public RecipeSymbol.Builder visitText(DirectivesParser.TextContext ctx) { String value = ctx.String().getText(); builder.addToken(new Text(value.substring(1, value.length()-1))); return builder; }
/** * A Directive can include identifiers, this method extracts that token that is being * identified as token of type <code>Identifier</code>. */ @Override public RecipeSymbol.Builder visitIdentifier(DirectivesParser.IdentifierContext ctx) { builder.addToken(new Identifier(ctx.Identifier().getText())); return super.visitIdentifier(ctx); }
/** * A Directive can consist of column specifiers. These are columns that the directive * would operate on. When a token of type column is visited, it would generate a token * type of type <code>ColumnName</code>. */ @Override public RecipeSymbol.Builder visitColumn(DirectivesParser.ColumnContext ctx) { builder.addToken(new ColumnName(ctx.Column().getText().substring(1))); return builder; }
/** * A Directive can consist of Bool field. The Bool field is represented as * either true or false. This visitor method extract the bool value into a * token type <code>Bool</code>. */ @Override public RecipeSymbol.Builder visitBool(DirectivesParser.BoolContext ctx) { builder.addToken(new Bool(Boolean.valueOf(ctx.Bool().getText()))); return builder; }
/** * This visitor method extracts the custom directive name specified. The custom * directives are specified with a bang (!) at the start. */ @Override public RecipeSymbol.Builder visitEcommand(DirectivesParser.EcommandContext ctx) { builder.addToken(new DirectiveName(ctx.Identifier().getText())); return builder; }
/** * A Directive has name and in the parsing context it's called a command. * This visitor methods extracts the command and creates a toke type <code>DirectiveName</code> */ @Override public RecipeSymbol.Builder visitCommand(DirectivesParser.CommandContext ctx) { builder.addToken(new DirectiveName(ctx.Identifier().getText())); return builder; }