private char next() { char res = peek(); cursor++; return res; }
private String conceptId() throws FHIRException { StringBuffer res = new StringBuffer(Utilities.padLeft("", ' ', 18)); int i = 0; while (peek() >= '0' && peek() <= '9') { res.setCharAt(i, next()); i++; } rule(i > 0, "Concept not found (next char = \""+peekDisp()+"\", in '"+source+"')"); return res.substring(0, i); }
private boolean gchar(char ch) { boolean result = peek() == ch; if (result) next(); return result; }
private Expression parse() throws FHIRException { Expression res = new Expression(); res.setStart(cursor); ws(); if (peek() == '=') { res.status = ExpressionStatus.Equivalent; prefix('='); } else if (peek() == '<') { res.status = ExpressionStatus.SubsumedBy; prefix('<'); } res.concepts.add(concept()); while (gchar('+')) res.concepts.add(concept()); if (gchar(':')) { ws(); refinements(res); } res.setStop(cursor); rule(cursor >= source.length(), "Found content (\""+peekDisp()+"\") after end of expression"); return res; }
private String conceptId() throws FHIRException { StringBuffer res = new StringBuffer(Utilities.padLeft("", ' ', 18)); int i = 0; while (peek() >= '0' && peek() <= '9') { res.setCharAt(i, next()); i++; } rule(i > 0, "Concept not found (next char = \""+peekDisp()+"\", in '"+source+"')"); return res.substring(0, i); }
private String term() { StringBuffer res = new StringBuffer(Utilities.padLeft("", ' ', MAX_TERM_LIMIT)); int i = 0; while (peek() != '|') { res.setCharAt(i, next()); i++; } return res.substring(0, i); }
private String stringConstant() throws FHIRException { StringBuffer res = new StringBuffer(Utilities.padLeft("", ' ', MAX_TERM_LIMIT)); fixed('"'); int i = 0; while (peek() != '"') { i++; res.setCharAt(i, next()); } fixed('"'); return res.substring(0, i); }
private void ws() { while (Utilities.existsInList(peek(), ' ', '\t', '\r', 'n')) next(); }
private void fixed(char ch) throws FHIRException { boolean b = gchar(ch); rule(b, "Expected character \""+ch+"\" but found "+peek()); ws(); }
private void refinements(Expression expr) throws FHIRException { boolean n = true; while (n) { if (peek() != '{') expr.refinements.add(attribute()); else expr.refinementGroups.add(attributeGroup()); ws(); n = gchar(','); ws(); } }
private Concept concept() throws FHIRException { Concept res = new Concept(); res.setStart(cursor); ws(); if (peek() == '#') res.decimal = decimal(); else if (peek() == '"') res.literal = stringConstant(); else res.code = conceptId(); ws(); if (gchar('|')) { ws(); res.description = term().trim(); ws(); fixed('|'); ws(); } res.setStop(cursor); return res; }
private char next() { char res = peek(); cursor++; return res; }
private boolean gchar(char ch) { boolean result = peek() == ch; if (result) next(); return result; }
private String term() { StringBuffer res = new StringBuffer(Utilities.padLeft("", ' ', MAX_TERM_LIMIT)); int i = 0; while (peek() != '|') { res.setCharAt(i, next()); i++; } return res.substring(0, i); }
private String stringConstant() throws FHIRException { StringBuffer res = new StringBuffer(Utilities.padLeft("", ' ', MAX_TERM_LIMIT)); fixed('"'); int i = 0; while (peek() != '"') { i++; res.setCharAt(i, next()); } fixed('"'); return res.substring(0, i); }
private void ws() { while (Utilities.existsInList(peek(), ' ', '\t', '\r', 'n')) next(); }
private void fixed(char ch) throws FHIRException { boolean b = gchar(ch); rule(b, "Expected character \""+ch+"\" but found "+peek()); ws(); }
private void refinements(Expression expr) throws FHIRException { boolean n = true; while (n) { if (peek() != '{') expr.refinements.add(attribute()); else expr.refinementGroups.add(attributeGroup()); ws(); n = gchar(','); ws(); } }