Skip to content

Commit

Permalink
Merge pull request consultingwerk#43 from consultingwerk/SCL-3450
Browse files Browse the repository at this point in the history
SCL-3450 : &IF .. &ENDIF are now replaced with text
  • Loading branch information
lutz-fechner authored Aug 3, 2021
2 parents b733345 + b599ea0 commit 51d8657
Show file tree
Hide file tree
Showing 14 changed files with 454 additions and 48 deletions.
4 changes: 2 additions & 2 deletions build.number
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Mon Jul 05 10:49:04 CEST 2021
build.number=1223
#Tue Aug 03 15:26:44 CEST 2021
build.number=1225
Binary file modified proparse.assemblies.zip
Binary file not shown.
Binary file modified proparse.jar
Binary file not shown.
Binary file modified proparse.java.zip
Binary file not shown.
Binary file modified proparse.net.dll
Binary file not shown.
207 changes: 207 additions & 0 deletions src/com/joanju/proparse/ConditionalCompilationToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
package com.joanju.proparse;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

import org.prorefactor.core.TokenTypes;

public class ConditionalCompilationToken
extends ProToken
{
protected ProToken ampIf;
protected ProToken ampEndIf;

protected String enclosedText;

protected boolean open;

/**
* Copy-Constructor for the ConditionalCompilationToken class to create the closing token
* @param token The original token
*/
public ConditionalCompilationToken (ConditionalCompilationToken token)
{
super (token.filenameList,
TokenTypes.CONDITIONALCOMPILATION,
"",
token.fileIndex,
token.line,
token.col,
token.macroSourceNum);
this.setAmpIf(token.getAmpIf());
this.setEndIf(token.getEndIf());
this.open = false;
}

/**
* Constructor for the ConditionalCompilationToken class
* @param filenameList IntegerIndex for the list of filenames
* @param file The index of the file
* @param textStartLine The starting line
* @param textStartCol The starting column
* @param textStartSource The starting macroSourceNum
*/
public ConditionalCompilationToken (IntegerIndex<String> filenameList,
int file,
int textStartLine,
int textStartCol,
int textStartSource)
{
super (filenameList, TokenTypes.CONDITIONALCOMPILATION, "", file, textStartLine, textStartCol, textStartSource);
this.open = true;
}

/**
* Returns whether this class is for the &IF token
* @return Whether this class is for the &IF token
*/
public boolean isOpening ()
{
return this.open;
}

/**
* Gets the &IF token
* @return The &IF token
*/
public ProToken getAmpIf ()
{
return this.ampIf;
}

/**
* Sets the &IF token
* @param ampIf The &IF token
*/
public void setAmpIf (ProToken ampIf)
{
this.ampIf = ampIf;
}

/**
* Sets the &ENDIF token and gets the enclosed text
* @param ampEndIf The &ENDIF token
*/
public void setEndIf (ProToken ampEndIf)
{
this.ampEndIf = ampEndIf;
this.setEnclosedText ();
}

/**
* Returns the &ENDIF token
* @return The &ENDIF token
*/
public ProToken getEndIf ()
{
return this.ampEndIf;
}

/**
* Returns the text between &IF and &ENDIF
* @return The text between &IF and &ENDIF
*/
public String getEnclosedText ()
{
return this.enclosedText;
}

/**
* Sets the enclosedText attribute as the text between &IF and &ENDIF
*/
protected void setEnclosedText ()
{
int beginLine;
int beginCol;
int endLine;
int endCol;

String beginFilename;
String endFilename;

ArrayList<String> lines;

if ( this.ampIf == null
|| this.ampEndIf == null)
return;

beginLine = this.ampIf.getLine() - 1;
beginCol = this.ampIf.getColumn() - 1;
beginFilename = this.ampIf.getFilename();

endLine = this.ampEndIf.getLine() + ((this.ampIf.getLine() == this.ampEndIf.getLine()) ? -1 : 0) ;
endCol = this.ampEndIf.getColumn() + this.ampEndIf.getText().length();
endFilename = this.ampEndIf.getFilename();

this.enclosedText = "";
if (beginFilename.equals(endFilename))
{
lines = this.getLines(beginFilename);
if(beginLine == endLine)
this.enclosedText = lines.get(beginLine).substring (beginCol, endCol);
else
{
for (int i = beginLine; i < endLine; i++)
{
if (i == beginLine)
this.enclosedText += lines.get(i).substring (beginCol);
else if (i == endLine)
this.enclosedText += lines.get(i).substring (0, endCol);
else
this.enclosedText += lines.get(i);
}
}
}
else
{
lines = this.getLines(beginFilename);
for (int i = beginLine; i < lines.size(); i++)
{
if (i == beginLine)
this.enclosedText += lines.get(i).substring (beginCol);
else
this.enclosedText += lines.get(i);
}

lines = this.getLines(endFilename);
for (int i = 0; i < endLine; i++)
{
if (i == endLine)
this.enclosedText += lines.get(i).substring (0, endCol);
else
this.enclosedText += lines.get(i);
}
}
// Remove last new Line
this.enclosedText = this.enclosedText.substring(0, this.enclosedText.length() + ((this.ampIf.getLine() == this.ampEndIf.getLine()) ? -1 : -2));
}

/**
* Reads a file as a list of lines
* @param filename Name of the file to read
* @return The files text as list of lines
*/
private ArrayList<String> getLines (String filename)
{
BufferedReader in;
String line;
ArrayList<String> lines = new ArrayList<String>();
try
{
in = new BufferedReader (new FileReader (new File (filename)));
while ((line = in.readLine()) != null)
lines.add(line + System.lineSeparator());
in.close();

return lines;
}
catch (IOException e)
{
e.printStackTrace();
return new ArrayList<String>();
}
}
}
5 changes: 5 additions & 0 deletions src/com/joanju/proparse/DoParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ else if (fileName != null) {
filter.hide(NodeTypes.INCLUDEFILEREFERENCE);
filter.hide(NodeTypes.MAKROREFERENCE);
filter.hide(NodeTypes.CONDITIONALCOMPILATION);
filter.hide(NodeTypes.AMPIF);
filter.hide(NodeTypes.AMPTHEN);
filter.hide(NodeTypes.AMPELSEIF);
filter.hide(NodeTypes.AMPELSE);
filter.hide(NodeTypes.AMPENDIF);
filter.hide(NodeTypes.AMPANALYZESUSPEND);
filter.hide(NodeTypes.AMPANALYZERESUME);
filter.hide(NodeTypes.AMPGLOBALDEFINE);
Expand Down
33 changes: 28 additions & 5 deletions src/com/joanju/proparse/Lexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
package com.joanju.proparse;

import java.io.IOException;
import java.util.Stack;

import org.prorefactor.core.TokenTypes;


public class Lexer implements ProParserTokenTypes {
Expand Down Expand Up @@ -46,14 +49,18 @@ public class Lexer implements ProParserTokenTypes {

private ProToken ampTextToken = null;
private ProToken newToken = null;


private Stack<ConditionalCompilationToken> condComp = new Stack<ConditionalCompilationToken>();
private ConditionalCompilationToken condToken = null;

//////////////// Lexical productions listed first, support functions follow.


ProToken nextToken() throws IOException {

String makroText;
String incRefText;
ConditionalCompilationToken token;

for (;;) {

Expand All @@ -74,6 +81,13 @@ ProToken nextToken() throws IOException {
} // switch
}

if(this.condToken != null)
{
token = this.condToken;
this.condToken = null;
return token;
}

if(!prepro.incRef.isEmpty())
{
textStartFile = prepro.textStartFile;
Expand Down Expand Up @@ -184,11 +198,20 @@ ProToken nextToken() throws IOException {
switch(ampTextToken.getType())
{
case ProParserTokenTypes.AMPIF:
case ProParserTokenTypes.AMPTHEN:
case ProParserTokenTypes.AMPELSE:
case ProParserTokenTypes.AMPELSEIF:
token = new ConditionalCompilationToken(filenameList, textStartFile, textStartLine, textStartCol, textStartSource);
token.setAmpIf(ampTextToken);
this.condComp.push(token);
newToken = token;
return newToken;

case ProParserTokenTypes.AMPENDIF:
return makeToken(CONDITIONALCOMPILATION, ampTextToken.getText());
token = this.condComp.pop();
token.setEndIf(ampTextToken);
newToken = ampTextToken;
ampTextToken = null;
this.condToken = new ConditionalCompilationToken(token);
return newToken;

default:
newToken = ampTextToken;
ampTextToken = null;
Expand Down
2 changes: 1 addition & 1 deletion src/com/joanju/proparse/TokenList.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void reviewObjcolon() {
}
if (list.get(index-1).getType() == NAMEDOT) {
index = index - 2;
} else if(list.get(index).getText().charAt(0)=='.') {
} else if(list.get(index).getText().length() > 0 && list.get(index).getText().charAt(0)=='.') {
index = index - 1;
} else {
break;
Expand Down
Loading

0 comments on commit 51d8657

Please sign in to comment.