private String toStringTree(@NotNull final Tree t, @Nullable final List<String> ruleNames) {
if (t.getChildCount() == 0) {
return Utils.escapeWhitespace(getNodeText(t, ruleNames), true);
}
StringBuilder buf = new StringBuilder();
buf.append(" ( ");
String s = Utils.escapeWhitespace(getNodeText(t, ruleNames), true);
buf.append(s);
buf.append(' ');
for (int i = 0; i < t.getChildCount(); i++) {
if (i > 0) {
buf.append(' ');
}
buf.append(toStringTree(t.getChild(i), ruleNames));
}
buf.append(" ) ");
return buf.toString();
}
java类org.antlr.v4.runtime.misc.Nullable的实例源码
ParseTreeCommand.java 文件源码
项目:antlr4ide
阅读 25
收藏 0
点赞 0
评论 0
ParseTreeCommand.java 文件源码
项目:antlr4ide
阅读 30
收藏 0
点赞 0
评论 0
private String getNodeText(@NotNull final Tree t, @Nullable final List<String> ruleNames) {
if (ruleNames != null) {
if (t instanceof RuleNode) {
int ruleIndex = ((RuleNode) t).getRuleContext().getRuleIndex();
String ruleName = ruleNames.get(ruleIndex);
return ruleName;
}
else if (t instanceof ErrorNode) {
return "<" + t.toString() + ">";
}
else if (t instanceof TerminalNode) {
Token symbol = ((TerminalNode) t).getSymbol();
if (symbol != null) {
String s = symbol.getText();
return "'" + s + "'";
}
}
}
// no recog for rule names
Object payload = t.getPayload();
if (payload instanceof Token) {
return ((Token) payload).getText();
}
return t.getPayload().toString();
}
RuleContext.java 文件源码
项目:Scratch-ApuC
阅读 29
收藏 0
点赞 0
评论 0
public String toString(@Nullable List<String> ruleNames, @Nullable RuleContext stop) {
StringBuilder buf = new StringBuilder();
RuleContext p = this;
buf.append("[");
while (p != null && p != stop) {
if (ruleNames == null) {
if (!p.isEmpty()) {
buf.append(p.invokingState);
}
}
else {
int ruleIndex = p.getRuleIndex();
String ruleName = ruleIndex >= 0 && ruleIndex < ruleNames.size() ? ruleNames.get(ruleIndex) : Integer.toString(ruleIndex);
buf.append(ruleName);
}
if (p.parent != null && (ruleNames != null || !p.parent.isEmpty())) {
buf.append(" ");
}
p = p.parent;
}
buf.append("]");
return buf.toString();
}
FailedPredicateException.java 文件源码
项目:Scratch-ApuC
阅读 24
收藏 0
点赞 0
评论 0
public FailedPredicateException(@NotNull Parser recognizer,
@Nullable String predicate,
@Nullable String message)
{
super(formatMessage(predicate, message), recognizer, recognizer.getInputStream(), recognizer._ctx);
ATNState s = recognizer.getInterpreter().atn.states.get(recognizer.getState());
AbstractPredicateTransition trans = (AbstractPredicateTransition)s.transition(0);
if (trans instanceof PredicateTransition) {
this.ruleIndex = ((PredicateTransition)trans).ruleIndex;
this.predicateIndex = ((PredicateTransition)trans).predIndex;
}
else {
this.ruleIndex = 0;
this.predicateIndex = 0;
}
this.predicate = predicate;
this.setOffendingToken(recognizer.getCurrentToken());
}
Trees.java 文件源码
项目:Scratch-ApuC
阅读 21
收藏 0
点赞 0
评论 0
/** Print out a whole tree in LISP form. {@link #getNodeText} is used on the
* node payloads to get the text for the nodes. Detect
* parse trees and extract data appropriately.
*/
public static String toStringTree(@NotNull Tree t, @Nullable List<String> ruleNames) {
String s = Utils.escapeWhitespace(getNodeText(t, ruleNames), false);
if ( t.getChildCount()==0 ) return s;
StringBuilder buf = new StringBuilder();
buf.append("(");
s = Utils.escapeWhitespace(getNodeText(t, ruleNames), false);
buf.append(s);
buf.append(' ');
for (int i = 0; i<t.getChildCount(); i++) {
if ( i>0 ) buf.append(' ');
buf.append(toStringTree(t.getChild(i), ruleNames));
}
buf.append(")");
return buf.toString();
}
Trees.java 文件源码
项目:Scratch-ApuC
阅读 24
收藏 0
点赞 0
评论 0
public static String getNodeText(@NotNull Tree t, @Nullable List<String> ruleNames) {
if ( ruleNames!=null ) {
if ( t instanceof RuleNode ) {
int ruleIndex = ((RuleNode)t).getRuleContext().getRuleIndex();
String ruleName = ruleNames.get(ruleIndex);
return ruleName;
}
else if ( t instanceof ErrorNode) {
return t.toString();
}
else if ( t instanceof TerminalNode) {
Token symbol = ((TerminalNode)t).getSymbol();
if (symbol != null) {
String s = symbol.getText();
return s;
}
}
}
// no recog for rule names
Object payload = t.getPayload();
if ( payload instanceof Token ) {
return ((Token)payload).getText();
}
return t.getPayload().toString();
}
ParseTreeMatch.java 文件源码
项目:Scratch-ApuC
阅读 20
收藏 0
点赞 0
评论 0
/**
* Constructs a new instance of {@link ParseTreeMatch} from the specified
* parse tree and pattern.
*
* @param tree The parse tree to match against the pattern.
* @param pattern The parse tree pattern.
* @param labels A mapping from label names to collections of
* {@link ParseTree} objects located by the tree pattern matching process.
* @param mismatchedNode The first node which failed to match the tree
* pattern during the matching process.
*
* @exception IllegalArgumentException if {@code tree} is {@code null}
* @exception IllegalArgumentException if {@code pattern} is {@code null}
* @exception IllegalArgumentException if {@code labels} is {@code null}
*/
public ParseTreeMatch(@NotNull ParseTree tree, @NotNull ParseTreePattern pattern, @NotNull MultiMap<String, ParseTree> labels, @Nullable ParseTree mismatchedNode) {
if (tree == null) {
throw new IllegalArgumentException("tree cannot be null");
}
if (pattern == null) {
throw new IllegalArgumentException("pattern cannot be null");
}
if (labels == null) {
throw new IllegalArgumentException("labels cannot be null");
}
this.tree = tree;
this.pattern = pattern;
this.labels = labels;
this.mismatchedNode = mismatchedNode;
}
ParserATNSimulator.java 文件源码
项目:Scratch-ApuC
阅读 25
收藏 0
点赞 0
评论 0
@NotNull
protected ATNConfigSet computeStartState(@NotNull ATNState p,
@Nullable RuleContext ctx,
boolean fullCtx)
{
// always at least the implicit call to start rule
PredictionContext initialContext = PredictionContext.fromRuleContext(atn, ctx);
ATNConfigSet configs = new ATNConfigSet(fullCtx);
for (int i=0; i<p.getNumberOfTransitions(); i++) {
ATNState target = p.transition(i).target;
ATNConfig c = new ATNConfig(target, i+1, initialContext);
Set<ATNConfig> closureBusy = new HashSet<ATNConfig>();
closure(c, configs, closureBusy, true, fullCtx, false);
}
return configs;
}
LL1Analyzer.java 文件源码
项目:Scratch-ApuC
阅读 22
收藏 0
点赞 0
评论 0
/**
* Calculates the SLL(1) expected lookahead set for each outgoing transition
* of an {@link ATNState}. The returned array has one element for each
* outgoing transition in {@code s}. If the closure from transition
* <em>i</em> leads to a semantic predicate before matching a symbol, the
* element at index <em>i</em> of the result will be {@code null}.
*
* @param s the ATN state
* @return the expected symbols for each outgoing transition of {@code s}.
*/
@Nullable
public IntervalSet[] getDecisionLookahead(@Nullable ATNState s) {
// System.out.println("LOOK("+s.stateNumber+")");
if ( s==null ) {
return null;
}
IntervalSet[] look = new IntervalSet[s.getNumberOfTransitions()];
for (int alt = 0; alt < s.getNumberOfTransitions(); alt++) {
look[alt] = new IntervalSet();
Set<ATNConfig> lookBusy = new HashSet<ATNConfig>();
boolean seeThruPreds = false; // fail to get lookahead upon pred
_LOOK(s.transition(alt).target, null, PredictionContext.EMPTY,
look[alt], lookBusy, new BitSet(), seeThruPreds, false);
// Wipe out lookahead for this alternative if we found nothing
// or we had a predicate when we !seeThruPreds
if ( look[alt].size()==0 || look[alt].contains(HIT_PRED) ) {
look[alt] = null;
}
}
return look;
}
ProfilingATNSimulator.java 文件源码
项目:Scratch-ApuC
阅读 23
收藏 0
点赞 0
评论 0
@Override
protected void reportAmbiguity(@NotNull DFA dfa, DFAState D, int startIndex, int stopIndex, boolean exact,
@Nullable BitSet ambigAlts, @NotNull ATNConfigSet configs)
{
int prediction;
if ( ambigAlts!=null ) {
prediction = ambigAlts.nextSetBit(0);
}
else {
prediction = configs.getAlts().nextSetBit(0);
}
if ( configs.fullCtx && prediction != conflictingAltResolvedBySLL ) {
// Even though this is an ambiguity we are reporting, we can
// still detect some context sensitivities. Both SLL and LL
// are showing a conflict, hence an ambiguity, but if they resolve
// to different minimum alternatives we have also identified a
// context sensitivity.
decisions[currentDecision].contextSensitivities.add(
new ContextSensitivityInfo(currentDecision, configs, _input, startIndex, stopIndex)
);
}
decisions[currentDecision].ambiguities.add(
new AmbiguityInfo(currentDecision, configs, _input, startIndex, stopIndex, configs.fullCtx)
);
super.reportAmbiguity(dfa, D, startIndex, stopIndex, exact, ambigAlts, configs);
}
GraphParser.java 文件源码
项目:digraph-parser
阅读 21
收藏 0
点赞 0
评论 0
public void syntaxError(@NotNull Recognizer<?, ?> recognizer,
@Nullable Object offendingSymbol, int line,
int charPositionInLine, @NotNull String msg,
@Nullable RecognitionException e)
{
mErrMsg = "at line " + line + ":" + charPositionInLine + " " + msg;
throw e;
}
GraphParser.java 文件源码
项目:digraph-parser
阅读 18
收藏 0
点赞 0
评论 0
@Override
public void reportAmbiguity(@NotNull Parser recognizer,
@NotNull DFA dfa,
int startIndex,
int stopIndex,
boolean exact,
@Nullable BitSet ambigAlts,
@NotNull ATNConfigSet configs)
{
}
GraphParser.java 文件源码
项目:digraph-parser
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void reportAttemptingFullContext(@NotNull Parser recognizer,
@NotNull DFA dfa,
int startIndex,
int stopIndex,
@Nullable BitSet conflictingAlts,
@NotNull ATNConfigSet configs)
{
}
OsiamAntlrErrorListener.java 文件源码
项目:resource-server
阅读 20
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
* <p/>
* The method is overridden to throw an exception if the parsed input has an invalid syntax.
*/
@Override
public void syntaxError(Recognizer<?, ?> recognizer, @Nullable Object offendingSymbol, int line,
int charPositionInLine, String msg, @Nullable RecognitionException e) {
String errorMessage = msg;
if (e instanceof InputMismatchException && msg.endsWith(" expecting VALUE")) {
errorMessage += ". Please make sure that all values are surrounded by double quotes.";
}
throw new IllegalArgumentException(errorMessage);
}
Node.java 文件源码
项目:myne
阅读 25
收藏 0
点赞 0
评论 0
private static String getNodeText(@NotNull Tree t, @Nullable List<String> ruleNames, @Nullable List<String> tokenNames) {
if (t instanceof RuleNode) {
int ruleIndex = ((RuleNode) t).getRuleContext().getRuleIndex();
return ruleNames.get(ruleIndex);
}
if (t instanceof ErrorNode) {
return t.toString();
}
if (t instanceof TerminalNode) {
Token symbol = ((TerminalNode) t).getSymbol();
if (symbol != null) {
return tokenNames.get(symbol.getType());
}
}
// no recog for rule names
Object payload = t.getPayload();
if (payload instanceof Token) {
return ((Token) payload).getText();
}
return t.getPayload().toString();
}
RuleContext.java 文件源码
项目:Scratch-ApuC
阅读 26
收藏 0
点赞 0
评论 0
/** Save this tree in a postscript file */
public void save(@Nullable Parser parser, String fileName)
throws IOException, PrintException
{
List<String> ruleNames = parser != null ? Arrays.asList(parser.getRuleNames()) : null;
save(ruleNames, fileName);
}
Trees.java 文件源码
项目:Scratch-ApuC
阅读 25
收藏 0
点赞 0
评论 0
public static String getPS(Tree t, @Nullable List<String> ruleNames,
String fontName, int fontSize)
{
TreePostScriptGenerator psgen =
new TreePostScriptGenerator(ruleNames, t, fontName, fontSize);
return psgen.getPS();
}
Trees.java 文件源码
项目:Scratch-ApuC
阅读 26
收藏 0
点赞 0
评论 0
public static void writePS(Tree t, @Nullable List<String> ruleNames,
String fileName,
String fontName, int fontSize)
throws IOException
{
String ps = getPS(t, ruleNames, fontName, fontSize);
FileWriter f = new FileWriter(fileName);
BufferedWriter bw = new BufferedWriter(f);
try {
bw.write(ps);
}
finally {
bw.close();
}
}
TreePostScriptGenerator.java 文件源码
项目:Scratch-ApuC
阅读 24
收藏 0
点赞 0
评论 0
public TreePostScriptGenerator(@Nullable List<String> ruleNames, Tree root,
String fontName, int fontSize)
{
this.root = root;
setTreeTextProvider(new TreeViewer.DefaultTreeTextProvider(ruleNames));
doc = new PostScriptDocument(fontName, fontSize);
boolean compareNodeIdentities = true;
this.treeLayout =
new TreeLayout<Tree>(new TreeLayoutAdaptor(root),
new VariableExtentProvide(),
new DefaultConfiguration<Tree>(gapBetweenLevels,
gapBetweenNodes,
Configuration.Location.Bottom),
compareNodeIdentities);
}
FailedPredicateException.java 文件源码
项目:Scratch-ApuC
阅读 23
收藏 0
点赞 0
评论 0
@NotNull
private static String formatMessage(@Nullable String predicate, @Nullable String message) {
if (message != null) {
return message;
}
return String.format(Locale.getDefault(), "failed predicate: {%s}?", predicate);
}
LexerNoViableAltException.java 文件源码
项目:Scratch-ApuC
阅读 22
收藏 0
点赞 0
评论 0
public LexerNoViableAltException(@Nullable Lexer lexer,
@NotNull CharStream input,
int startIndex,
@Nullable ATNConfigSet deadEndConfigs) {
super(lexer, input, null);
this.startIndex = startIndex;
this.deadEndConfigs = deadEndConfigs;
}
ProxyErrorListener.java 文件源码
项目:Scratch-ApuC
阅读 24
收藏 0
点赞 0
评论 0
@Override
public void reportAmbiguity(@NotNull Parser recognizer,
@NotNull DFA dfa,
int startIndex,
int stopIndex,
boolean exact,
@Nullable BitSet ambigAlts,
@NotNull ATNConfigSet configs)
{
for (ANTLRErrorListener listener : delegates) {
listener.reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs);
}
}
ProxyErrorListener.java 文件源码
项目:Scratch-ApuC
阅读 26
收藏 0
点赞 0
评论 0
@Override
public void reportAttemptingFullContext(@NotNull Parser recognizer,
@NotNull DFA dfa,
int startIndex,
int stopIndex,
@Nullable BitSet conflictingAlts,
@NotNull ATNConfigSet configs)
{
for (ANTLRErrorListener listener : delegates) {
listener.reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs);
}
}
NoViableAltException.java 文件源码
项目:Scratch-ApuC
阅读 24
收藏 0
点赞 0
评论 0
public NoViableAltException(@NotNull Parser recognizer,
@NotNull TokenStream input,
@NotNull Token startToken,
@NotNull Token offendingToken,
@Nullable ATNConfigSet deadEndConfigs,
@NotNull ParserRuleContext ctx)
{
super(recognizer, input, ctx);
this.deadEndConfigs = deadEndConfigs;
this.startToken = startToken;
this.setOffendingToken(offendingToken);
}
BaseErrorListener.java 文件源码
项目:Scratch-ApuC
阅读 22
收藏 0
点赞 0
评论 0
@Override
public void syntaxError(@NotNull Recognizer<?, ?> recognizer,
@Nullable Object offendingSymbol,
int line,
int charPositionInLine,
@NotNull String msg,
@Nullable RecognitionException e)
{
}
BaseErrorListener.java 文件源码
项目:Scratch-ApuC
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void reportAmbiguity(@NotNull Parser recognizer,
@NotNull DFA dfa,
int startIndex,
int stopIndex,
boolean exact,
@Nullable BitSet ambigAlts,
@NotNull ATNConfigSet configs)
{
}
RecognitionException.java 文件源码
项目:Scratch-ApuC
阅读 19
收藏 0
点赞 0
评论 0
public RecognitionException(@Nullable Recognizer<?, ?> recognizer,
@Nullable IntStream input,
@Nullable ParserRuleContext ctx)
{
this.recognizer = recognizer;
this.input = input;
this.ctx = ctx;
if ( recognizer!=null ) this.offendingState = recognizer.getState();
}
RuleContext.java 文件源码
项目:Scratch-ApuC
阅读 33
收藏 0
点赞 0
评论 0
/** Save this tree in a postscript file using a particular font name and size */
public void save(@Nullable List<String> ruleNames, String fileName,
String fontName, int fontSize)
throws IOException
{
Trees.writePS(this, ruleNames, fileName, fontName, fontSize);
}
AbstractMetrics.java 文件源码
项目:pinot
阅读 21
收藏 0
点赞 0
评论 0
/**
* Builds a complete metric name, of the form prefix.resource.metric
*
* @param request The broker request containing all the information
* @param metricName The metric name to register
* @return The complete metric name
*/
private String buildMetricName(@Nullable BrokerRequest request, String metricName) {
if (request != null && request.getQuerySource() != null && request.getQuerySource().getTableName() != null) {
return _metricPrefix + getTableName(request.getQuerySource().getTableName()) + "." + metricName;
} else {
return _metricPrefix + "unknown." + metricName;
}
}
DiagnosticErrorListener.java 文件源码
项目:Scratch-ApuC
阅读 23
收藏 0
点赞 0
评论 0
@Override
public void reportAttemptingFullContext(@NotNull Parser recognizer,
@NotNull DFA dfa,
int startIndex,
int stopIndex,
@Nullable BitSet conflictingAlts,
@NotNull ATNConfigSet configs)
{
String format = "reportAttemptingFullContext d=%s, input='%s'";
String decision = getDecisionDescription(recognizer, dfa);
String text = recognizer.getTokenStream().getText(Interval.of(startIndex, stopIndex));
String message = String.format(format, decision, text);
recognizer.notifyErrorListeners(message);
}