{
  "language": "avap",
  "version": "2.0",
  "file_extensions": [".avap"],

  "lexer": {
    "string_delimiters": ["\"", "'"],
    "escape_char": "\\",
    "comment_line": ["///", "//"],
    "comment_block": { "open": "/*", "close": "*/" },
    "line_oriented": true
  },

  "blocks": [
    {
      "name": "function",
      "doc_type": "code",
      "opener_pattern": "^\\s*function\\s+(\\w+)\\s*\\(([^)]*)",
      "closer_pattern": "^\\s*\\}\\s*$",
      "extract_signature": true,
      "signature_template": "function {group1}({group2})"
    },
    {
      "name": "if",
      "doc_type": "code",
      "opener_pattern": "^\\s*if\\s*\\(",
      "closer_pattern": "^\\s*end\\s*\\(\\s*\\)",
      "note": "Closer is end(). The else() marker is an inline separator within the if block, not a block opener."
    },
    {
      "name": "startLoop",
      "doc_type": "code",
      "opener_pattern": "^\\s*startLoop\\s*\\(",
      "closer_pattern": "^\\s*endLoop\\s*\\(\\s*\\)"
    },
    {
      "name": "try",
      "doc_type": "code",
      "opener_pattern": "^\\s*try\\s*\\(\\s*\\)",
      "closer_pattern": "^\\s*end\\s*\\(\\s*\\)",
      "note": "try() closes with end(), same as if(). The exception() command is a statement within the try block."
    }
  ],

  "statements": [
    { "name": "registerEndpoint",  "pattern": "^\\s*registerEndpoint\\s*\\(" },
    { "name": "addVar",            "pattern": "^\\s*addVar\\s*\\(" },
    { "name": "addResult",         "pattern": "^\\s*addResult\\s*\\(" },
    { "name": "addParam",          "pattern": "^\\s*addParam\\s*\\(" },
    { "name": "getQueryParamList", "pattern": "^\\s*getQueryParamList\\s*\\(" },
    { "name": "getListLen",        "pattern": "^\\s*getListLen\\s*\\(" },
    { "name": "itemFromList",      "pattern": "^\\s*itemFromList\\s*\\(" },
    { "name": "variableToList",    "pattern": "^\\s*variableToList\\s*\\(" },
    { "name": "variableFromJSON",  "pattern": "^\\s*variableFromJSON\\s*\\(" },
    { "name": "addVariableToJSON", "pattern": "^\\s*AddvariableToJSON\\s*\\(|^\\s*AddVariableToJSON\\s*\\(", "note": "init.sql uses AddvariableToJSON (lowercase v). Both casings are accepted." },
    { "name": "RequestGet",        "pattern": "^\\s*\\w+\\s*=\\s*RequestGet\\s*\\(|^\\s*RequestGet\\s*\\(" },
    { "name": "RequestPost",       "pattern": "^\\s*\\w+\\s*=\\s*RequestPost\\s*\\(|^\\s*RequestPost\\s*\\(" },
    { "name": "ormDirect",         "pattern": "^\\s*\\w+\\s*=\\s*ormDirect\\s*\\(|^\\s*ormDirect\\s*\\(" },
    { "name": "orm_command",       "pattern": "^\\s*(ormCheckTable|ormCreateTable|ormAccessSelect|ormAccessInsert|ormAccessUpdate)\\s*\\(" },
    { "name": "exception",         "pattern": "^\\s*exception\\s*\\(|^\\s*\\w+\\s*=\\s*exception\\s*\\(", "note": "exception() appears inside try blocks as an error capture statement. Can be used as: exception(var) or var = exception(...)" },
    { "name": "else",              "pattern": "^\\s*else\\s*\\(\\s*\\)", "note": "else() is a flow separator marker inside if() blocks. Not a block opener — the parser handles branching at the if() level." },
    { "name": "end",               "pattern": "^\\s*end\\s*\\(\\s*\\)", "note": "end() closes if() and try() blocks. Handled by the block closer_pattern of those blocks. Listed here as a fallback for standalone end() statements." },
    { "name": "endLoop",           "pattern": "^\\s*endLoop\\s*\\(\\s*\\)", "note": "endLoop() closes startLoop() blocks. Listed here as a fallback for standalone endLoop() statements." },
    { "name": "encodeSHA256",      "pattern": "^\\s*\\w+\\s*=\\s*encodeSHA256\\s*\\(|^\\s*encodeSHA256\\s*\\(" },
    { "name": "encodeMD5",         "pattern": "^\\s*\\w+\\s*=\\s*encodeMD5\\s*\\(|^\\s*encodeMD5\\s*\\(" },
    { "name": "randomString",      "pattern": "^\\s*randomString\\s*\\(" },
    { "name": "replace",           "pattern": "^\\s*replace\\s*\\(" },
    { "name": "getRegex",          "pattern": "^\\s*\\w+\\s*=\\s*getRegex\\s*\\(|^\\s*getRegex\\s*\\(" },
    { "name": "getDateTime",       "pattern": "^\\s*\\w+\\s*=\\s*getDateTime\\s*\\(|^\\s*getDateTime\\s*\\(" },
    { "name": "getTimeStamp",      "pattern": "^\\s*\\w+\\s*=\\s*getTimeStamp\\s*\\(|^\\s*getTimeStamp\\s*\\(" },
    { "name": "stampToDatetime",   "pattern": "^\\s*\\w+\\s*=\\s*stampToDatetime\\s*\\(|^\\s*stampToDatetime\\s*\\(" },
    { "name": "async_command",     "pattern": "^\\s*\\w+\\s*=\\s*go\\s+\\w+\\s*\\(|^\\s*gather\\s*\\(" },
    { "name": "connector",         "pattern": "^\\s*\\w+\\s*=\\s*avapConnector\\s*\\(" },
    { "name": "return",            "pattern": "^\\s*return\\s+\\S" },
    { "name": "modularity",        "pattern": "^\\s*(import|include)\\s+" },
    { "name": "assignment",        "pattern": "^\\s*\\w+\\s*=\\s*" }
  ],

  "semantic_tags": [
    { "tag": "uses_orm",            "pattern": "\\b(ormDirect|ormCheckTable|ormCreateTable|ormAccessSelect|ormAccessInsert|ormAccessUpdate)\\s*\\(" },
    { "tag": "uses_http",           "pattern": "\\b(RequestPost|RequestGet)\\s*\\(" },
    { "tag": "uses_connector",      "pattern": "\\bavapConnector\\s*\\(" },
    { "tag": "uses_async",          "pattern": "\\bgo\\s+\\w+\\s*\\(|\\bgather\\s*\\(" },
    { "tag": "uses_crypto",         "pattern": "\\b(encodeSHA256|encodeMD5)\\s*\\(" },
    { "tag": "uses_auth",           "pattern": "\\b(addParam|_status)\\b" },
    { "tag": "uses_error_handling", "pattern": "\\btry\\s*\\(\\s*\\)" },
    { "tag": "uses_exception",      "pattern": "\\bexception\\s*\\(" },
    { "tag": "uses_loop",           "pattern": "\\bstartLoop\\s*\\(" },
    { "tag": "uses_conditional",    "pattern": "\\bif\\s*\\(" },
    { "tag": "uses_json",           "pattern": "\\b(variableFromJSON|AddvariableToJSON|AddVariableToJSON)\\s*\\(" },
    { "tag": "uses_list",           "pattern": "\\b(variableToList|itemFromList|getListLen)\\s*\\(" },
    { "tag": "uses_regex",          "pattern": "\\bgetRegex\\s*\\(" },
    { "tag": "uses_datetime",       "pattern": "\\b(getDateTime|getTimeStamp|stampToDatetime)\\s*\\(" },
    { "tag": "uses_string_ops",     "pattern": "\\b(randomString|replace|encodeSHA256|encodeMD5)\\s*\\(" },
    { "tag": "uses_return",         "pattern": "^\\s*return\\s+\\S" },
    { "tag": "returns_result",      "pattern": "\\baddResult\\s*\\(" },
    { "tag": "registers_endpoint",  "pattern": "\\bregisterEndpoint\\s*\\(" }
  ]
}
