org.jsimpledb.parse.CompositeIndexParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsimpledb-parse Show documentation
Show all versions of jsimpledb-parse Show documentation
JSimpleDB classes for parsing Java expressions.
The newest version!
/*
* Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
*/
package org.jsimpledb.parse;
import java.util.SortedMap;
import java.util.regex.Matcher;
import org.jsimpledb.core.CompositeIndex;
import org.jsimpledb.core.ObjType;
import org.jsimpledb.util.ParseContext;
/**
* Parses a composite index.
*
*
* Syntax examples:
*
* Person.byLastFirst
* Person.mycompositeindex
*
*/
public class CompositeIndexParser implements Parser {
private final SpaceParser spaceParser = new SpaceParser();
@Override
public CompositeIndex parse(final ParseSession session, final ParseContext ctx, final boolean complete) {
// Get object type
final ObjType objType = new ObjTypeParser().parse(session, ctx, complete);
// Get composite index name and resolve index
ctx.skipWhitespace();
if (!ctx.tryLiteral("."))
throw new ParseException(ctx, "expected composite index name").addCompletion(".");
ctx.skipWhitespace();
final SortedMap indexMap = objType.getCompositeIndexesByName();
final Matcher nameMatcher = ctx.tryPattern("\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*");
if (nameMatcher == null)
throw new ParseException(ctx, "expected composite index name").addCompletions(indexMap.keySet());
final String indexName = nameMatcher.group();
final CompositeIndex index = indexMap.get(indexName);
if (index == null) {
throw new ParseException(ctx, "unknown composite index `" + indexName + "' on " + objType)
.addCompletions(ParseUtil.complete(indexMap.keySet(), indexName));
}
// Done
return index;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy