Package etch.compiler

Examples of etch.compiler.ParseException


    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

    super( name.name, name.token.beginLine );
    addType( Message.class );
    addType( Service.class );
   
    if (args.length != 1)
      throw new ParseException( String.format( "AsyncReceiver args length != 1" ) );
   
    Token arg = args[0];
    if (arg.kind != EtchGrammarConstants.ID)
      throw new ParseException( String.format( "AsyncReceiver arg should be identifier: "+arg.image ) );
   
    try
    {
      AsyncReceiverMode m = AsyncReceiverMode.valueOf( arg.image.toUpperCase() );
      if (m == AsyncReceiverMode.POOL)
      {
        System.out.printf(
          "WARNING: deprecated AsyncReceiver mode POOL should be changed to QUEUED at line %d\n",
          arg.beginLine );
        m = AsyncReceiverMode.QUEUED;
      }
      this.mode = m;
    }
    catch ( IllegalArgumentException e )
    {
      throw new ParseException( String.format(
        "AsyncReceiver arg should be one of: "+EnumSet.allOf( AsyncReceiverMode.class ) ) );
    }
  }
View Full Code Here

    super( name.name, name.token.beginLine );
    addType( Message.class );
    addType( Service.class );
   
    if (args.length > 1)
      throw new ParseException( String.format(
        "Oneway 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(
          "Oneway accepts one optional boolean argument at line %d",
          name.token.beginLine ) );
      oneway = Boolean.parseBoolean( arg.image );
    }
    else
View Full Code Here

  public void check() throws ParseException
  {
    Named<?> n = getNamed();
   
    if (n == null)
      throw new ParseException( String.format(
        "undefined exception %s at line %d", name().token.image, name().token.beginLine ) );

    if (!(n instanceof Except))
      throw new ParseException( String.format(
        "%s not an exception at line %d", name().token.image, name().token.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.