dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / tools / gen_aria_roles / module.lucb
#==============================================================================================
#
# gen_aria_roles - the generator of the ARIA role classes' functions (ARIA/AriaRoles.cpp)
#
# DESCRIPTION:
# Port of Meta/Generators/generate_libweb_aria_roles.py, which turns ARIA/AriaRoles.json
# into AriaRoles.h (a class per role, derived from its super class roles) and
# AriaRoles.cpp (each class's constructors and its overrides of RoleType's virtuals:
# the supported, required and prohibited states and properties, the required context
# roles and owned elements as static hash tables, accessible_name_required,
# children_are_presentational, the implicit values and the name source). It reads
# data/aria/AriaRoles.json and writes src/web/generated/aria/aria_roles.lucb, the Luce of
# AriaRoles.cpp. The classes' structs, vtables and class ids, the Luce of AriaRoles.h, are
# the skeleton generator's (generated/aria/types_aria_roles.lucb).
#
# Usage: gen_aria_roles DATA_DIRECTORY OUTPUT_DIRECTORY, e.g. gen_aria_roles data/aria
# src/web/generated/aria. tests/generated regenerates into build/tests/generated and compares
# with the committed fragment.
#
# Copyright (c) 2023, Jonah Shafran <jonahshafran@gmail.com>
# Copyright (c) 2026-present, the Ladybird developers.
# Copyright (c) 2026 the luce-browser authors.
# SPDX-License-Identifier: BSD-2-Clause (see data/aria/LICENSE)
#
#==============================================================================================
import c
from luce_std import collections, files
## Generate aria_roles.lucb from the JSON of `arguments[1]` into `arguments[2]`.
pub func main(arguments: c.str[]) -> i32!:
if arguments.length != 3:
print("usage: gen_aria_roles DATA_DIRECTORY OUTPUT_DIRECTORY")
return 2
let data_directory = try str(arguments[1])
let output_directory = try str(arguments[2])
let json_path = try c_cat([data_directory, "/AriaRoles.json"])
# the parsed roles borrow the file's bytes, which the whole run keeps
let json_bytes = try files.read(json_path)
let roles_data = try json_parse(json_bytes.value)
let output_path = try c_cat([output_directory, "/aria_roles.lucb"])
try files.write(output_path, (try emit_aria_roles(roles_data)).bytes)
return 0