Package etch.compiler

Examples of etch.compiler.ParseException


  {
    super( name.name, name.token.beginLine );
    addType( Except.class );
   
    if (args.length > 1)
      throw new ParseException( String.format(
        "Unchecked accepts one optional boolean argument at line %d",
        name.token.beginLine ) );
   
    if (args.length > 0)
    {
      Token arg = args[0];
      if (arg.kind != EtchGrammarConstants.TRUE &&
          arg.kind != EtchGrammarConstants.FALSE)
        throw new ParseException( String.format(
          "Unchecked accepts one optional boolean argument at line %d",
          name.token.beginLine ) );
      unchecked = Boolean.parseBoolean( arg.image );
    }
    else
View Full Code Here


    super( name.name, name.token.beginLine );
    addType( Except.class );
    addType( Struct.class );
   
    if (args.length != 1)
      throw new ParseException( String.format(
        "ToString accepts one string argument at line %d",
        name.token.beginLine ) );
   
    Token arg = args[0];
    if (arg.kind != EtchGrammarConstants.STR)
      throw new ParseException( String.format(
        "ToString accepts one string argument at line %d",
        arg.beginLine ) );
   
    try
    {
      format = parse( arg.image );
    }
    catch ( IOException e )
    {
      throw new ParseException( String.format(
        "ToString: problem with format string at line %d: %s",
        arg.beginLine, e.getMessage() ) );
    }
  }
View Full Code Here

   
    // usage: @Extern(language, name, nameImport, serializer, serializerImport)
    // example: @Extern(java, "java.util.Date", "", "etch.bindings.java.util.DateSerializer", "")
   
    if (args.length != 5)
      throw new ParseException( String.format(
        "usage: @Extern(language, \"xname\", \"xnameImport\", \"serializer\", \"serializerImport\") at line %d",
        name.token.beginLine ) );
   
    language = args[0];
    xname = args[1];
    xnameImport = args[2];
    serializer = args[3];
    serializerImport = args[4];
   
    if (language.kind != EtchGrammarConstants.ID)
      throw new ParseException( String.format(
        "Extern expected language to be <ID> at line %d",
        language.beginLine ) );
   
    if (xname.kind != EtchGrammarConstants.STR)
      throw new ParseException( String.format(
        "Extern expected xname to be <STR> at line %d",
        xname.beginLine ) );
   
    if (xnameImport.kind != EtchGrammarConstants.STR)
      throw new ParseException( String.format(
        "Extern expected xnameImport to be <STR> at line %d",
        xnameImport.beginLine ) );
   
    if (serializer.kind != EtchGrammarConstants.STR)
      throw new ParseException( String.format(
        "Extern expected serializer to be <STR> at line %d",
        serializer.beginLine ) );
   
    if (serializerImport.kind != EtchGrammarConstants.STR)
      throw new ParseException( String.format(
        "Extern expected serializerImport to be <STR> at line %d",
        serializerImport.beginLine ) );
  }
View Full Code Here

    method = args[0];
    if (method.kind != EtchGrammarConstants.ID &&
        method.kind != EtchGrammarConstants.TRUE &&
        method.kind != EtchGrammarConstants.FALSE)
    {
      throw new ParseException( String.format(
        "Authorize method should be identifier, true, or false (but not %s) at line %d",
        method, method.beginLine ) );
    }
   
    if ((method.kind == EtchGrammarConstants.TRUE ||
        method.kind == EtchGrammarConstants.FALSE) && args.length > 1)
    {
      throw new ParseException( String.format(
        "Authorize %d cannot have any args at line %d",
        method, method.beginLine ) );
    }

    this.argList = argsToArgList( args );
View Full Code Here

    if (isMethodTrue() || isMethodFalse())
      return;
   
    Named<?> named = service.get( method.image );
    if (named == null)
      throw new ParseException( String.format(
        "Authorize method name %s is not defined at %d",
          method.image, lineno() ) );
   
    if (!named.isMessage())
      throw new ParseException( String.format(
        "Authorize method name %s is not a method at %d",
        method.image, lineno() ) );
   
    Message authMsg = (Message) named;
   
    if (authMsg.type().type().kind != EtchGrammarConstants.BOOLEAN)
      throw new ParseException( String.format(
        "Authorize method %s result type is not boolean at %d",
        method.image, lineno() ) );
   
    List<Parameter> authParams = authMsg.getParameters();
    if (authParams.size() != argList.size())
      throw new ParseException( String.format(
        "Authorize method %s parameter list size does not match the number of supplied arguments at %d",
        method.image, lineno() ) );
   
    int n = argList.size();
    for (int i = 0; i < n; i++)
    {
      Parameter param = authParams.get( i );
      AuthArg aarg = argList.get( i );
      aarg.setType( param.type() );
      Token arg = aarg.value();
     
//      System.out.printf( "auth method %s param %s = %s\n",
//        method, param.name(), arg );
     
      switch (arg.kind)
      {
        case EtchGrammarConstants.NULL:
          // any parameter value may be specified as null...
          break;
       
        case EtchGrammarConstants.ID:
          // arg is referencing either a parameter of msg or a
          // service constant.
          checkMsgParamOrServiceConst( msg, param, arg, i );
          break;
       
        case EtchGrammarConstants.QID:
          // arg is referencing an enum item (enum.item) or
          // could be trying to reference a field of a
          // parameter of message (param(.field)+).
          checkMsgParamFieldRefOrEnumItem( msg, param, arg, i );
          break;
       
        case EtchGrammarConstants.TRUE:
        case EtchGrammarConstants.FALSE:
          // arg is a boolean constant the parameter better be
          // boolean, too.
          checkBooleanConstant( param, arg, i );
          break;
       
        case EtchGrammarConstants.INTEGER:
          // arg is an integer constant, the parameter better
          // be an integral or floating type and arg better
          // be the right size...
          checkIntegerConstant( param, arg, i );
          break;
       
        case EtchGrammarConstants.OCTAL:
          // arg is an octal constant, the parameter better
          // be an integral or floating type and arg better
          // be the right size...
          checkOctalConstant( param, arg, i );
          break;
       
        case EtchGrammarConstants.HEX:
          // arg is a hex constant, the parameter better
          // be an integral or floating type and arg better
          // be the right size...
          checkHexConstant( param, arg, i );
          break;
       
        case EtchGrammarConstants.BINARY:
          // arg is a binary constant, the parameter better
          // be an integral or floating type and arg better
          // be the right size...
          checkBinaryConstant( param, arg, i );
          break;
       
        case EtchGrammarConstants.DECIMAL:
          // arg is a decimal constant, the parameter better
          // be a floating type and arg better be the right
          // size...
          checkDecimalConstant( param, arg, i );
          break;
       
        case EtchGrammarConstants.STR:
          // arg is a string constant the parameter better be
          // string, too.
          checkStringConstant( param, arg, i );
          break;
       
        default:
          throw new ParseException( String.format(
            "Authorize method %s arg %d unsupported kind (%s) at line %d",
            method.image, i+1, arg, lineno() ) );
      }
    }
  }
View Full Code Here

        throw typeMismatch( param, arg, argNo );
      }
     
      // the named thing is not a constant, so blow chunks.
     
      throw new ParseException( String.format(
        "Authorize method %s arg %d name not a parameter or constant (%s) at line %d",
        method.image, argNo+1, arg, lineno() ) );
    }
   
    // the named thing does not exist, so blow chunks.
   
    throw new ParseException( String.format(
      "Authorize method %s arg %d name unknown (%s) at line %d",
      method.image, argNo+1, arg, lineno() ) );
  }
View Full Code Here

      // it's a parameter, so type of p must be a struct...

      p = getField( service, p, path );
     
      if (p == null)
        throw new ParseException( String.format(
          "Authorize method %s arg %d name does not resolve to a field (%s) at line %d",
          method.image, argNo+1, arg, lineno() ) );
     
      Named<?> pt = p.type().getNamed( service );
      Named<?> paramType = param.type().getNamed( service );
      if (pt == paramType)
        return;

      throw typeMismatch( param, arg, argNo );
    }
   
    // it isn't a parameter, so it must be an enum...
   
    Named<?> named = service.get( name );
    if (named == null)
      throw new ParseException( String.format(
        "Authorize method %s arg %d name unknown (%s) at line %d",
        method.image, argNo+1, arg, lineno() ) );
   
    if (!named.isEnumx())
      throw new ParseException( String.format(
        "Authorize method %s arg %d name not a parameter field or enum (%s) at line %d",
        method.image, argNo+1, arg, lineno() ) );
   
    Enumx e = (Enumx) named;
   
    Item i = e.getItem( path.nextToken() );
    if (i == null)
      throw new ParseException( String.format(
        "Authorize method %s arg %d name not an enum item (%s) at line %d",
        method.image, argNo+1, arg, lineno() ) );
   
    if (path.hasMoreTokens())
      throw new ParseException( String.format(
        "Authorize method %s arg %d name not an enum item (%s) at line %d",
        method.image, argNo+1, arg, lineno() ) );
  }
View Full Code Here

  }

  private ParseException typeMismatch( Parameter param, Token arg, int argNo )
  {
    //if (true) throw new RuntimeException( "type mismatch" );
    return new ParseException( String.format(
      "Authorize method %s parameter %d (%s) type mismatch at line %d",
      method, argNo+1, param.name(), arg.beginLine ) );
  }
View Full Code Here

    Token arg, int argNo ) throws ParseException
  {
    if (value >= min && value <= max)
      return;
   
    throw new ParseException( String.format(
      "Authorize method %s parameter %d (%s) integral value out of range at line %d",
      method, argNo+1, param.name(), arg.beginLine ) );
  }
View Full Code Here

    dvalue = Math.abs( dvalue );
   
    if (dvalue >= min && dvalue <= max)
      return;
   
    throw new ParseException( String.format(
      "Authorize method %s parameter %d (%s) floating value out of range at line %d",
      method, argNo+1, param.name(), arg.beginLine ) );
  }
View Full Code Here

TOP

Related Classes of etch.compiler.ParseException

Copyright © 2018 www.massapicom. 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.