Skip to content

Commit

Permalink
add MacroProcessor before input lphy script into parser #420
Browse files Browse the repository at this point in the history
  • Loading branch information
walterxie committed Nov 29, 2023
1 parent 1e9983e commit 6bba71e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions examples/macro/MacroLanguage.lphy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
data {
L = {{L = 100}};
taxa = taxa(names=1:{{n = 10}});
}
model {
ψ ~ Coalescent(theta=10, taxa=taxa);
D ~ PhyloCTMC(tree=ψ, L=L, Q=jukesCantor());
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lphy.core.parser;

import lphy.core.exception.SimulatorParsingException;
import lphy.core.io.MacroProcessor;
import lphy.core.model.ExpressionUtils;
import lphy.core.model.Value;
import lphy.core.model.datatype.DoubleValue;
Expand Down Expand Up @@ -92,13 +93,18 @@ default void source(File sourceFile) throws IOException {
default void source(BufferedReader bufferedReader) throws IOException {
StringBuilder builder = new StringBuilder();

String lineProcessed;
String line = bufferedReader.readLine();
while (line != null) {
builder.append(line);
// process macro here
lineProcessed = MacroProcessor.process(line);
builder.append(lineProcessed);
builder.append("\n");

line = bufferedReader.readLine();
}
bufferedReader.close();
// after macro processed
parse(builder.toString());
}

Expand Down

0 comments on commit 6bba71e

Please sign in to comment.