-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve #2613 : support HCL and a Terraform derivation
- Loading branch information
1 parent
2321e18
commit c5ef7ff
Showing
26 changed files
with
2,491 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/hcl/Consts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* CDDL HEADER START | ||
* | ||
* The contents of this file are subject to the terms of the | ||
* Common Development and Distribution License (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* | ||
* See LICENSE.txt included in this distribution for the specific | ||
* language governing permissions and limitations under the License. | ||
* | ||
* When distributing Covered Code, include this CDDL HEADER in each | ||
* file and include the License file at LICENSE.txt. | ||
* If applicable, add the following below this CDDL HEADER, with the | ||
* fields enclosed by brackets "[]" replaced with your own identifying | ||
* information: Portions Copyright [yyyy] [name of copyright owner] | ||
* | ||
* CDDL HEADER END | ||
*/ | ||
|
||
/* | ||
* Copyright (c) 2020, Chris Fraire <cfraire@me.com>. | ||
*/ | ||
|
||
package org.opengrok.indexer.analysis.hcl; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Represents a container for HCL keywords and other string constants. | ||
*/ | ||
public class Consts { | ||
|
||
private static final Set<String> kwd = new HashSet<>(); | ||
|
||
public static final Set<String> KEYWORDS = Collections.unmodifiableSet(kwd); | ||
|
||
static { | ||
/* | ||
* HCL has the irritating aspect that "there are no globally-reserved | ||
* words, but in some contexts certain identifiers are reserved to | ||
* function as keywords." | ||
* | ||
* We'll just treat the following as globally reserved and wait to see | ||
* if that causes problems for any users. | ||
*/ | ||
|
||
kwd.add("false"); | ||
kwd.add("true"); | ||
kwd.add("null"); | ||
kwd.add("for"); | ||
kwd.add("endfor"); | ||
kwd.add("in"); | ||
kwd.add("if"); | ||
kwd.add("else"); | ||
kwd.add("endif"); | ||
} | ||
|
||
/* private to enforce static */ | ||
private Consts() { | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/hcl/HCLAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* CDDL HEADER START | ||
* | ||
* The contents of this file are subject to the terms of the | ||
* Common Development and Distribution License (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* | ||
* See LICENSE.txt included in this distribution for the specific | ||
* language governing permissions and limitations under the License. | ||
* | ||
* When distributing Covered Code, include this CDDL HEADER in each | ||
* file and include the License file at LICENSE.txt. | ||
* If applicable, add the following below this CDDL HEADER, with the | ||
* fields enclosed by brackets "[]" replaced with your own identifying | ||
* information: Portions Copyright [yyyy] [name of copyright owner] | ||
* | ||
* CDDL HEADER END | ||
*/ | ||
|
||
/* | ||
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. | ||
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>. | ||
*/ | ||
|
||
package org.opengrok.indexer.analysis.hcl; | ||
|
||
import org.opengrok.indexer.analysis.AbstractAnalyzer; | ||
import org.opengrok.indexer.analysis.AnalyzerFactory; | ||
import org.opengrok.indexer.analysis.JFlexTokenizer; | ||
import org.opengrok.indexer.analysis.JFlexXref; | ||
import org.opengrok.indexer.analysis.plain.AbstractSourceCodeAnalyzer; | ||
|
||
import java.io.Reader; | ||
|
||
/** | ||
* Represents an extension of {@link AbstractSourceCodeAnalyzer} for the HCL | ||
* configuration language. | ||
*/ | ||
public class HCLAnalyzer extends AbstractSourceCodeAnalyzer { | ||
|
||
/** | ||
* Creates a new instance of {@link HCLAnalyzer}. | ||
* @param factory defined instance for the analyzer | ||
*/ | ||
protected HCLAnalyzer(AnalyzerFactory factory) { | ||
super(factory, () -> new JFlexTokenizer(new HCLSymbolTokenizer( | ||
AbstractAnalyzer.DUMMY_READER))); | ||
} | ||
|
||
/** | ||
* @return {@code null} as there is no aligned language | ||
*/ | ||
@Override | ||
public String getCtagsLang() { | ||
return null; | ||
} | ||
|
||
/** | ||
* Gets a version number to be used to tag processed documents so that | ||
* re-analysis can be re-done later if a stored version number is different | ||
* from the current implementation. | ||
* @return 20200409_05 | ||
*/ | ||
@Override | ||
protected int getSpecializedVersionNo() { | ||
return 20200409_05; // Edit comment above too! | ||
} | ||
|
||
/** | ||
* Creates a wrapped instance of {@link HCLXref}. | ||
* @param reader an instance passed to the new {@link HCLXref} | ||
* @return a defined instance | ||
*/ | ||
@Override | ||
protected JFlexXref newXref(Reader reader) { | ||
return new JFlexXref(new HCLXref(reader)); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/hcl/HCLAnalyzerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* CDDL HEADER START | ||
* | ||
* The contents of this file are subject to the terms of the | ||
* Common Development and Distribution License (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* | ||
* See LICENSE.txt included in this distribution for the specific | ||
* language governing permissions and limitations under the License. | ||
* | ||
* When distributing Covered Code, include this CDDL HEADER in each | ||
* file and include the License file at LICENSE.txt. | ||
* If applicable, add the following below this CDDL HEADER, with the | ||
* fields enclosed by brackets "[]" replaced with your own identifying | ||
* information: Portions Copyright [yyyy] [name of copyright owner] | ||
* | ||
* CDDL HEADER END | ||
*/ | ||
|
||
/* | ||
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. | ||
* Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>. | ||
*/ | ||
|
||
package org.opengrok.indexer.analysis.hcl; | ||
|
||
import org.opengrok.indexer.analysis.AbstractAnalyzer; | ||
import org.opengrok.indexer.analysis.FileAnalyzerFactory; | ||
|
||
/** | ||
* Represents an extension of {@link FileAnalyzerFactory} to produce | ||
* {@link HCLAnalyzer} instances. | ||
*/ | ||
public class HCLAnalyzerFactory extends FileAnalyzerFactory { | ||
|
||
private static final String name = "HCL"; | ||
|
||
private static final String[] SUFFIXES = {"HCL"}; | ||
|
||
/** | ||
* Creates a new instance of {@link HCLAnalyzerFactory}. | ||
*/ | ||
public HCLAnalyzerFactory() { | ||
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, name); | ||
} | ||
|
||
/** | ||
* Creates a new instance of {@link HCLAnalyzer}. | ||
* @return the new instance | ||
*/ | ||
@Override | ||
protected AbstractAnalyzer newAnalyzer() { | ||
return new HCLAnalyzer(this); | ||
} | ||
} |
Oops, something went wrong.