Examples of ErrorSyntax


Examples of edu.mit.csail.sdg.alloy4.ErrorSyntax

      if (body.errors.size()>0) throw body.errors.pick(); else return body;
   }

   /** Throw an exception if the name is already used, or has @ or /, or is univ/Int/none. */
   private void dup(Pos pos, String name, boolean checkSig) throws Err {
      if (name.length()==0)     throw new ErrorSyntax(pos, "Name cannot be empty");
      if (name.indexOf('@')>=0) throw new ErrorSyntax(pos, "Name cannot contain the \'@\' character");
      if (name.indexOf('/')>=0) throw new ErrorSyntax(pos, "Name cannot contain the \'/\' character");
      if (name.equals("univ"))  throw new ErrorSyntax(pos, "\'univ\' is a reserved keyword.");
      if (name.equals("Int"))   throw new ErrorSyntax(pos, "\'Int\' is a reserved keyword.");
      if (name.equals("none"))  throw new ErrorSyntax(pos, "\'none\' is a reserved keyword.");
      if (checkSig && (params.containsKey(name) || sigs.containsKey(name)))
         throw new ErrorSyntax(pos, "\""+name+"\" is already the name of a sig/parameter in this module.");
   }
View Full Code Here

Examples of edu.mit.csail.sdg.alloy4.ErrorSyntax

         else if (x instanceof Expr) {
            Expr y = (Expr)x;
            msg.append("assertion at ").append(y.pos.toShortString());
         }
      }
      throw new ErrorSyntax(pos, msg.toString());
   }
View Full Code Here

Examples of edu.mit.csail.sdg.alloy4.ErrorSyntax

   /** Returns an unmodifiable copy of the current list of OPEN statements. */
   public ConstList<Open> getOpens() { return ConstList.make(opens.values()); }

   /** Add the "MODULE" declaration. */
   void addModelName(Pos pos, String moduleName, List<ExprVar> list) throws Err {
      if (status>0) throw new ErrorSyntax(pos,
            "The \"module\" declaration must occur at the top,\n" + "and can occur at most once.");
      this.moduleName = moduleName;
      this.modulePos = pos;
      boolean nextIsExact = false;
      if (list!=null) for(ExprVar expr: list) {
View Full Code Here

Examples of edu.mit.csail.sdg.alloy4.ErrorSyntax

      }
   }

   /** Add an OPEN declaration. */
   void addOpen(Pos pos, Pos isPrivate, ExprVar name, List<ExprVar> args, ExprVar alias) throws Err {
      if (status>2) throw new ErrorSyntax(pos, "The \"open\" declaration must occur before any\n" + "sig/pred/fun/fact/assert/check/run command.");
      String as = (alias==null ? "" : alias.label);
      if (name.label.length()==0) throw new ErrorSyntax(name.span(), "The filename cannot be empty.");
      if (as.indexOf('$')>=0) throw new ErrorSyntax(alias==null ? null : alias.span(), "Alias must not contain the \'$\' character");
      if (as.indexOf('@')>=0) throw new ErrorSyntax(alias==null ? null : alias.span(), "Alias must not contain the \'@\' character");
      if (as.indexOf('/')>=0) throw new ErrorSyntax(alias==null ? null : alias.span(), "Alias must not contain the \'/\' character");
      if (as.length()==0) {
         as="open$"+(1+opens.size());
         if (args==null || args.size()==0) {
            for(int i=0; ; i++) {
               if (i>=name.label.length()) { as=name.label; break; }
               char c=name.label.charAt(i);
               if ((c>='a' && c<='z') || (c>='A' && c<='Z')) continue;
               if (i==0) break;
               if (!(c>='0' && c<='9') && c!='_' && c!='\'' && c!='\"') break;
            }
         }
      }
      final TempList<String> newlist = new TempList<String>(args==null ? 0 : args.size());
      if (args!=null) for(int i=0; i<args.size(); i++) {
         ExprVar arg=args.get(i);
         if (arg.label.length()==0)      throw new ErrorSyntax(arg.span(), "Argument cannot be empty.");
         if (arg.label.indexOf('@')>=0throw new ErrorSyntax(arg.span(), "Argument cannot contain the \'@\' chracter.");
         newlist.add(arg.label);
      }
      Open x = opens.get(as);
      if (x!=null) {
         // we allow this, especially because of util/sequniv
         if (x.args.equals(newlist.makeConst()) && x.filename.equals(name.label)) return;
         throw new ErrorSyntax(pos, "You cannot import two different modules\n" + "using the same alias.");
      }
      x = new Open(pos, isPrivate!=null, as, newlist.makeConst(), name.label);
      opens.put(as, x);
   }
View Full Code Here

Examples of edu.mit.csail.sdg.alloy4.ErrorSyntax

         Open missing=null;
         String missingName="";
         for(CompModule mod: modules) for(Open open: mod.opens.values()) {
            CompModule sub = open.realModule;
            if (open.args.size()!=sub.params.size())
               throw new ErrorSyntax(open.pos,
                     "You supplied "+open.args.size()+" arguments to the open statement, but the imported module requires "
                     +sub.params.size()+" arguments.");
            int i=0;
            for(Map.Entry<String,Sig> p: sub.params.entrySet()) {
               Sig old = p.getValue();
               String kn = p.getKey(), vn = open.args.get(i);
               i++;
               Sig vv=mod.getRawSIG(open.pos, vn);
               if (vv==null) {if (old==null) {missing=open; missingName=vn;} continue;}
               if (old==vv) continue;
               if (old!=null) throw new ErrorFatal(open.pos, "Internal error (module re-instantiated with different arguments)");
               if (vv==NONE) throw new ErrorSyntax(open.pos, "You cannot use \"none\" as an instantiating argument.");
               chg=true;
               p.setValue(vv);
               rep.parse("RESOLVE: "+(sub.path.length()==0?"this/":sub.path)+"/"+kn+" := "+vv+"\n");
            }
         }
         if (!chg && missing==null) return;
         if (!chg) throw new ErrorSyntax(missing.pos, "The signature name \""+missingName+"\" cannot be found.");
      }
   }
View Full Code Here

Examples of edu.mit.csail.sdg.alloy4.ErrorSyntax

   /** Add an enumeration. */
   void addEnum(Pos pos, Pos priv, ExprVar name, List<ExprVar> atoms, Pos closingBracket) throws Err {
      ExprVar EXTENDS = ExprVar.make(null, "extends");
      ExprVar THIS = ExprVar.make(null, "this/"+name);
      List<ExprVar> THESE = Arrays.asList(THIS);
      if (atoms==null || atoms.size()==0) throw new ErrorSyntax(pos, "Enumeration must contain at least one name.");
      addSig(name.label, null, null, null, null, WHERE.make(name.pos), ABSTRACT.make(name.pos), PRIVATE.makenull(priv), Attr.ENUM);
      for(ExprVar a:atoms) addSig(a.label, EXTENDS, THESE, null, null, WHERE.make(a.pos), ONE.make(a.pos), PRIVATE.makenull(priv));
      int oldStatus = status;
      status = 0;
      try {
View Full Code Here

Examples of edu.mit.csail.sdg.alloy4.ErrorSyntax

      if (!topo.add(oldS)) throw new ErrorType(pos, "Sig "+oldS+" is involved in a cyclic inheritance.");
      if (oldS instanceof SubsetSig)  {
         List<Sig> parents = new ArrayList<Sig>();
         for(Sig n: ((SubsetSig)oldS).parents) {
            Sig parentAST = u.getRawSIG(n.pos, n.label);
            if (parentAST==null) throw new ErrorSyntax(n.pos, "The sig \""+n.label+"\" cannot be found.");
            parents.add(resolveSig(res, topo, parentAST));
         }
         realSig = new SubsetSig(fullname, parents, oldS.attributes.toArray(new Attr[0]));
      } else {
         Sig sup = ((PrimSig)oldS).parent;
         Sig parentAST = u.getRawSIG(sup.pos, sup.label);
         if (parentAST==null) throw new ErrorSyntax(sup.pos, "The sig \""+sup.label+"\" cannot be found.");
         Sig parent = resolveSig(res, topo, parentAST);
         if (!(parent instanceof PrimSig)) throw new ErrorSyntax(sup.pos, "Cannot extend the subset signature \"" + parent
               + "\".\n" + "A signature can only extend a toplevel signature or a subsignature.");
         PrimSig p = (PrimSig)parent;
         realSig = new PrimSig(fullname, p, oldS.attributes.toArray(new Attr[0]));
      }
      res.new2old.put(realSig, oldS);
View Full Code Here

Examples of edu.mit.csail.sdg.alloy4.ErrorSyntax

   //============================================================================================================================//

   /** Add a MACRO declaration. */
   void addMacro(Pos p, Pos isPrivate, String n, List<ExprVar> decls, Expr v) throws Err {
      if (!Version.experimental) throw new ErrorSyntax(p, "LET declaration is allowed only inside a toplevel paragraph.");
      ConstList<ExprVar> ds = ConstList.make(decls);
      status=3;
      dup(p, n, false);
      for(int i=0; i<ds.size(); i++) for(int j=i+1; j<ds.size(); j++)
         if (ds.get(i).label.equals(ds.get(j).label))
            throw new ErrorSyntax(ds.get(j).span(), "The parameter name \""+ds.get(j).label+"\" cannot appear more than once.");
      Macro ans = new Macro(p, isPrivate, this, n, ds, v);
      Macro old = macros.put(n, ans);
      if (old!=null) { macros.put(n, old); throw new ErrorSyntax(p, "You cannot declare more than one macro with the same name \""+n+"\" in the same file."); }
   }
View Full Code Here

Examples of edu.mit.csail.sdg.alloy4.ErrorSyntax

      if (decls==null) decls=new ArrayList<Decl>(); else decls=new ArrayList<Decl>(decls);
      if (f!=null) decls.add(0, new Decl(null, null, null, Util.asList(ExprVar.make(f.span(), "this")), f));
      for(Decl d:decls) {
         if (d.isPrivate!=null) {
            ExprHasName name = d.names.get(0);
            throw new ErrorSyntax(d.isPrivate.merge(name.pos), "Function parameter \""+name.label+"\" is always private already.");
         }
         if (d.disjoint2!=null) {
            ExprHasName name = d.names.get(d.names.size()-1);
            throw new ErrorSyntax(d.disjoint2.merge(name.pos), "Function parameter \""+name.label+"\" cannot be bound to a 'disjoint' expression.");
         }
      }
      status=3;
      dup(p, n, false);
      ExprHasName dup = Decl.findDuplicateName(decls);
      if (dup!=null) throw new ErrorSyntax(dup.span(), "The parameter name \""+dup.label+"\" cannot appear more than once.");
      Func ans = new Func(p, isPrivate, n, decls, t, v);
      ArrayList<Func> list = funcs.get(n);
      if (list==null) { list = new ArrayList<Func>(); funcs.put(n, list); }
      list.add(ans);
   }
View Full Code Here

Examples of edu.mit.csail.sdg.alloy4.ErrorSyntax

      if (name==null || name.length()==0) name="assert$"+(1+asserts.size());
      dup(pos, name, false);
      Expr old = asserts.put(name, ExprUnary.Op.NOOP.make(value.span().merge(pos), value));
      if (old!=null) {
         asserts.put(name, old);
         throw new ErrorSyntax(pos, "\""+name+"\" is already the name of an assertion in this module.");
      }
      return name;
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.