Skip to content

Commit

Permalink
consultingwerk#55 fix parsing of cases when the preprocessor variable…
Browse files Browse the repository at this point in the history
… is used inside the name checked by DEFINED() function.

e.g.
&if defined(i_tt{&prefix}companydata{&suffix}) = 0 &then
&IF DEFINED(OPEN-QUERY-{&QUERY-NAME}) NE 0 &THEN
  • Loading branch information
Daniel Baciu committed Oct 5, 2021
1 parent 51d8657 commit 969e649
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 3 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!
#Tue Aug 03 15:26:44 CEST 2021
build.number=1225
#Tue Oct 05 12:20:52 EEST 2021
build.number=1226
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.
6 changes: 6 additions & 0 deletions src/com/joanju/proparse/Lexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
*/
package com.joanju.proparse;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Stack;

import org.prorefactor.core.TokenTypes;
Expand Down Expand Up @@ -383,6 +386,7 @@ ProToken getAmpIfDefArg() throws IOException {
* I don't think there's any way to get whitespace into a macro name either.
*/
private ProToken ampIfDefArg() throws IOException {

loop:
for (;;) {
if (currChar == ')') {
Expand All @@ -404,7 +408,9 @@ private ProToken ampIfDefArg() throws IOException {
}
append();
getChar();

}

return makeToken(ID);
}

Expand Down
28 changes: 27 additions & 1 deletion src/com/joanju/proparse/Postlexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

import java.util.LinkedList;
import java.util.ArrayList;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;


public class Postlexer implements antlr.TokenStream, ProParserTokenTypes {
Expand Down Expand Up @@ -87,15 +90,38 @@ ProToken defined() throws IOException {
// Progress DEFINED() returns a single digit: 0,1,2, or 3.
// The text between the parens can be pretty arbitrary, and can
// have embedded comments, so this calls a specific lexer function for it.
// We may have macro usage inside the preprocessor string, which we need to skip
// lexer.getAmpIfDefArg returns expansed name
getNextToken();
if (currToken.getType() == WS)
getNextToken();
if (currToken.getType() != LEFTPAREN)
throwMessage("Bad DEFINED function in &IF preprocessor condition");

// in case the token starts with a preprocessor we skip it. need to get to preprocessed value,
for (;currToken.getType() == MAKROREFERENCE;)
getNextToken();

ProToken argToken = lexer.getAmpIfDefArg();

// when preprocessor variable to check starts with a preprocessor include,
// we take next one
for (;argToken.getType() == MAKROREFERENCE;)
argToken = lexer.getAmpIfDefArg();

// skip other preprocessors
for (;currToken.getType() == MAKROREFERENCE;)
getNextToken();

getNextToken();

// consume last preprocessors
for (;currToken.getType() == MAKROREFERENCE;){
getNextToken();
}

if (currToken.getType() != RIGHTPAREN)
throwMessage("Bad DEFINED function in &IF preprocessor condition");
throwMessage("Bad DEFINED function in &IF preprocessor condition. currToken=" + currToken.getText());
return new ProToken(filenameList, NUMBER, prepro.defined(argToken.getText().trim().toLowerCase()));
}

Expand Down
6 changes: 6 additions & 0 deletions src/com/joanju/proparse/Preprocessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,12 @@ else if (refText.startsWith("{&")) {
else
macroReference.put("col", refPos.col - 2);
makroRef.add(macroReference.toString());

final OutputStream os = new FileOutputStream("C:\\Temp\\parse.out", true);
final PrintStream printStream = new PrintStream(os);
printStream.println(macroReference.toString());
printStream.close();

}
catch(JSONException e)
{
Expand Down
40 changes: 40 additions & 0 deletions src/test/github55/TestClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package test.github55;

import java.io.File;

import org.prorefactor.core.JPNode;
import org.prorefactor.treeparser.ParseUnit;

import com.joanju.proparse.NodeTypes;

import junit.framework.Assert;
import junit.framework.TestCase;

public class TestClass extends TestCase {

public void test() throws Exception {

com.joanju.proparse.Environment proparseEnv = null;
org.prorefactor.core.schema.Schema proparseSchema = null;

proparseEnv = com.joanju.proparse.Environment.instance();
proparseSchema = org.prorefactor.core.schema.Schema.getInstance();

proparseSchema.clear();
// proparseSchema.loadSchema("C:\\Work\\Proparse\\Github\\proparse\\src\\test\\SCL3301\\schema.txt");

// proparseEnv.configSet ("propath", "C:\\Work_STREAM\\SmartComponentLibrary\\Develop122\\ABL");

proparseEnv.configSet ("batch-mode", "false");
proparseEnv.configSet ("opsys", "WIN32");
proparseEnv.configSet ("proversion", "12.2");
proparseEnv.configSet ("window-system", "MS-WINXP");


File file = new File("C:\\Work\\Proparse\\Github\\proparse\\src\\test\\github55\\testCode.p");
// File file = new File("C:\\Projects\\proparse\\src\\test\\github55\\testCode.p");
ParseUnit pu = new ParseUnit(file);

pu.treeParser01();

} }
44 changes: 44 additions & 0 deletions src/test/github55/testCode.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*------------------------------------------------------------------------
File : testCode.p
Purpose :
Syntax :
Description :
Author(s) : Daniel
Created : Mon Oct 04 11:57:10 CET 2021
Notes :
----------------------------------------------------------------------*/

/* *************************** Definitions ************************** */

block-level on error undo, throw.

/* ******************** Preprocessor Definitions ******************** */

/* preprocessor in middle and at the end of checked preprocessor variable*/
&if defined(i_tt{&prefix}companydata{&suffix}) = 0 &then
&global-define i_tt{&prefix}companydata{&suffix} yes
define {&scope} temp-table tt{&prefix}CompanyData{&suffix} no-undo {&reference-only} before-table bt{&prefix}CompanyData{&suffix}
field Company as character /* bedrijf */.
&ENDIF


/* preprocessor at begining of checked preprocessor variable */
&IF DEFINED({&PREFIX}TTEqSearchModel-I) = 0 &THEN
&GLOBAL-DEFINE {&PREFIX}TTEqSearchModel-I 1

def {&SCOPE} temp-table {&PREFIX}ttEqSearchModel no-undo {&REFERENCE-ONLY}
field SortOrder as int.

&ENDIF

/* *************************** Main Block *************************** */
&SCOP QUERY-NAME Query-Main
&Scoped-define OPEN-QUERY-Query-Main OPEN QUERY Query-Main FOR EACH baktype NO-LOCK INDEXED-REPOSITION.

&IF DEFINED(OPEN-QUERY-{&QUERY-NAME}) NE 0 &THEN
define variable hQuery as handle no-undo.
define variable hBuffer as handle no-undo.
&ENDIF

0 comments on commit 969e649

Please sign in to comment.