-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: implement some rules with nester statements for experimental parser
- Loading branch information
Showing
55 changed files
with
3,586 additions
and
196 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ public enum TokenType { | |
NUMBER_LITERAL, | ||
COBOL_WORD, | ||
NEW_LINE, | ||
DOT, | ||
OTHER, | ||
EOF | ||
} |
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
89 changes: 89 additions & 0 deletions
89
.../parser/src/main/java/org/eclipse/lsp/cobol/rules/procedure/ArithmeticExpressionRule.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,89 @@ | ||
/* | ||
* 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.rules.procedure; | ||
|
||
import org.eclipse.lsp.cobol.parser.hw.ParsingContext; | ||
import org.eclipse.lsp.cobol.parser.hw.lexer.TokenType; | ||
import org.eclipse.lsp.cobol.rules.CobolLanguage; | ||
import org.eclipse.lsp.cobol.rules.LanguageRule; | ||
|
||
/** p. 266 */ | ||
public class ArithmeticExpressionRule implements LanguageRule { | ||
|
||
@Override | ||
public void parse(ParsingContext ctx, CobolLanguage language) { | ||
arithmeticExpression(ctx, language); | ||
} | ||
|
||
private void arithmeticExpression(ParsingContext ctx, CobolLanguage language) { | ||
if (ctx.match("(")) { | ||
ctx.consume("("); | ||
do { | ||
arithmeticExpression(ctx, language); | ||
} while (!ctx.match(")")); | ||
ctx.consume(")"); | ||
ctx.spaces(); | ||
// p. 267 | ||
if (ctx.match("+", "-", "*", "/", "**")) { | ||
ctx.or("+", "-", "*", "/", "**"); | ||
ctx.spaces(); | ||
arithmeticExpression(ctx, language); | ||
} | ||
return; | ||
} | ||
|
||
if (ctx.getLexer().peek().getType() == TokenType.NUMBER_LITERAL) { | ||
ctx.consume(); | ||
ctx.spaces(); | ||
} else { | ||
language.parseRule(IdentifierRule.class, ctx); | ||
} | ||
// p. 267 | ||
if (ctx.match("+", "-", "*", "/", "**")) { | ||
ctx.or("+", "-", "*", "/", "**"); | ||
ctx.spaces(); | ||
arithmeticExpression(ctx, language); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean tryMatch(ParsingContext ctx, CobolLanguage language) { | ||
// An arithmetic expression can consist of any of the following items: | ||
// 1. An identifier described as a numeric elementary item (including numeric functions) | ||
if (language.tryMatchRule(IdentifierRule.class, ctx)) { | ||
return true; | ||
} | ||
// 2. A numeric literal | ||
if (ctx.getLexer().peek().getType() == TokenType.NUMBER_LITERAL) { | ||
return true; | ||
} | ||
// 3. The figurative constant ZERO | ||
if (ctx.match("ZERO")) { | ||
return true; | ||
} | ||
// 4. Identifiers and literals, as defined in items 1, 2, and 3, separated by arithmetic | ||
// operators | ||
// 5. Two arithmetic expressions, as defined in items 1, 2, 3, or 4, separated by an arithmetic | ||
// operator | ||
// 6. An arithmetic expression, as defined in items 1, 2, 3, 4, or 5, enclosed in parentheses | ||
if (ctx.match("(")) { | ||
return true; | ||
} | ||
// Any arithmetic expression can be preceded by a unary operator. | ||
if (ctx.match("+", "-")) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
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
Oops, something went wrong.