diff --git a/examples/macro/MacroLanguage.lphy b/examples/macro/MacroLanguage.lphy new file mode 100644 index 00000000..4c3b697f --- /dev/null +++ b/examples/macro/MacroLanguage.lphy @@ -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()); +} \ No newline at end of file diff --git a/lphy/src/main/java/lphy/core/parser/LPhyParserDictionary.java b/lphy/src/main/java/lphy/core/parser/LPhyParserDictionary.java index cc575477..9d984142 100644 --- a/lphy/src/main/java/lphy/core/parser/LPhyParserDictionary.java +++ b/lphy/src/main/java/lphy/core/parser/LPhyParserDictionary.java @@ -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; @@ -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()); }