Skip to content

Commit

Permalink
slf4j
Browse files Browse the repository at this point in the history
  • Loading branch information
davydotcom committed Apr 25, 2023
1 parent d891da7 commit da08d33
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {

## What's New

* **0.7.1** Adding some parser exception safety and added slf4j dependency for logging errors
* **0.7.0** Adding some null safety on some of the base functions
* **0.6.9** Fixed some null pointer issues if content on base64encode was null and some exceptions on array traversal
* **0.6.8** Fixed ! (not) operator and added base64encode, base64decode, textdecodebase64, textencodebase64
Expand Down
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ext {


group = 'com.bertramlabs.plugins'
version = '0.7.0'
version = '0.7.1'

ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
sourceCompatibility = "1.8"
Expand All @@ -46,11 +46,14 @@ dependencies {
api 'com.fasterxml.jackson.core:jackson-databind:2.14.1'
api 'com.fasterxml.jackson.core:jackson-annotations:2.14.1'
api 'com.fasterxml.jackson.core:jackson-core:2.14.1'
api "org.slf4j:slf4j-parent:1.7.26"
api "org.slf4j:slf4j-api:1.7.26"
testImplementation platform("org.spockframework:spock-bom:2.3-groovy-4.0")
testImplementation "org.spockframework:spock-core"
testImplementation "org.spockframework:spock-junit4" // you can remove this if your code does not rely on old JUnit 4 rules
testImplementation "org.apache.groovy:groovy-all:4.0.4"


// testImplementation "org.spockframework:spock-core:2.3-groovy-3.0"
}

Expand Down
41 changes: 19 additions & 22 deletions src/main/java/com/bertramlabs/plugins/hcl4j/HCLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.io.*;
import java.nio.charset.Charset;
import java.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Parser for the Hashicorp Configuration Language (HCL). This is the primary endpoint and converts the HCL syntax into a {@link Map}.
Expand All @@ -41,7 +43,7 @@
* @author David Estes
*/
public class HCLParser {

static Logger log = LoggerFactory.getLogger(HCLParser.class);
//Time to parse the AST Tree into a Map
protected Map<String,Object> result = new LinkedHashMap<>();
protected Map<String,Object> variables = new LinkedHashMap<>();
Expand Down Expand Up @@ -296,33 +298,28 @@ public Map<String,Object> parse(Reader reader) throws HCLParserException, IOExce
public Map<String,Object> parse(Reader reader, Boolean ignoreParserExceptions) throws HCLParserException, IOException {
HCLLexer lexer = new HCLLexer(reader);
ArrayList<Symbol> rootBlocks;

if(ignoreParserExceptions) {
try {
lexer.yylex();
} catch(Exception ex) {
//TODO: Log the exception
}
} else {
lexer.yylex();
}


rootBlocks = lexer.elementStack;
try {
lexer.yylex();
rootBlocks = lexer.elementStack;


result = new LinkedHashMap<>();
Map<String,Object> mapPosition = result;
result = new LinkedHashMap<>();
Map<String,Object> mapPosition = result;

for(Symbol currentElement : rootBlocks) {
processSymbolPass1(currentElement,mapPosition);
}
for(Symbol currentElement : rootBlocks) {
processSymbolPass1(currentElement,mapPosition);
}

//pass2
for(String key : result.keySet()) {
//pass2
for(String key : result.keySet()) {
processSymbolPass2(result.get(key),result);
}
} catch(Exception ex) {
log.error("Error Parsing HCL...{}",ex.getMessage(),ex);
if(ignoreParserExceptions != true) { //its nullable so thats why we look at inverse
throw new RuntimeException(ex);
}
}
// System.out.println(result);
return result;
}

Expand Down

0 comments on commit da08d33

Please sign in to comment.