Browse Source

(HOA path) PrismParser: support QuotedString

REG_QUOTED_IDENT takes precedence over REG_QUOTED_STRING, therefore
QuotedString matches both.
tud-infrastructure-2018-10-12
Joachim Klein 7 years ago
parent
commit
333d86e6d8
  1. 24
      prism/src/parser/PrismParser.jj

24
prism/src/parser/PrismParser.jj

@ -516,7 +516,10 @@ TOKEN :
| < REG_DOUBLE: (["0"-"9"])*(".")?(["0"-"9"])+(["e","E"](["-","+"])?(["0"-"9"])+)? > | < REG_DOUBLE: (["0"-"9"])*(".")?(["0"-"9"])+(["e","E"](["-","+"])?(["0"-"9"])+)? >
| < REG_IDENTPRIME: ["_","a"-"z","A"-"Z"](["_","a"-"z","A"-"Z","0"-"9"])*"'" > | < REG_IDENTPRIME: ["_","a"-"z","A"-"Z"](["_","a"-"z","A"-"Z","0"-"9"])*"'" >
| < REG_IDENT: ["_","a"-"z","A"-"Z"](["_","a"-"z","A"-"Z","0"-"9"])* > | < REG_IDENT: ["_","a"-"z","A"-"Z"](["_","a"-"z","A"-"Z","0"-"9"])* >
// REG_QUOTED_IDENT has precedence before general REG_QUOTED_STRING
| < REG_QUOTED_IDENT: "\"" (["_","a"-"z","A"-"Z"](["_","a"-"z","A"-"Z","0"-"9"])*) "\"" > | < REG_QUOTED_IDENT: "\"" (["_","a"-"z","A"-"Z"](["_","a"-"z","A"-"Z","0"-"9"])*) "\"" >
// REG_QUOTED_STRING: first ", then finitely often either \+arbitrary char or not(\,"), then "
| < REG_QUOTED_STRING: "\"" (("\\" ~[]) | ~["\\","\""] )* "\"" >
| < PREPROC: "#"(~["#"])*"#" > | < PREPROC: "#"(~["#"])*"#" >
// Special catch-all token for lexical errors // Special catch-all token for lexical errors
// (this allows us to throw our usual exceptions in this case) // (this allows us to throw our usual exceptions in this case)
@ -1911,6 +1914,27 @@ ExpressionIdent QuotedIdentifierExpression() :
{ ret = new ExpressionIdent(ident); ret.setPosition(begin, getToken(0)); return ret; } { ret = new ExpressionIdent(ident); ret.setPosition(begin, getToken(0)); return ret; }
} }
// A quoted string ("text"), returns the unquoted text
QuotedString QuotedString() :
{
String s;
Token begin;
}
{
{begin = getToken(1);}
// can be either a QUOTED_IDENT or a QUOTED_STRING
( <REG_QUOTED_IDENT> { s = getToken(0).image;}
| <REG_QUOTED_STRING> { s = getToken(0).image;}
)
{
try {
return QuotedString.fromQuoted(s);
} catch (PrismLangException e) {
throw new ParseException(e.getMessage() + ", at line " + begin.next.beginLine + ", column " + begin.next.beginColumn +".");
}
}
}
// Identifier or min/max keyword (returns ExpressionIdent, storing position info) // Identifier or min/max keyword (returns ExpressionIdent, storing position info)
ExpressionIdent IdentifierExpressionMinMax() : ExpressionIdent IdentifierExpressionMinMax() :

Loading…
Cancel
Save