use of edu.mit.csail.sdg.alloy4.ErrorSyntax in project org.alloytools.alloy by AlloyTools.
the class CompModule method unique.
/**
* Throw an exception if there are more than 1 match; return nonnull if only one
* match; return null if no match.
*/
private Object unique(Pos pos, String name, List<Object> objs) throws Err {
if (objs.size() == 0)
return null;
if (objs.size() == 1)
return objs.get(0);
StringBuilder msg = new StringBuilder("The name \"").append(name);
msg.append("\" is ambiguous.\n" + "There are ").append(objs.size()).append(" choices:");
for (int i = 0; i < objs.size(); i++) {
msg.append("\n\n#").append(i + 1).append(": ");
Object x = objs.get(i);
if (x instanceof Sig) {
Sig y = (Sig) x;
msg.append("sig ").append(y.label).append("\n" + "at ").append(y.pos.toShortString());
} else if (x instanceof Func) {
Func y = (Func) x;
msg.append(y.isPred ? "pred " : "fun ").append(y.label).append("\n" + "at ").append(y.pos.toShortString());
} else if (x instanceof Expr) {
Expr y = (Expr) x;
msg.append("assertion at ").append(y.pos.toShortString());
}
}
throw new ErrorSyntax(pos, msg.toString());
}
use of edu.mit.csail.sdg.alloy4.ErrorSyntax in project org.alloytools.alloy by AlloyTools.
the class CompLexer method alloy_string.
private final Symbol alloy_string(String txt) throws Err {
Pos p = alloy_here(txt);
if (!Version.experimental)
throw new ErrorSyntax(p, "String literal is not currently supported.");
StringBuilder sb = new StringBuilder(txt.length());
for (int i = 0; i < txt.length(); i++) {
char c = txt.charAt(i);
if (c == '\r' || c == '\n')
throw new ErrorSyntax(p, "String literal cannot span multiple lines; use \\n instead.");
if (c == '\\') {
i++;
if (i >= txt.length())
throw new ErrorSyntax(p, "String literal cannot end with a single \\");
c = txt.charAt(i);
if (c == 'n')
c = '\n';
else if (c != '\'' && c != '\"' && c != '\\')
throw new ErrorSyntax(p, "String literal currenty only supports\nfour escape sequences: \\\\, \\n, \\\', and \\\"");
}
sb.append(c);
}
txt = sb.toString();
if (txt.length() == 2)
throw new ErrorSyntax(p, "Empty string is not allowed; try rewriting your model to use an empty set instead.");
return new Symbol(CompSym.STR, p, ExprConstant.Op.STRING.make(p, txt));
}
use of edu.mit.csail.sdg.alloy4.ErrorSyntax in project org.alloytools.alloy by AlloyTools.
the class CompLexer method alloy_binarynum.
private final Symbol alloy_binarynum(String txt) throws Err {
Pos p = alloy_here(txt);
int n = 0;
try {
txt = txt.substring(2).replaceAll("_", "");
n = Integer.parseInt(txt, 2);
} catch (NumberFormatException ex) {
throw new ErrorSyntax(p, "The binary number " + txt + " " + ex);
}
return new Symbol(CompSym.NUMBER, p, ExprConstant.Op.NUMBER.make(p, n));
}
use of edu.mit.csail.sdg.alloy4.ErrorSyntax in project org.alloytools.alloy by AlloyTools.
the class CompLexer method next_token.
/**
* Resumes scanning until the next regular expression is matched, the end of
* input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException if any I/O-Error occurs
*/
@Override
public java_cup.runtime.Symbol next_token() throws java.io.IOException {
int zzInput;
int zzAction;
// cached fields:
int zzCurrentPosL;
int zzMarkedPosL;
int zzEndReadL = zzEndRead;
char[] zzBufferL = zzBuffer;
char[] zzCMapL = ZZ_CMAP;
int[] zzTransL = ZZ_TRANS;
int[] zzRowMapL = ZZ_ROWMAP;
int[] zzAttrL = ZZ_ATTRIBUTE;
while (true) {
zzMarkedPosL = zzMarkedPos;
boolean zzR = false;
for (zzCurrentPosL = zzStartRead; zzCurrentPosL < zzMarkedPosL; zzCurrentPosL++) {
switch(zzBufferL[zzCurrentPosL]) {
case '\u000B':
case '\u000C':
case '\u0085':
case '\u2028':
case '\u2029':
yyline++;
yycolumn = 0;
zzR = false;
break;
case '\r':
yyline++;
yycolumn = 0;
zzR = true;
break;
case '\n':
if (zzR)
zzR = false;
else {
yyline++;
yycolumn = 0;
}
break;
default:
zzR = false;
yycolumn++;
}
}
if (zzR) {
// peek one character ahead if it is \n (if we have counted one line too much)
boolean zzPeek;
if (zzMarkedPosL < zzEndReadL)
zzPeek = zzBufferL[zzMarkedPosL] == '\n';
else if (zzAtEOF)
zzPeek = false;
else {
boolean eof = zzRefill();
zzEndReadL = zzEndRead;
zzMarkedPosL = zzMarkedPos;
zzBufferL = zzBuffer;
if (eof)
zzPeek = false;
else
zzPeek = zzBufferL[zzMarkedPosL] == '\n';
}
if (zzPeek)
yyline--;
}
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
zzState = zzLexicalState;
zzForAction: {
while (true) {
if (zzCurrentPosL < zzEndReadL)
zzInput = zzBufferL[zzCurrentPosL++];
else if (zzAtEOF) {
zzInput = YYEOF;
break zzForAction;
} else {
// store back cached positions
zzCurrentPos = zzCurrentPosL;
zzMarkedPos = zzMarkedPosL;
boolean eof = zzRefill();
// get translated positions and possibly new buffer
zzCurrentPosL = zzCurrentPos;
zzMarkedPosL = zzMarkedPos;
zzBufferL = zzBuffer;
zzEndReadL = zzEndRead;
if (eof) {
zzInput = YYEOF;
break zzForAction;
} else {
zzInput = zzBufferL[zzCurrentPosL++];
}
}
int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]];
if (zzNext == -1)
break zzForAction;
zzState = zzNext;
int zzAttributes = zzAttrL[zzState];
if ((zzAttributes & 1) == 1) {
zzAction = zzState;
zzMarkedPosL = zzCurrentPosL;
if ((zzAttributes & 8) == 8)
break zzForAction;
}
}
}
// store back cached position
zzMarkedPos = zzMarkedPosL;
switch(zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 4:
{
return alloy_sym(yytext(), CompSym.AMPERSAND);
}
case 86:
break;
case 50:
{
return alloy_sym(yytext(), CompSym.SEQ);
}
case 87:
break;
case 62:
{
return alloy_binarynum(yytext());
}
case 88:
break;
case 38:
{
return alloy_sym(yytext(), CompSym.IMPLIES);
}
case 89:
break;
case 23:
{
return alloy_sym(yytext(), CompSym.RBRACE);
}
case 90:
break;
case 82:
{
return alloy_sym(yytext(), CompSym.EXACTLY);
}
case 91:
break;
case 1:
{
throw new ErrorSyntax(alloy_here(" "), "Syntax error at the " + yytext() + " character. HEX: \\u" + Integer.toString(yytext().charAt(0), 16) + ")");
}
case 92:
break;
case 53:
{
return alloy_sym(yytext(), CompSym.RUN);
}
case 93:
break;
case 36:
{
return alloy_sym(yytext(), CompSym.SHL);
}
case 94:
break;
case 35:
{
return alloy_sym(yytext(), CompSym.DOMAIN);
}
case 95:
break;
case 60:
{
return alloy_sym(yytext(), CompSym.SIGINT);
}
case 96:
break;
case 24:
{
return alloy_sym(yytext(), CompSym.TILDE);
}
case 97:
break;
case 21:
{
return alloy_sym(yytext(), CompSym.LBRACE);
}
case 98:
break;
case 7:
{
return alloy_sym(yytext(), CompSym.STAR);
}
case 99:
break;
case 30:
{
return alloy_sym(yytext(), CompSym.PLUSPLUS);
}
case 100:
break;
case 58:
{
return alloy_sym(yytext(), CompSym.FUN);
}
case 101:
break;
case 81:
{
return alloy_sym(yytext(), CompSym.STRING);
}
case 102:
break;
case 55:
{
return alloy_sym(yytext(), CompSym.EXH);
}
case 103:
break;
case 56:
{
return alloy_sym(yytext(), CompSym.INT);
}
case 104:
break;
case 52:
{
return alloy_sym(yytext(), CompSym.SIG);
}
case 105:
break;
case 75:
{
return alloy_sym(yytext(), CompSym.PRED);
}
case 106:
break;
case 25:
{
return alloy_id(yytext());
}
case 107:
break;
case 66:
{
return alloy_sym(yytext(), CompSym.LONE);
}
case 108:
break;
case 41:
{
return alloy_sym(yytext(), CompSym.NO);
}
case 109:
break;
case 9:
{
return alloy_sym(yytext(), CompSym.COMMA);
}
case 110:
break;
case 40:
{
return alloy_sym(yytext(), CompSym.AS);
}
case 111:
break;
case 65:
{
return alloy_sym(yytext(), CompSym.THIS);
}
case 112:
break;
case 13:
{
return alloy_sym(yytext(), CompSym.SLASH);
}
case 113:
break;
case 48:
{
return alloy_sym(yytext(), CompSym.BUT);
}
case 114:
break;
case 43:
{
return alloy_string(yytext());
}
case 115:
break;
case 68:
{
return alloy_sym(yytext(), CompSym.DISJ);
}
case 116:
break;
case 32:
{
return alloy_sym(yytext(), CompSym.SHA);
}
case 117:
break;
case 39:
{
return alloy_sym(yytext(), CompSym.OR);
}
case 118:
break;
case 45:
{
return alloy_sym(yytext(), CompSym.SHR);
}
case 119:
break;
case 84:
{
return alloy_sym(yytext(), CompSym.PRIVATE);
}
case 120:
break;
case 31:
{
return alloy_sym(yytext(), CompSym.ARROW);
}
case 121:
break;
case 33:
{
return alloy_sym(yytext(), CompSym.GTE);
}
case 122:
break;
case 20:
{
return alloy_sym(yytext(), CompSym.CARET);
}
case 123:
break;
case 46:
{
return alloy_sym(yytext(), CompSym.IFF);
}
case 124:
break;
case 69:
{
return alloy_sym(yytext(), CompSym.ELSE);
}
case 125:
break;
case 3:
{
return alloy_sym(yytext(), CompSym.HASH);
}
case 126:
break;
case 12:
{
return alloy_sym(yytext(), CompSym.DOT);
}
case 127:
break;
case 22:
{
return alloy_sym(yytext(), CompSym.BAR);
}
case 128:
break;
case 79:
{
return alloy_sym(yytext(), CompSym.EXPECT);
}
case 129:
break;
case 8:
{
return alloy_sym(yytext(), CompSym.PLUS);
}
case 130:
break;
case 37:
{
return alloy_sym(yytext(), CompSym.LTE);
}
case 131:
break;
case 57:
{
return alloy_sym(yytext(), CompSym.ONE);
}
case 132:
break;
case 73:
{
return alloy_sym(yytext(), CompSym.OPEN);
}
case 133:
break;
case 63:
{
return alloy_hexnum(yytext());
}
case 134:
break;
case 11:
{
return alloy_sym(yytext(), CompSym.GT);
}
case 135:
break;
case 80:
{
return alloy_sym(yytext(), CompSym.MODULE);
}
case 136:
break;
case 14:
{
return alloy_sym(yytext(), CompSym.COLON);
}
case 137:
break;
case 51:
{
return alloy_sym(yytext(), CompSym.SUM);
}
case 138:
break;
case 74:
{
return alloy_sym(yytext(), CompSym.PART);
}
case 139:
break;
case 16:
{
return alloy_sym(yytext(), CompSym.EQUALS);
}
case 140:
break;
case 83:
{
return alloy_sym(yytext(), CompSym.EXTENDS);
}
case 141:
break;
case 26:
{
throw new ErrorSyntax(alloy_here(yytext()), "String literal is missing its closing \" character");
}
case 142:
break;
case 59:
{
return alloy_sym(yytext(), CompSym.FOR);
}
case 143:
break;
case 28:
{
return alloy_num(yytext());
}
case 144:
break;
case 72:
{
return alloy_sym(yytext(), CompSym.IDEN);
}
case 145:
break;
case 15:
{
return alloy_sym(yytext(), CompSym.LT);
}
case 146:
break;
case 17:
{
return alloy_sym(yytext(), CompSym.AT);
}
case 147:
break;
case 34:
{
return alloy_sym(yytext(), CompSym.RANGE);
}
case 148:
break;
case 71:
{
return alloy_sym(yytext(), CompSym.UNIV);
}
case 149:
break;
case 2:
{
return alloy_sym(yytext(), CompSym.NOT);
}
case 150:
break;
case 49:
{
return alloy_sym(yytext(), CompSym.SET);
}
case 151:
break;
case 6:
{
return alloy_sym(yytext(), CompSym.RPAREN);
}
case 152:
break;
case 42:
{
return alloy_sym(yytext(), CompSym.IN);
}
case 153:
break;
case 77:
{
return alloy_sym(yytext(), CompSym.CHECK);
}
case 154:
break;
case 29:
{
return alloy_sym(yytext(), CompSym.AND);
}
case 155:
break;
case 64:
{
return alloy_sym(yytext(), CompSym.SOME);
}
case 156:
break;
case 76:
{
return alloy_sym(yytext(), CompSym.FACT);
}
case 157:
break;
case 10:
{
return alloy_sym(yytext(), CompSym.MINUS);
}
case 158:
break;
case 5:
{
return alloy_sym(yytext(), CompSym.LPAREN);
}
case 159:
break;
case 67:
{
return alloy_sym(yytext(), CompSym.NONE);
}
case 160:
break;
case 18:
{
return alloy_sym(yytext(), CompSym.LBRACKET);
}
case 161:
break;
case 19:
{
return alloy_sym(yytext(), CompSym.RBRACKET);
}
case 162:
break;
case 70:
{
return alloy_sym(yytext(), CompSym.ENUM);
}
case 163:
break;
case 47:
{
return alloy_sym(yytext(), CompSym.ALL);
}
case 164:
break;
case 85:
{
return alloy_sym(yytext(), CompSym.ABSTRACT);
}
case 165:
break;
case 78:
{
return alloy_sym(yytext(), CompSym.ASSERT);
}
case 166:
break;
case 61:
{
throw new ErrorSyntax(alloy_here(yytext()), "String literal cannot be followed by a legal identifier character.");
}
case 167:
break;
case 54:
{
return alloy_sym(yytext(), CompSym.LET);
}
case 168:
break;
case 27:
{
}
case 169:
break;
case 44:
{
throw new ErrorSyntax(alloy_here(yytext()), "Name cannot start with a number.");
}
case 170:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
zzDoEOF();
{
return new Symbol(CompSym.EOF, alloy_here(" "), alloy_here(" "));
}
} else {
zzScanError(ZZ_NO_MATCH);
}
}
}
}
use of edu.mit.csail.sdg.alloy4.ErrorSyntax in project org.alloytools.alloy by AlloyTools.
the class ScopeComputer method sig2scope.
/**
* Sets the scope for a sig; returns true iff the sig's scope is changed by this
* call.
*/
private void sig2scope(Sig sig, int newValue) throws Err {
if (sig.builtin)
throw new ErrorSyntax(cmd.pos, "Cannot specify a scope for the builtin signature \"" + sig + "\"");
if (!(sig instanceof PrimSig))
throw new ErrorSyntax(cmd.pos, "Cannot specify a scope for a subset signature \"" + sig + "\"");
if (newValue < 0)
throw new ErrorSyntax(cmd.pos, "Cannot specify a negative scope for sig \"" + sig + "\"");
int old = sig2scope(sig);
if (old == newValue)
return;
if (old >= 0)
throw new ErrorSyntax(cmd.pos, "Sig \"" + sig + "\" already has a scope of " + old + ", so we cannot set it to be " + newValue);
sig2scope.put((PrimSig) sig, newValue);
rep.scope("Sig " + sig + " scope <= " + newValue + "\n");
}
Aggregations