From 7bda9de511a5642efb297eae98c6ea7c42b27754 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Wed, 25 Oct 2017 12:10:14 -0300 Subject: Start switch to maven modules --- base/src/bjc/dicelang/CompilerTweaker.java | 102 +++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 base/src/bjc/dicelang/CompilerTweaker.java (limited to 'base/src/bjc/dicelang/CompilerTweaker.java') diff --git a/base/src/bjc/dicelang/CompilerTweaker.java b/base/src/bjc/dicelang/CompilerTweaker.java new file mode 100644 index 0000000..1154be4 --- /dev/null +++ b/base/src/bjc/dicelang/CompilerTweaker.java @@ -0,0 +1,102 @@ +package bjc.dicelang; + +import bjc.utils.parserutils.splitter.ConfigurableTokenSplitter; + +/* + * @TODO 10/09/17 Ben Culkin :CompilerTweaking + * Expand this to allow tweaking more things about the compiler. + */ +/** + * Contains methods for customizing the DiceLang and SCL compilers. + * + * @author Ben Culkin + */ +public class CompilerTweaker { + /* Bits of the compiler necessary */ + private final DiceLangEngine eng; + private final ConfigurableTokenSplitter opExpander; + + /** + * Create a new compiler tweaker. + * + * @param engine + * The engine to tweak. + */ + public CompilerTweaker(final DiceLangEngine engine) { + eng = engine; + + this.opExpander = engine.opExpander; + } + + /** + * Add a string literal to the compiler's internal banks. + * + * @param val + * The string literal to add. + * + * @return The key into the string literal table for this string. + */ + public int addStringLiteral(final String val) { + eng.addStringLiteral(eng.nextLiteral, val); + + eng.nextLiteral += 1; + return eng.nextLiteral; + } + + /** + * Add a line defn to the compiler. + * + * @param dfn + * The defn to add. + */ + public void addLineDefine(final Define dfn) { + eng.addLineDefine(dfn); + } + + /** + * Add a token defn to the compiler. + * + * @param dfn + * The defn to add. + */ + public void addTokenDefine(final Define dfn) { + eng.addTokenDefine(dfn); + } + + /** + * Adds delimiters that are expanded from tokens. + * + * @param delims + * The delimiters to expand on. + */ + public void addDelimiter(final String... delims) { + opExpander.addSimpleDelimiters(delims); + } + + /** + * Adds multi-character delimiters that are expanded from tokens. + * + * @param delims + * The multi-character delimiters to expand on. + */ + public void addMultiDelimiter(final String... delims) { + opExpander.addMultiDelimiters(delims); + } + + /** + * Make delimiter changes visible to the compiler. + */ + public void compile() { + opExpander.compile(); + } + + /** + * Change the max no. of times defines are allowed to recur. + * + * @param times + * The number of times to allow defines to recur. + */ + public static void setDefineRecurLimit(final int times) { + Define.MAX_RECURS = times; + } +} -- cgit v1.2.3