Skip to content

Parser fixes #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 21, 2020
Merged
29 changes: 19 additions & 10 deletions core/src/main/antlr4/oracle/weblogic/deploy/yaml/Yaml.g4
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
* The Universal Permissive License (UPL), Version 1.0
*/
grammar Yaml;
Expand Down Expand Up @@ -84,17 +84,17 @@ statement
;

assign
: name ASSIGN_OP value WS? COMMENT? NEWLINE?
: name ASSIGN_OP value COMMENT? NEWLINE
;

list_item
: LIST_ITEM_OP assign # YamlListItemAssign
| LIST_ITEM_OP value WS? COMMENT? NEWLINE? # YamlListItemValue
| LIST_ITEM_OP value COMMENT? NEWLINE? # YamlListItemValue
| LIST_ITEM_OP object # YamlListItemObject
;

object
: name BLOCK_OP COMMENT? obj_block
: name ASSIGN_OP COMMENT? obj_block
;

obj_block
Expand Down Expand Up @@ -127,8 +127,16 @@ inline_list_item
: (NEWLINE (INDENT)?)? value
;

// comments and blank lines before the first element avoid use of NEWLINE so there is no indent/dedent.
// this rule should be one of the first in this file, to override later definitions.
ATSTART
: {atStartOfInput()}? ( (COMMENT | WS*) ('\r'? '\n' | '\r' | '\f') )+ -> skip
;

// comments may appear on separate lines, or on the same line as assignments or object starts.
// don't close with NEWLINE here, needed to distinguish assign from object declaration.
COMMENT
: '# ' ~[\r\n\f]+ NEWLINE -> skip
: WS? '#' ~[\r\n\f]* -> skip
;

NULL
Expand Down Expand Up @@ -192,7 +200,12 @@ NEWLINE
String spaces = getText().replaceAll("[\r\n\f]+", "");

int next = _input.LA(1);
if (opened > 0 || next == '\r' || next == '\n' || next == '\f') {

// if opened > 0, we're in a square-bracket list.
// if next character is end-of-line, this was a blank line.
// if next character is #, this is a comment line.
// for these cases, don't check for indent, dedent.
if (opened > 0 || next == '\r' || next == '\n' || next == '\f' || next == '#') {
skip();
} else {
emit(commonToken(NEWLINE, newLine));
Expand Down Expand Up @@ -233,10 +246,6 @@ LIST_ITEM_OP
;

ASSIGN_OP
: WS? ': ' WS?
;

BLOCK_OP
: WS? ':' WS?
;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle Corporation and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
*/
package oracle.weblogic.deploy.logging;
Expand All @@ -17,7 +17,9 @@ public static <T extends Handler> Class<T> getHandlerClass(String handlerName) {
Class<T> handler = null;
try {
Class<?> checkClass = Class.forName(handlerName);
handler = (Class<T>)checkClass.asSubclass(Class.forName(handlerName));
@SuppressWarnings("unchecked")
Class<T> castHandler = (Class<T>)checkClass.asSubclass(Class.forName(handlerName));
handler = castHandler;
} catch(ClassNotFoundException | ClassCastException cnf) {
exitWithError(
MessageFormat.format("Unable to find handler class {0} so skipping logging configuration",
Expand Down
Loading