Пример #1
0
ast_result_t pass_syntax(ast_t** astp, pass_opt_t* options)
{
  assert(astp != NULL);
  ast_t* ast = *astp;
  assert(ast != NULL);

  token_id id = ast_id(ast);
  ast_result_t r = AST_OK;

  switch(id)
  {
    case TK_SEMI:       r = syntax_semi(options, ast); break;
    case TK_TYPE:       r = syntax_entity(options, ast, DEF_TYPEALIAS); break;
    case TK_PRIMITIVE:  r = syntax_entity(options, ast, DEF_PRIMITIVE); break;
    case TK_STRUCT:     r = syntax_entity(options, ast, DEF_STRUCT); break;
    case TK_CLASS:      r = syntax_entity(options, ast, DEF_CLASS); break;
    case TK_ACTOR:      r = syntax_entity(options, ast, DEF_ACTOR); break;
    case TK_TRAIT:      r = syntax_entity(options, ast, DEF_TRAIT); break;
    case TK_INTERFACE:  r = syntax_entity(options, ast, DEF_INTERFACE); break;
    case TK_THISTYPE:   r = syntax_thistype(options, ast); break;
    case TK_ARROW:      r = syntax_arrowtype(options, ast); break;
    case TK_MATCH:      r = syntax_match(options, ast); break;
    case TK_FFIDECL:    r = syntax_ffi(options, ast, false); break;
    case TK_FFICALL:    r = syntax_ffi(options, ast, true); break;
    case TK_ELLIPSIS:   r = syntax_ellipsis(options, ast); break;
    case TK_CONSUME:    r = syntax_consume(options, ast); break;
    case TK_RETURN:
    case TK_BREAK:      r = syntax_return(options, ast, 1); break;
    case TK_CONTINUE:
    case TK_ERROR:      r = syntax_return(options, ast, 0); break;
    case TK_LET:
    case TK_VAR:        r = syntax_local(options, ast); break;
    case TK_EMBED:      r = syntax_embed(options, ast); break;
    case TK_TYPEPARAM:  r = syntax_type_param(options, ast); break;
    case TK_IFDEF:      r = syntax_ifdef(options, ast); break;
    case TK_USE:        r = syntax_use(options, ast); break;
    case TK_LAMBDACAPTURE:
                        r = syntax_lambda_capture(options, ast); break;
    case TK_COMPILE_INTRINSIC:
                        r = syntax_compile_intrinsic(options, ast); break;
    case TK_COMPILE_ERROR:
                        r = syntax_compile_error(options, ast); break;

    case TK_ISO:
    case TK_TRN:
    case TK_REF:
    case TK_VAL:
    case TK_BOX:
    case TK_TAG:        r = syntax_cap(options, ast); break;

    case TK_LAMBDA:     r = syntax_lambda(options, ast); break;
    case TK_OBJECT:     r = syntax_object(options, ast); break;
    case TK_FUN:        r = syntax_fun(options, ast); break;

    case TK_CAP_READ:
    case TK_CAP_SEND:
    case TK_CAP_SHARE:
    case TK_CAP_ALIAS:
    case TK_CAP_ANY:    r = syntax_cap_set(options, ast); break;

    case TK_VALUEFORMALARG:
    case TK_VALUEFORMALPARAM:
      ast_error(options->check.errors, ast,
        "Value formal parameters not yet supported");
      r = AST_ERROR;
      break;

    case TK_CONSTANT:
      ast_error(options->check.errors, ast,
        "Compile time expressions not yet supported");
      r = AST_ERROR;
      break;

    default: break;
  }

  if(is_expr_infix(id))
    r = syntax_infix_expr(options, ast);

  if(ast_checkflag(ast, AST_FLAG_MISSING_SEMI))
  {
    ast_error(options->check.errors, ast,
      "Use a semi colon to separate expressions on the same line");
    r = AST_ERROR;
  }

  return r;
}
Пример #2
0
ast_result_t pass_syntax(ast_t** astp, pass_opt_t* options)
{
  typecheck_t* t = &options->check;

  assert(astp != NULL);
  ast_t* ast = *astp;
  assert(ast != NULL);

  token_id id = ast_id(ast);

  // These node all use the data field as pointers to stuff
  if(id == TK_PROGRAM || id == TK_PACKAGE || id == TK_MODULE)
    return AST_OK;

  if(ast_checkflag(ast, AST_FLAG_TEST_ONLY))
  {
    // Test node, not allowed outside parse pass
    ast_error(ast, "Illegal character '$' found");
    return AST_ERROR;
  }

  ast_result_t r = AST_OK;

  switch(id)
  {
    case TK_SEMI:       r = syntax_semi(ast); break;
    case TK_TYPE:       r = syntax_entity(ast, DEF_TYPEALIAS); break;
    case TK_PRIMITIVE:  r = syntax_entity(ast, DEF_PRIMITIVE); break;
    case TK_STRUCT:     r = syntax_entity(ast, DEF_STRUCT); break;
    case TK_CLASS:      r = syntax_entity(ast, DEF_CLASS); break;
    case TK_ACTOR:      r = syntax_entity(ast, DEF_ACTOR); break;
    case TK_TRAIT:      r = syntax_entity(ast, DEF_TRAIT); break;
    case TK_INTERFACE:  r = syntax_entity(ast, DEF_INTERFACE); break;
    case TK_THISTYPE:   r = syntax_thistype(t, ast); break;
    case TK_ARROW:      r = syntax_arrowtype(ast); break;
    case TK_MATCH:      r = syntax_match(ast); break;
    case TK_FFIDECL:    r = syntax_ffi(ast, false); break;
    case TK_FFICALL:    r = syntax_ffi(ast, true); break;
    case TK_ELLIPSIS:   r = syntax_ellipsis(ast); break;
    case TK_CONSUME:    r = syntax_consume(ast); break;
    case TK_RETURN:
    case TK_BREAK:      r = syntax_return(options, ast, 1); break;
    case TK_CONTINUE:
    case TK_ERROR:      r = syntax_return(options, ast, 0); break;
    case TK_LET:
    case TK_VAR:        r = syntax_local(ast); break;
    case TK_EMBED:      r = syntax_embed(ast); break;
    case TK_PARAM:      r = syntax_param(ast); break;
    case TK_TYPEPARAM:  r = syntax_type_param(ast); break;
    case TK_IFDEF:      r = syntax_ifdef(ast); break;
    case TK_USE:        r = syntax_use(ast); break;
    case TK_LAMBDACAPTURE:
                        r = syntax_lambda_capture(ast); break;
    case TK_COMPILE_INTRINSIC:
                        r = syntax_compile_intrinsic(ast); break;
    case TK_COMPILE_ERROR:
                        r = syntax_compile_error(ast); break;
    default: break;
  }

  if(is_expr_infix(id))
    r = syntax_infix_expr(ast);

  if(ast_checkflag(ast, AST_FLAG_MISSING_SEMI))
  {
    ast_error(ast,
      "Use a semi colon to separate expressions on the same line");
    r = AST_ERROR;
  }

  return r;
}