Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions parser.ccc/src/main/ccc/Grammer.ccc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ NODE_PACKAGE = org.eclipse.daanse.mdx.parser.ccc.tree;
TABS_TO_SPACES = 4;
PRESERVE_TABS = true;
NODE_PREFIX = "AST";
TREE_BUILDING_ENABLED = false;
COPYRIGHT_BLURB="\n*\n* Copyright (c) 2023 Contributors to the Eclipse Foundation.\n*\n* This program and the accompanying materials are made\n* available under the terms of the Eclipse Public License 2.0\n* which is available at https://www.eclipse.org/legal/epl-2.0/\n*\n* SPDX-License-Identifier: EPL-2.0\n*\n* Contributors: see corresponding .ccc file\n";

INJECT PARSER_CLASS :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

import java.util.List;
import java.util.Optional;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.Set;

import org.slf4j.Logger;
Expand Down Expand Up @@ -99,8 +96,6 @@ public MdxStatement parseMdxStatement() throws MdxParserException {
} catch (StackOverflowError e) {
logger.debug("Failed to parse, nested too deep");
throw tooDeep(e);
} finally {
dump();
}

}
Expand All @@ -118,11 +113,11 @@ private static MdxParserException toMdxParserException(ParseException pe) {
* text does not have. The statement ends right after its last token, so that is where it is reported.
*/
private static MdxParserException atToken(ParseException pe) {
Node.TerminalNode token = pe.getToken();
Token token = pe.getToken();
String message = pe.getMessage();
int line = token.getBeginLine();
int column = token.getBeginColumn();
Token last = token instanceof Token eof && eof.getType() == Token.TokenType.EOF ? eof.getPrevious() : null;
Token last = token.getType() == Token.TokenType.EOF ? token.getPrevious() : null;
if (last != null) {
line = last.getEndLine();
column = last.getEndColumn() + 1;
Expand All @@ -132,26 +127,6 @@ private static MdxParserException atToken(ParseException pe) {
return new MdxParserException(message, pe, line, column);
}

private void dump() {
// Node.dump() writes the whole tree to System.out, so it has to be gated on the
// level like the message above it. Ungated, every parse printed its AST: ~177k
// lines per TCK test group, unreachable by any logging configuration.
if (!logger.isTraceEnabled()) {
return;
}
Node root = delegate.rootNode();
if (root != null) {
// through the logger, not to System.out: the configuration decides where it goes
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
root.dump("", new PrintStream(buffer, false, StandardCharsets.UTF_8));
logger.trace("parser AST:{}{}", System.lineSeparator(), buffer.toString(StandardCharsets.UTF_8));
} catch (StackOverflowError e) {
logger.trace("parser AST is nested too deep to dump");
}
}
}

/**
* Every failure of a parse is a MdxParserException, also the stack that runs
* out on input the nesting limit of the grammar did not stop.
Expand Down Expand Up @@ -276,8 +251,6 @@ private <T> T parse(String what, ParseAction<T> action) throws MdxParserExceptio
} catch (StackOverflowError e) {
logger.debug("Failed to parse, nested too deep");
throw tooDeep(e);
} finally {
dump();
}
}
}
Loading