@Override public void evaluate(StringBuilder b, Resource resource, LiquidEngineContext ctxt) throws FHIRException { String src = includeResolver.fetchInclude(LiquidEngine.this, page); LiquidParser parser = new LiquidParser(src); LiquidDocument doc = parser.parse(page); LiquidEngineContext nctxt = new LiquidEngineContext(ctxt.externalContext); Tuple incl = new Tuple(); nctxt.vars.put("include", incl); for (String s : params.keySet()) { incl.addProperty(s, engine.evaluate(ctxt, resource, resource, params.get(s))); } for (LiquidNode n : doc.body) { n.evaluate(b, resource, nctxt); } } }
private String parseList(List<LiquidNode> list, String[] terminators) throws FHIRException { String close = null; while (cursor < source.length()) { if (next1() == '{' && (next2() == '%' || next2() == '{' )) { if (next2() == '%') { String cnt = parseTag('%'); if (Utilities.existsInList(cnt, terminators)) { close = cnt; break; } else if (cnt.startsWith("if ")) list.add(parseIf(cnt)); else if (cnt.startsWith("loop ")) list.add(parseLoop(cnt.substring(4).trim())); else if (cnt.startsWith("include ")) list.add(parseInclude(cnt.substring(7).trim())); else throw new FHIRException("Script "+name+": Script "+name+": Unknown flow control statement "+cnt); } else { // next2() == '{' list.add(parseStatement()); ((LiquidConstant) list.get(list.size()-1)).addChar(grab());
private LiquidNode parseLoop(String cnt) throws FHIRException { int i = 0; while (!Character.isWhitespace(cnt.charAt(i))) i++; LiquidLoop res = new LiquidLoop(); res.varName = cnt.substring(0, i); while (Character.isWhitespace(cnt.charAt(i))) i++; int j = i; while (!Character.isWhitespace(cnt.charAt(i))) i++; if (!"in".equals(cnt.substring(j, i))) throw new FHIRException("Script "+name+": Script "+name+": Error reading loop: "+cnt); res.condition = cnt.substring(i).trim(); parseList(res.body, new String[] { "endloop"} ); return res; }
private String parseList(List<LiquidNode> list, String[] terminators) throws FHIRException { String close = null; while (cursor < source.length()) { if (next1() == '{' && (next2() == '%' || next2() == '{' )) { if (next2() == '%') { String cnt = parseTag('%'); if (Utilities.existsInList(cnt, terminators)) { close = cnt; break; } else if (cnt.startsWith("if ")) list.add(parseIf(cnt)); else if (cnt.startsWith("loop ")) list.add(parseLoop(cnt.substring(4).trim())); else if (cnt.startsWith("include ")) list.add(parseInclude(cnt.substring(7).trim())); else throw new FHIRException("Script "+name+": Script "+name+": Unknown flow control statement "+cnt); } else { // next2() == '{' list.add(parseStatement()); ((LiquidConstant) list.get(list.size()-1)).addChar(grab());
private LiquidNode parseLoop(String cnt) throws FHIRException { int i = 0; while (!Character.isWhitespace(cnt.charAt(i))) i++; LiquidLoop res = new LiquidLoop(); res.varName = cnt.substring(0, i); while (Character.isWhitespace(cnt.charAt(i))) i++; int j = i; while (!Character.isWhitespace(cnt.charAt(i))) i++; if (!"in".equals(cnt.substring(j, i))) throw new FHIRException("Script "+name+": Script "+name+": Error reading loop: "+cnt); res.condition = cnt.substring(i).trim(); parseList(res.body, new String[] { "endloop"} ); return res; }
@Override public void evaluate(StringBuilder b, Resource resource, LiquidEngineContext ctxt) throws FHIRException { String src = includeResolver.fetchInclude(LiquidEngine.this, page); LiquidParser parser = new LiquidParser(src); LiquidDocument doc = parser.parse(page); LiquidEngineContext nctxt = new LiquidEngineContext(ctxt.externalContext); Tuple incl = new Tuple(); nctxt.vars.put("include", incl); for (String s : params.keySet()) { incl.addProperty(s, engine.evaluate(ctxt, resource, resource, params.get(s))); } for (LiquidNode n : doc.body) { n.evaluate(b, resource, nctxt); } } }
private LiquidStatement parseStatement() throws FHIRException { grab(); grab(); StringBuilder b = new StringBuilder(); while (cursor < source.length() && !(next1() == '}' && next2() == '}')) { b.append(grab()); } if (!(next1() == '}' && next2() == '}')) throw new FHIRException("Script "+name+": Unterminated Liquid statement {{ "+b.toString()); grab(); grab(); LiquidStatement res = new LiquidStatement(); res.statement = b.toString().trim(); return res; }
public LiquidDocument parse(String source, String sourceName) throws Exception { return new LiquidParser(source).parse(sourceName); }
private String parseTag(char ch) throws FHIRException { grab(); grab(); StringBuilder b = new StringBuilder(); while (cursor < source.length() && !(next1() == '%' && next2() == '}')) { b.append(grab()); } if (!(next1() == '%' && next2() == '}')) throw new FHIRException("Script "+name+": Unterminated Liquid statement {% "+b.toString()); grab(); grab(); return b.toString().trim(); }
private LiquidNode parseIf(String cnt) throws FHIRException { LiquidIf res = new LiquidIf(); res.condition = cnt.substring(3).trim(); String term = parseList(res.thenBody, new String[] { "else", "endif"} ); if ("else".equals(term)) term = parseList(res.elseBody, new String[] { "endif"} ); return res; }
public LiquidDocument parse(String name) throws FHIRException { this.name = name; LiquidDocument doc = new LiquidDocument(); parseList(doc.body, new String[0]); return doc; }
private LiquidStatement parseStatement() throws FHIRException { grab(); grab(); StringBuilder b = new StringBuilder(); while (cursor < source.length() && !(next1() == '}' && next2() == '}')) { b.append(grab()); } if (!(next1() == '}' && next2() == '}')) throw new FHIRException("Script "+name+": Unterminated Liquid statement {{ "+b.toString()); grab(); grab(); LiquidStatement res = new LiquidStatement(); res.statement = b.toString().trim(); return res; }
public LiquidDocument parse(String source, String sourceName) throws Exception { return new LiquidParser(source).parse(sourceName); }
private String parseTag(char ch) throws FHIRException { grab(); grab(); StringBuilder b = new StringBuilder(); while (cursor < source.length() && !(next1() == '%' && next2() == '}')) { b.append(grab()); } if (!(next1() == '%' && next2() == '}')) throw new FHIRException("Script "+name+": Unterminated Liquid statement {% "+b.toString()); grab(); grab(); return b.toString().trim(); }
public LiquidDocument parse(String name) throws FHIRException { this.name = name; LiquidDocument doc = new LiquidDocument(); parseList(doc.body, new String[0]); return doc; }
private LiquidNode parseIf(String cnt) throws FHIRException { LiquidIf res = new LiquidIf(); res.condition = cnt.substring(3).trim(); String term = parseList(res.thenBody, new String[] { "else", "endif"} ); if ("else".equals(term)) term = parseList(res.elseBody, new String[] { "endif"} ); return res; }