public abstract class AbstractCobolSourceCleaner extends Object
This allows users to submit complete COBOL programs or fragments of COBOL programs with non data description statements to the parser without the need to add grammar rules for all these cases.
| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractCobolSourceCleaner.CleaningContext
Describes the cleaning context.
|
| Modifier and Type | Field and Description |
|---|---|
static Pattern |
ALPHANUM_LITERAL_START
Pattern that recognizes the start of an alphanumeric literal.
|
static char |
COBOL_DELIMITER
Cobol sentences are assumed to be terminated by this character.
|
static List<String> |
COMPILER_DIRECTIVES
List of compiler directives (they can be period delimited but are
guaranteed to be alone on a line).
|
static Pattern |
DATA_DESCRIPTION_END
Pattern that recognizes the end of a data description entry.
|
static Pattern |
DATA_DESCRIPTION_START
Pattern that recognizes the start of a data description entry.
|
static Pattern |
DATA_DIVISION
Pattern that recognizes the start of a data division.
|
static Pattern |
IDENTIFICATION_DIVISION
Pattern that recognizes the start of an identification division.
|
static Pattern |
PROCEDURE_DIVISION
Pattern that recognizes the start of a procedure division.
|
| Constructor and Description |
|---|
AbstractCobolSourceCleaner(RecognizerErrorHandler errorHandler)
Construct with a shared error handler.
|
| Modifier and Type | Method and Description |
|---|---|
String |
clean(Reader cobolReader)
Takes in a raw COBOL source, potentially containing sequence numbers or
non data description statements and produces a clean source code.
|
String |
cleanLine(String line)
Remove characters that should not be passed to the lexer.
|
void |
emitErrorMessage(String msg)
Add an error message to the history.
|
String |
extendedCleanLine(String line)
Derived classes can extend this method to further clean a line of code.
|
RecognizerErrorHandler |
getErrorHandler() |
abstract int |
getIndicatorAreaPos() |
protected boolean |
isArgument(String fragment)
Examine characters before an assumed level.
|
abstract boolean |
isComment(String line)
Specialized cleaners determine if this line is a comment.
|
boolean |
isDataDivision(String line,
AbstractCobolSourceCleaner.CleaningContext context)
Rough triage of statements which are not strictly part of the data
division.
|
boolean |
isLineOfCode(String line)
Make sure this is a line worth parsing.
|
String |
removeExtraneousCharacters(String fragment,
AbstractCobolSourceCleaner.CleaningContext context)
Removes characters which are not part of a data description entry.
|
protected String |
replaceLongSeparators(String str)
Replace token separators such as ", " and "; " which complicate matters
uselessly.
|
public static final char COBOL_DELIMITER
public static final Pattern DATA_DESCRIPTION_START
public static final Pattern DATA_DESCRIPTION_END
public static final Pattern ALPHANUM_LITERAL_START
public static final Pattern PROCEDURE_DIVISION
public static final Pattern IDENTIFICATION_DIVISION
public static final Pattern DATA_DIVISION
public AbstractCobolSourceCleaner(RecognizerErrorHandler errorHandler)
errorHandler - handles error messagespublic String clean(Reader cobolReader) throws CleanerException
Statements which are not data descriptions become empty lines in order to preserve original line numbering.
cobolReader - a reader for the raw COBOL sourceCleanerException - if source cannot be readpublic boolean isLineOfCode(String line)
line - the line to parsepublic String cleanLine(String line)
line - before cleaningpublic abstract boolean isComment(String line)
line - the line to checkpublic String extendedCleanLine(String line)
line - the current line of codeprotected String replaceLongSeparators(String str)
str - a string containing long separatorspublic boolean isDataDivision(String line, AbstractCobolSourceCleaner.CleaningContext context)
Since we are not guaranteed to have identification division, we initially consider we are in the data division. If we find an identification division, then we stop processing till we find a data division.
line - the line to set data description status fromcontext - the data description detection contextpublic abstract int getIndicatorAreaPos()
public String removeExtraneousCharacters(String fragment, AbstractCobolSourceCleaner.CleaningContext context)
The fragment received as a parameter is assumed to be cleaned from sequence numbers.
Data description entries start with an integer (the level) and end with a period followed by either space, newline or EOF.
A single line might hold multiple data descriptions. This method is recursive, and is called multiple times for each line fragment holding a new data description.
Data description entries might span multiple lines which is why we need to keep a context. Context tells us if we need to start by looking for a level (no data description has started on some previous line) or for a period.
Unsupported data description instructions such as COPY might appear on the same line as data instructions. They also can span multiple lines. This code blanks out such "non data description" statements.
Code that is outside alphanumeric literals is also cleaned from long separators.
fragment - a fragment of a line which might hold a data descriptioncontext - the data description detection contextprotected boolean isArgument(String fragment)
fragment - a fragment of code preceding an assumed levelpublic void emitErrorMessage(String msg)
msg - the error messagepublic RecognizerErrorHandler getErrorHandler()
Copyright © 2021 LegSem. All rights reserved.