@Override public Map<RuleContext, CaretReachedException> getParseTrees(TParser parser) { List<MultipleDecisionData> potentialAlternatives = new ArrayList<>(); IntegerList currentPath = new IntegerList(); Map<RuleContext, CaretReachedException> results = new IdentityHashMap<>(); // make sure the token stream is initialized before getting the index parser.getInputStream().LA(1); int initialToken = parser.getInputStream().index(); while (true) { parser.getInputStream().seek(initialToken); tryParse(parser, potentialAlternatives, currentPath, results); if (!incrementCurrentPath(potentialAlternatives, currentPath)) { break; } } LOGGER.log(Level.FINE, "Forest parser constructed {0} parse trees.", results.size()); if (LOGGER.isLoggable(Level.FINEST)) { for (Map.Entry<RuleContext, CaretReachedException> entry : results.entrySet()) { LOGGER.log(Level.FINEST, entry.getKey().toStringTree(parser instanceof Parser ? (Parser)parser : null)); } } return results; }
public SerializedATN(OutputModelFactory factory, ATN atn) { super(factory); IntegerList data = ATNSerializer.getSerialized(atn); serialized = new ArrayList<String>(data.size()); for (int c : data.toArray()) { String encoded = factory.getGenerator().getTarget().encodeIntAsCharEscape(c == -1 ? Character.MAX_VALUE : c); serialized.add(encoded); } // System.out.println(ATNSerializer.getDecoded(factory.getGrammar(), atn)); }
@Override protected DFAState addDFAEdge(DFA dfa, DFAState fromState, int t, IntegerList contextTransitions, ATNConfigSet toConfigs, PredictionContextCache contextCache) { if (!getSuppressedSet(startIndex).isNil()) { DFAState to = addDFAState(dfa, toConfigs, contextCache); return to; } return super.addDFAEdge(dfa, fromState, t, contextTransitions, toConfigs, contextCache); }
protected boolean incrementCurrentPath(List<MultipleDecisionData> potentialAlternatives, IntegerList currentPath) { for (int i = currentPath.size() - 1; i >= 0; i--) { if (currentPath.get(i) < potentialAlternatives.get(i).alternatives.length - 1) { currentPath.set(i, currentPath.get(i) + 1); return true; } potentialAlternatives.remove(i); currentPath.removeAt(i); } return false; }
public void setFixedDecisions(List<MultipleDecisionData> decisionPoints, IntegerList selections) { Parameters.notNull("decisionPoints", decisionPoints); Parameters.notNull("selections", selections); this.decisionPoints = decisionPoints; this.selections = selections; this.caretTransitions = null; if (decisionPoints != null && !decisionPoints.isEmpty()) { _firstDecisionIndex = decisionPoints.get(0).inputIndex; } else { _firstDecisionIndex = Integer.MAX_VALUE; } }
public SilverstripeLexerState(int mode, IntegerList modeStack) { this.mode = mode; this.modeStack = new IntegerList(); this.modeStack.addAll(modeStack); }
public @NonNull IntegerList getBlockOffsets() { return _blockOffsets; }
public @NonNull IntegerList getBlockLineOffsets() { return _blockLineOffsets; }
public @NonNull ArrayList<IntegerList> getLineOffsets() { return _lineOffsets; }
public static IntegerList getSerialized(ATN atn) { return new ATNSerializer(atn).serialize(); }
public static String getDecoded(ATN atn, List<String> tokenNames) { IntegerList serialized = getSerialized(atn); char[] data = Utils.toCharArray(serialized); return new ATNSerializer(atn, tokenNames).decode(data); }
private void serializeUUID(IntegerList data, UUID uuid) { serializeLong(data, uuid.getLeastSignificantBits()); serializeLong(data, uuid.getMostSignificantBits()); }
private void serializeLong(IntegerList data, long value) { serializeInt(data, (int)value); serializeInt(data, (int)(value >> 32)); }
private void serializeInt(IntegerList data, int value) { data.add((char)value); data.add((char)(value >> 16)); }