Skip to content

Commit

Permalink
Merge pull request #40 from consultingwerk/SCL-3366
Browse files Browse the repository at this point in the history
SCL-3366 : Fixed issue with nested macro references.
Lutz Fechner: Code changes look syntactically fine to me.
  • Loading branch information
lutz-fechner authored Jun 7, 2021
2 parents 4b679e8 + baf585a commit 71e0ab8
Show file tree
Hide file tree
Showing 10 changed files with 376 additions and 22 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!
#Fri May 28 16:37:43 CEST 2021
build.number=1219
#Mon May 31 10:04:22 CEST 2021
build.number=1220
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.
23 changes: 16 additions & 7 deletions src/com/joanju/proparse/Lexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class Lexer implements ProParserTokenTypes {

ProToken nextToken() throws IOException {

String makroText;
String incRefText;

for (;;) {

if (preserve) {
Expand All @@ -71,24 +74,30 @@ ProToken nextToken() throws IOException {
} // switch
}

if(prepro.newIncRefText)
if(!prepro.incRef.isEmpty())
{
prepro.newIncRefText = false;
textStartFile = prepro.textStartFile;
textStartLine = prepro.textStartLine;
textStartCol = prepro.textStartCol;
textStartSource = prepro.textStartSourceNum;
return makeToken(INCLUDEFILEREFERENCE, prepro.incRefText);

incRefText = prepro.incRef.get(0);
prepro.incRef.remove(0);

return makeToken(INCLUDEFILEREFERENCE, incRefText);
}

if(prepro.newMakroRef)
if(!prepro.makroRef.isEmpty())
{
prepro.newMakroRef = false;
textStartFile = prepro.textStartFile;
textStartLine = prepro.textStartLine;
textStartCol = prepro.textStartCol;
textStartSource = prepro.textStartSourceNum;
return makeToken(MAKROREFERENCE, prepro.makroRef);

makroText = prepro.makroRef.get(0);
prepro.makroRef.remove(0);

return makeToken(MAKROREFERENCE, makroText);
}

// Proparse Directive
Expand Down Expand Up @@ -401,7 +410,7 @@ ProToken whitespace() throws IOException {
append();
fileIdx = prepro.currFile;
getChar();
if(prepro.newIncRefText || fileIdx != prepro.currFile)
if((!prepro.incRef.isEmpty()) || fileIdx != prepro.currFile)
break loop;
break;
default:
Expand Down
2 changes: 0 additions & 2 deletions src/com/joanju/proparse/Postlexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import java.util.ArrayList;
import java.io.IOException;

import org.prorefactor.core.TokenTypes;


public class Postlexer implements antlr.TokenStream, ProParserTokenTypes {

Expand Down
16 changes: 5 additions & 11 deletions src/com/joanju/proparse/Preprocessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,9 @@ public Preprocessor(
int currLine;
int currSourceNum;

String incRefText;
boolean newIncRefText;
ArrayList<String> incRef = new ArrayList<String>();
ArrayList<String> makroRef = new ArrayList<String>();

String makroRef;
boolean newMakroRef;

/** Are we in the middle of a comment? */
boolean doingComment = false;
boolean doingSingleLineComment = false;
Expand Down Expand Up @@ -686,15 +683,13 @@ else if (refText.startsWith("{&")) {
macroReference.put("col", refPos.col - 1);
else
macroReference.put("col", refPos.col - 2);

makroRef = macroReference.toString();
makroRef.add(macroReference.toString());
}
catch(JSONException e)
{
e.printStackTrace();
}
newMakroRef = true;


return;
}

Expand Down Expand Up @@ -814,8 +809,7 @@ else if (cp.chars[cp.pos] == '&') { // include '&' named args
argNum++;
}
}
this.incRefText = refText;
this.newIncRefText = true;
incRef.add(refText);
} // include file reference

} // macroReference()
Expand Down
34 changes: 34 additions & 0 deletions src/test/SCL3366/TestClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,40 @@ public void test_02() throws IOException, RefactorException
}
}

public void test_03() throws IOException, RefactorException
{
File source;
ParseUnit pu;

JPNode node;
String txt;
File target = new File("C:\\Work\\Proparse\\GitHub\\proparse\\src\\test\\SCL3366\\wWin_copy.w");
FileWriter fw = new FileWriter(target);

source = new File("C:\\Work\\Proparse\\GitHub\\proparse\\src\\test\\SCL3366\\wWin.w");
pu = new ParseUnit(source);
pu.treeParser01();

node = pu.getTopNode();
try{
txt = node.toStringSourceText();

fw.write(txt);
fw.flush();
fw.close();

this.compare(source, txt);
}
catch (RefactorException e)
{
System.out.println("Caught RefactorException: " + e.getMessage());
for(StackTraceElement ste: e.getStackTrace())
{
System.out.println(ste.toString());
}
}
}

private void compare(File orig, String copy)
{
BufferedReader brOrig;
Expand Down
Loading

0 comments on commit 71e0ab8

Please sign in to comment.