Skip to content

Commit

Permalink
wip: hw parser reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
ishche committed May 16, 2024
1 parent 45576ae commit a5fb1df
Show file tree
Hide file tree
Showing 50 changed files with 569 additions and 231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
import org.eclipse.lsp.cobol.core.CobolParser;
import org.eclipse.lsp.cobol.core.CobolParserBaseVisitor;
import org.eclipse.lsp.cobol.core.semantics.CopybooksRepository;
import org.eclipse.lsp.cobol.dialects.ibm.experimental.visitors.CobolDataDivisionVisitor;
import org.eclipse.lsp.cobol.dialects.ibm.experimental.visitors.CobolIdentificationDivisionVisitor;
import org.eclipse.lsp.cobol.dialects.ibm.experimental.visitors.CobolProcedureDivisionVisitor;
import org.eclipse.lsp.cobol.service.settings.CachingConfigurationService;
import org.eclipse.lsp.cobol.common.dialects.CobolProgramLayout;
import org.eclipse.lsp4j.Location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/** This class provides keywords that are used for suggestions during the syntax check. */
@Slf4j
class KeywordSuggestions {
public class KeywordSuggestions {

@Getter private Set<String> suggestions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Levenshtein algorithm.
*/
@UtilityClass
class MisspelledKeywordDistance {
public class MisspelledKeywordDistance {

public static final KeywordSuggestions KEYWORDS = new KeywordSuggestions();
private static final LevenshteinDistance DISTANCE = LevenshteinDistance.getDefaultInstance();
Expand All @@ -38,7 +38,7 @@ class MisspelledKeywordDistance {
* @param wrongToken - potentially misspelled token to check
* @return the closest keyword or null if nothing found
*/
Optional<String> calculateDistance(String wrongToken) {
public Optional<String> calculateDistance(String wrongToken) {
return KEYWORDS.getSuggestions().stream()
.map(item -> new Object[] {item, DISTANCE.apply(wrongToken, item)})
.sorted(comparingInt(o -> (int) o[1]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static String getName(ParserRuleContext context) {
* @param stop is end position
* @return Locality with interval position
*/
static Locality getIntervalPosition(Locality start, Locality stop) {
public static Locality getIntervalPosition(Locality start, Locality stop) {
return Locality.builder()
.uri(start.getUri())
.range(new Range(start.getRange().getStart(), stop.getRange().getEnd()))
Expand Down Expand Up @@ -290,8 +290,8 @@ public static Range constructRange(ParserRuleContext ctx) {
* @param children list of child nodes of the parser rule
* @return a node for semantic analysis
*/
static Function<Locality, List<Node>> constructNode(
Function<Locality, Node> nodeConstructor, List<Node> children) {
public static Function<Locality, List<Node>> constructNode(
Function<Locality, Node> nodeConstructor, List<Node> children) {
return locality -> {
Node node = nodeConstructor.apply(locality);
children.forEach(node::addChild);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.lsp.cobol.dialects.hp.HpTrueCobolDialect;
import org.eclipse.lsp.cobol.dialects.ibm.*;
import org.eclipse.lsp.cobol.common.dialects.CobolLanguageId;
import org.eclipse.lsp.cobol.dialects.ibm.experimental.EnterpriseCobol64;
import org.eclipse.lsp.cobol.service.settings.CachingConfigurationService;
import org.eclipse.lsp.cobol.service.settings.layout.CodeLayoutStore;

Expand Down Expand Up @@ -63,7 +64,7 @@ public TrueDialectServiceImpl(
messageService, treeListener, subroutineService, cachingConfigurationService, dialectService,
astProcessor, symbolsRepository, codeLayoutStore));

dialects.put(CobolLanguageId.EXPERIMENTAL_COBOL, new HwIbmTrueCobolDialect(grammarPreprocessor,
dialects.put(CobolLanguageId.EXPERIMENTAL_COBOL, new EnterpriseCobol64(grammarPreprocessor,
messageService, treeListener, subroutineService, cachingConfigurationService, dialectService,
astProcessor, symbolsRepository, codeLayoutStore));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Broadcom, Inc. - initial API and implementation
*
*/
package org.eclipse.lsp.cobol.dialects.ibm;
package org.eclipse.lsp.cobol.dialects.ibm.experimental;

import org.antlr.v4.runtime.tree.ParseTreeListener;
import org.eclipse.lsp.cobol.common.CleanerPreprocessor;
Expand All @@ -25,26 +25,27 @@
import org.eclipse.lsp.cobol.core.engine.symbols.SymbolsRepository;
import org.eclipse.lsp.cobol.core.preprocessor.delegates.GrammarPreprocessor;
import org.eclipse.lsp.cobol.dialects.TrueCobolDialect;
import org.eclipse.lsp.cobol.dialects.ibm.*;
import org.eclipse.lsp.cobol.service.settings.CachingConfigurationService;
import org.eclipse.lsp.cobol.service.settings.layout.CodeLayoutStore;

/**
* HP Cobol Dialect
*/
public class HwIbmTrueCobolDialect implements TrueCobolDialect {
public class EnterpriseCobol64 implements TrueCobolDialect {

private final CleanerPreprocessor preprocessor;
private final Pipeline<AnalysisContext> pipeline;

public HwIbmTrueCobolDialect(GrammarPreprocessor grammarPreprocessor,
MessageService messageService,
ParseTreeListener treeListener,
SubroutineService subroutineService,
CachingConfigurationService cachingConfigurationService,
DialectService dialectService,
AstProcessor astProcessor,
SymbolsRepository symbolsRepository,
CodeLayoutStore codeLayoutStore) {
public EnterpriseCobol64(GrammarPreprocessor grammarPreprocessor,
MessageService messageService,
ParseTreeListener treeListener,
SubroutineService subroutineService,
CachingConfigurationService cachingConfigurationService,
DialectService dialectService,
AstProcessor astProcessor,
SymbolsRepository symbolsRepository,
CodeLayoutStore codeLayoutStore) {
preprocessor = new IbmTextPreprocessor(messageService, codeLayoutStore);

pipeline = new Pipeline<>();
Expand All @@ -54,7 +55,7 @@ public HwIbmTrueCobolDialect(GrammarPreprocessor grammarPreprocessor,
pipeline.add(new DialectProcessingStage(dialectService, preprocessor));
pipeline.add(new PreprocessorStage(grammarPreprocessor, preprocessor));
pipeline.add(new ImplicitDialectProcessingStage(dialectService));
pipeline.add(new HwParserStage(messageService, treeListener));
pipeline.add(new ExperimentalParserStage(messageService, treeListener));
pipeline.add(
new TransformTreeStage(
symbolsRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Broadcom, Inc. - initial API and implementation
*
*/
package org.eclipse.lsp.cobol.dialects.ibm;
package org.eclipse.lsp.cobol.dialects.ibm.experimental;

import com.google.common.collect.ImmutableList;
import lombok.RequiredArgsConstructor;
Expand All @@ -31,6 +31,7 @@
import org.eclipse.lsp.cobol.common.pipeline.Stage;
import org.eclipse.lsp.cobol.core.strategy.CobolErrorStrategy;
import org.eclipse.lsp.cobol.core.visitor.ParserListener;
import org.eclipse.lsp.cobol.dialects.ibm.ParserStageResult;
import org.eclipse.lsp.cobol.parser.AstBuilder;
import org.eclipse.lsp.cobol.parser.SplitParser;
import org.eclipse.lsp4j.Location;
Expand All @@ -42,7 +43,7 @@
* Parser stage
*/
@RequiredArgsConstructor
class HwParserStage implements Stage<AnalysisContext, ParserStageResult, DialectOutcome> {
class ExperimentalParserStage implements Stage<AnalysisContext, ParserStageResult, DialectOutcome> {
private final MessageService messageService;
private final ParseTreeListener treeListener;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Broadcom, Inc. - initial API and implementation
*
*/
package org.eclipse.lsp.cobol.dialects.ibm;
package org.eclipse.lsp.cobol.dialects.ibm.experimental;

import org.antlr.v4.runtime.CommonTokenStream;
import org.eclipse.lsp.cobol.common.SubroutineService;
Expand All @@ -26,7 +26,10 @@
import org.eclipse.lsp.cobol.core.engine.processor.AstProcessor;
import org.eclipse.lsp.cobol.core.engine.symbols.SymbolsRepository;
import org.eclipse.lsp.cobol.core.semantics.CopybooksRepository;
import org.eclipse.lsp.cobol.core.visitor.HwCobolVisitor;
import org.eclipse.lsp.cobol.dialects.ibm.experimental.visitors.HwCobolVisitor;
import org.eclipse.lsp.cobol.dialects.ibm.ParserStageResult;
import org.eclipse.lsp.cobol.dialects.ibm.ProcessingResult;
import org.eclipse.lsp.cobol.dialects.ibm.TransformTreeStage;
import org.eclipse.lsp.cobol.service.settings.CachingConfigurationService;
import org.eclipse.lsp.cobol.service.settings.layout.CodeLayoutStore;
import org.eclipse.lsp.cobol.service.settings.layout.CodeLayoutUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Broadcom, Inc. - initial API and implementation
*
*/
package org.eclipse.lsp.cobol.core.visitor;
package org.eclipse.lsp.cobol.dialects.ibm.experimental.visitors;

import com.google.common.collect.ImmutableList;
import lombok.Getter;
Expand All @@ -39,6 +39,7 @@
import org.eclipse.lsp.cobol.core.CobolDataDivisionParserBaseVisitor;
import org.eclipse.lsp.cobol.core.CobolParser;
import org.eclipse.lsp.cobol.core.semantics.CopybooksRepository;
import org.eclipse.lsp.cobol.core.visitor.VisitorHelper;
import org.eclipse.lsp4j.Location;

import java.util.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Broadcom, Inc. - initial API and implementation
*
*/
package org.eclipse.lsp.cobol.core.visitor;
package org.eclipse.lsp.cobol.dialects.ibm.experimental.visitors;

import com.google.common.collect.ImmutableList;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
*/

package org.eclipse.lsp.cobol.core.visitor;
package org.eclipse.lsp.cobol.dialects.ibm.experimental.visitors;

import com.google.common.collect.ImmutableList;
import lombok.Getter;
Expand Down Expand Up @@ -45,6 +45,8 @@
import org.eclipse.lsp.cobol.common.utils.StringUtils;
import org.eclipse.lsp.cobol.core.*;
import org.eclipse.lsp.cobol.core.semantics.CopybooksRepository;
import org.eclipse.lsp.cobol.core.visitor.MisspelledKeywordDistance;
import org.eclipse.lsp.cobol.core.visitor.VisitorHelper;
import org.eclipse.lsp.cobol.service.settings.CachingConfigurationService;
import org.eclipse.lsp.cobol.common.dialects.CobolProgramLayout;
import org.eclipse.lsp4j.Location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
*/

package org.eclipse.lsp.cobol.core.visitor;
package org.eclipse.lsp.cobol.dialects.ibm.experimental.visitors;

import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
*/

package org.eclipse.lsp.cobol.core.visitor;
package org.eclipse.lsp.cobol.dialects.ibm.experimental.visitors;

import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -26,6 +26,7 @@
import org.eclipse.lsp.cobol.common.model.tree.*;
import org.eclipse.lsp.cobol.core.*;
import org.eclipse.lsp.cobol.core.semantics.CopybooksRepository;
import org.eclipse.lsp.cobol.core.visitor.CobolVisitor;
import org.eclipse.lsp.cobol.service.settings.CachingConfigurationService;

import java.util.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.lsp.cobol.core.CobolDataDivisionParser.*;
import org.eclipse.lsp.cobol.core.CobolParser;
import org.eclipse.lsp.cobol.core.semantics.CopybooksRepository;
import org.eclipse.lsp.cobol.dialects.ibm.experimental.visitors.CobolDataDivisionVisitor;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.eclipse.lsp.cobol.positive.CobolTextRegistry.DEFAULT_LISTING_PATH;
import static org.eclipse.lsp.cobol.positive.CobolTextRegistry.PATH_TO_LISTING_SNAP;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT;

import java.io.File;
import java.nio.file.Files;
Expand All @@ -47,6 +48,7 @@
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand All @@ -57,6 +59,7 @@
* regressions. The complete error description with the file name logged.
*/
@Slf4j
@Execution(CONCURRENT)
class PositiveTest extends ConfigurableTest {

private CobolTextRegistry cobolTextRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import lombok.Getter;
import lombok.Setter;
import org.eclipse.lsp.cobol.cst.base.CstNodeImpl;
import org.eclipse.lsp.cobol.parser.hw.Token;
import org.eclipse.lsp.cobol.parser.hw.lexer.Token;

/**
* ProcedureDivision node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import lombok.Getter;
import lombok.Setter;
import org.eclipse.lsp.cobol.cst.base.CstNodeImpl;
import org.eclipse.lsp.cobol.parser.hw.Token;
import org.eclipse.lsp.cobol.parser.hw.lexer.Token;

/**
* Section node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.eclipse.lsp.cobol.core.CobolParser;
import org.eclipse.lsp.cobol.cst.SourceUnit;
import org.eclipse.lsp.cobol.parser.hw.ParserSettings;
import org.eclipse.lsp.cobol.parser.hw.CobolLexer;
import org.eclipse.lsp.cobol.parser.hw.lexer.CobolLexer;
import org.eclipse.lsp.cobol.parser.hw.antlradapter.AntlrAdapter;
import org.eclipse.lsp.cobol.parser.hw.Diagnostic;
import org.eclipse.lsp.cobol.parser.hw.ParseResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import lombok.extern.slf4j.Slf4j;

import org.eclipse.lsp.cobol.cst.*;
import org.eclipse.lsp.cobol.parser.hw.lexer.CobolLexer;
import org.eclipse.lsp.cobol.rules.CobolLanguage;
import org.eclipse.lsp.cobol.rules.SourceUnitRule;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import lombok.Getter;
import org.apache.commons.text.similarity.JaroWinklerSimilarity;
import org.eclipse.lsp.cobol.cst.base.CstNode;
import org.eclipse.lsp.cobol.parser.hw.lexer.CobolLexer;
import org.eclipse.lsp.cobol.parser.hw.lexer.Token;
import org.eclipse.lsp.cobol.parser.hw.lexer.TokenType;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;

Expand Down
Loading

0 comments on commit a5fb1df

Please sign in to comment.