swim.recon.ReconParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swim-recon Show documentation
Show all versions of swim-recon Show documentation
Uploads all artifacts belonging to configuration ':swim-recon:archives'
// Copyright 2015-2019 SWIM.AI inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package swim.recon;
import java.math.BigInteger;
import swim.codec.Diagnostic;
import swim.codec.Input;
import swim.codec.Output;
import swim.codec.Parser;
import swim.codec.Unicode;
import swim.util.Builder;
/**
* Factory for constructing Recon parsers and parse trees.
*/
public abstract class ReconParser {
public abstract boolean isDistinct(V value);
public abstract I item(V value);
public abstract V value(I item);
public abstract I attr(V key, V value);
public abstract I attr(V key);
public abstract I slot(V key, V value);
public abstract I slot(V key);
public abstract Builder valueBuilder();
public abstract Builder recordBuilder();
public abstract Output dataOutput();
public abstract Output textOutput();
public abstract V ident(V value);
public abstract V num(int value);
public abstract V num(long value);
public abstract V num(float value);
public abstract V num(double value);
public abstract V num(BigInteger value);
public abstract V num(String value);
public abstract V uint32(int value);
public abstract V uint64(long value);
public abstract V bool(boolean value);
public abstract V selector();
public abstract V extant();
public abstract V absent();
public abstract V conditional(V ifTerm, V thenTerm, V elseTerm);
public abstract V or(V lhs, V rhs);
public abstract V and(V lhs, V rhs);
public abstract V bitwiseOr(V lhs, V rhs);
public abstract V bitwiseXor(V lhs, V rhs);
public abstract V bitwiseAnd(V lhs, V rhs);
public abstract V lt(V lhs, V rhs);
public abstract V le(V lhs, V rhs);
public abstract V eq(V lhs, V rhs);
public abstract V ne(V lhs, V rhs);
public abstract V ge(V lhs, V rhs);
public abstract V gt(V lhs, V rhs);
public abstract V plus(V lhs, V rhs);
public abstract V minus(V lhs, V rhs);
public abstract V times(V lhs, V rhs);
public abstract V divide(V lhs, V rhs);
public abstract V modulo(V lhs, V rhs);
public abstract V not(V rhs);
public abstract V bitwiseNot(V rhs);
public abstract V negative(V rhs);
public abstract V positive(V rhs);
public abstract V invoke(V func, V args);
public abstract V lambda(V bindings, V template);
public abstract V get(V selector, V key);
public abstract V getAttr(V selector, V key);
public abstract I getItem(V selector, V index);
public abstract V children(V selector);
public abstract V descendants(V selector);
public abstract V keys(V selector);
public abstract V values(V selector);
public abstract V filter(V selector, V predicate);
public Parser parseBlock(Input input) {
return BlockParser.parse(input, this);
}
public Parser parseAttr(Input input) {
return AttrParser.parse(input, this);
}
public Parser parseBlockItem(Input input) {
return BlockItemParser.parse(input, this);
}
public Parser parseInlineItem(Input input) {
return InlineItemParser.parse(input, this);
}
public Parser parseRecord(Input input, Builder builder) {
return RecordParser.parse(input, this, builder);
}
public Parser parseRecord(Input input) {
return RecordParser.parse(input, this);
}
public Parser parseMarkup(Input input, Builder builder) {
return MarkupParser.parse(input, this, builder);
}
public Parser parseMarkup(Input input) {
return MarkupParser.parse(input, this);
}
public Parser parseData(Input input) {
return DataParser.parse(input, this);
}
public Parser parseIdent(Input input) {
return IdentParser.parse(input, this);
}
public Parser parseString(Input input) {
return StringParser.parse(input, this);
}
public Parser parseNumber(Input input) {
return NumberParser.parse(input, this);
}
public Parser parseInteger(Input input) {
return NumberParser.parseInteger(input, this);
}
public Parser parseBlockExpression(Input input, Builder builder) {
return parseLambdaFunc(input, builder);
}
public Parser parseBlockExpression(Input input) {
return parseLambdaFunc(input, null);
}
public Parser parseLambdaFunc(Input input, Builder builder) {
return LambdaFuncParser.parse(input, this, builder);
}
public Parser parseConditionalOperator(Input input, Builder builder) {
return ConditionalOperatorParser.parse(input, this, builder);
}
public Parser parseOrOperator(Input input, Builder builder) {
return OrOperatorParser.parse(input, this, builder);
}
public Parser parseAndOperator(Input input, Builder builder) {
return AndOperatorParser.parse(input, this, builder);
}
public Parser parseBitwiseOrOperator(Input input, Builder builder) {
return BitwiseOrOperatorParser.parse(input, this, builder);
}
public Parser parseBitwiseXorOperator(Input input, Builder builder) {
return BitwiseXorOperatorParser.parse(input, this, builder);
}
public Parser parseBitwiseAndOperator(Input input, Builder builder) {
return BitwiseAndOperatorParser.parse(input, this, builder);
}
public Parser parseComparisonOperator(Input input, Builder builder) {
return ComparisonOperatorParser.parse(input, this, builder);
}
public Parser parseAttrExpression(Input input, Builder builder) {
return AttrExpressionParser.parse(input, this, builder);
}
public Parser parseAdditiveOperator(Input input, Builder builder) {
return AdditiveOperatorParser.parse(input, this, builder);
}
public Parser parseMultiplicativeOperator(Input input, Builder builder) {
return MultiplicativeOperatorParser.parse(input, this, builder);
}
public Parser parsePrefixOperator(Input input, Builder builder) {
return PrefixOperatorParser.parse(input, this, builder);
}
public Parser parseInvokeOperator(Input input, Builder builder) {
return InvokeOperatorParser.parse(input, this, builder);
}
public Parser parsePrimary(Input input, Builder builder) {
return PrimaryParser.parse(input, this, builder);
}
public Parser parseLiteral(Input input, Builder builder) {
return LiteralParser.parse(input, this, builder);
}
public Parser parseSelector(Input input, Builder builder) {
return SelectorParser.parse(input, this, builder);
}
public Parser parseSelector(Input input) {
return SelectorParser.parse(input, this, null);
}
public Parser blockParser() {
return new BlockParser(this);
}
public V parseBlockString(String string) {
Input input = Unicode.stringInput(string);
while (input.isCont() && Recon.isWhitespace(input.head())) {
input = input.step();
}
Parser parser = parseBlock(input);
if (parser.isDone()) {
while (input.isCont() && Recon.isWhitespace(input.head())) {
input = input.step();
}
}
if (input.isCont() && !parser.isError()) {
parser = Parser.error(Diagnostic.unexpected(input));
} else if (input.isError()) {
parser = Parser.error(input.trap());
}
return parser.bind();
}
public V parseNumberString(String string) {
Input input = Unicode.stringInput(string);
while (input.isCont() && Recon.isWhitespace(input.head())) {
input = input.step();
}
Parser parser = parseNumber(input);
if (parser.isDone()) {
while (input.isCont() && Recon.isWhitespace(input.head())) {
input = input.step();
}
}
if (input.isCont() && !parser.isError()) {
parser = Parser.error(Diagnostic.unexpected(input));
} else if (input.isError()) {
parser = Parser.error(input.trap());
}
return parser.bind();
}
}