use of org.antlr.v4.runtime.misc.Triple in project antlr4 by antlr.
the class ParserATNFactory method optional.
/**
* From {@code (A)?} build either:
*
* <pre>
* o--A->o
* | ^
* o---->|
* </pre>
*
* or, if {@code A} is a block, just add an empty alt to the end of the
* block
*/
@Override
public Handle optional(GrammarAST optAST, Handle blk) {
BlockStartState blkStart = (BlockStartState) blk.left;
ATNState blkEnd = blk.right;
preventEpsilonOptionalBlocks.add(new Triple<Rule, ATNState, ATNState>(currentRule, blkStart, blkEnd));
boolean greedy = ((QuantifierAST) optAST).isGreedy();
blkStart.nonGreedy = !greedy;
epsilon(blkStart, blk.right, !greedy);
optAST.atnState = blk.left;
return blk;
}
use of org.antlr.v4.runtime.misc.Triple in project bookish by parrt.
the class Translator method visitLatex.
@Override
public OutputModelObject visitLatex(BookishParser.LatexContext ctx) {
String text = ctx.getText().trim();
// \latex{{...}}
List<String> stuff = extract(latexPattern, text);
text = stuff.get(0);
if (target == Tool.Target.LATEX || target == Tool.Target.LATEX_BOOK) {
return new Latex(this, null, text, text);
}
String relativePath = "images/latex-" + md5hash(text) + ".svg";
String src = outputDir + "/" + relativePath;
Path outpath = Paths.get(src);
if (!Files.exists(outpath)) {
Triple<String, Float, Float> results = texConverter.tex2svg(text, LATEX, BLOCK_EQN_FONT_SIZE);
String svg = results.a;
try {
System.out.println(outpath);
Files.write(outpath, svg.getBytes());
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
return new Latex(this, relativePath, text, text);
}
use of org.antlr.v4.runtime.misc.Triple in project bookish by parrt.
the class Translator method visitBlock_eqn.
@Override
public OutputModelObject visitBlock_eqn(BookishParser.Block_eqnContext ctx) {
String eqn = stripQuotes(ctx.getText(), 3);
if (target == Tool.Target.LATEX || target == Tool.Target.LATEX_BOOK) {
return new BlockEquation(this, null, eqn);
}
String relativePath = "images/blkeqn-" + md5hash(eqn) + ".svg";
String src = outputDir + "/" + relativePath;
Path outpath = Paths.get(src);
if (!Files.exists(outpath)) {
Triple<String, Float, Float> results = texConverter.tex2svg(eqn, BLOCKEQN, BLOCK_EQN_FONT_SIZE);
String svg = results.a;
try {
System.out.println(outpath);
Files.write(outpath, svg.getBytes());
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
return new BlockEquation(this, relativePath, eqn);
}
Aggregations