Skip to content

Commit

Permalink
fix: alter go to support in experimental parser (#2306)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishche authored May 20, 2024
1 parent 71881e2 commit aa7ba71
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ public CstNode peek() {
* @return true if we have a match
*/
public boolean matchSeq(String... lexemes) {
List<Token> tokens = lexer.peekSeq(lexemes.length, t -> t.getType() == TokenType.WHITESPACE);
List<Token> tokens = lexer.peekSeq(lexemes.length,
t -> t.getType() == TokenType.WHITESPACE || t.getType() == TokenType.NEW_LINE);
if (tokens.size() != lexemes.length) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public boolean tryMatch(ParsingContext ctx, CobolLanguage language) {
if (!CobolLanguageUtils.isInAriaA(nameToken)) {
return false;
}
if (ctx.matchSeq(null, ".", "GO", "TO", ".")) {
return false;
}
if (ctx.matchSeq(null, ".", "GO", ".")) {
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2024 Broadcom.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*
*/
package org.eclipse.lsp.cobol.divisions.procedure;

import org.eclipse.lsp.cobol.cst.ProgramUnit;
import org.eclipse.lsp.cobol.cst.procedure.Paragraph;
import org.eclipse.lsp.cobol.cst.procedure.ProcedureDivision;
import org.eclipse.lsp.cobol.parser.hw.CobolParser;
import org.eclipse.lsp.cobol.parser.hw.ParseResult;
import org.eclipse.lsp.cobol.parser.hw.ParserSettings;
import org.eclipse.lsp.cobol.parser.hw.lexer.CobolLexer;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

/** test alter go - to */
public class AlterGoToTest {
@Test
void test() {
String source = " ID DIVISION. PROGRAM-ID. str1.\n"
+ " PROCEDURE DIVISION.\n"
+ " DISPLAY 'OUT'.\n"
+ " PARAG2.\n"
+ " GO TO.\n"
+ " PARAG2.\n"
+ " DISPLAY 'PARAG2'.\n";
ParseResult parseResult = new CobolParser(new CobolLexer(source), new ParserSettings()).parse();
assertTrue(parseResult.getDiagnostics().isEmpty());
ProgramUnit pu = (ProgramUnit) parseResult.getSourceUnit().getChildren().get(1);
ProcedureDivision pd = (ProcedureDivision) pu.getChildren().get(1);
assertEquals(1, pd.getChildren().stream().filter(Paragraph.class::isInstance).count());
assertEquals(source, parseResult.getSourceUnit().toText());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
* DAF Trucks NV – implementation of DaCo COBOL statements
* and DAF development standards
*
*/
package org.eclipse.lsp.cobol.divisions.procedure;
Expand Down

0 comments on commit aa7ba71

Please sign in to comment.