128 lines
4.1 KiB
Plaintext
128 lines
4.1 KiB
Plaintext
|
|
use core.accessibility_modifier;
|
||
|
|
use core.identifier;
|
||
|
|
use core.type_system;
|
||
|
|
|
||
|
|
module Directory {
|
||
|
|
// Language extension configuration
|
||
|
|
syntax {
|
||
|
|
type_system.extend({
|
||
|
|
name: "Directory",
|
||
|
|
category: "system_resource",
|
||
|
|
runtime_layer: "low_level",
|
||
|
|
platform_dependent: true,
|
||
|
|
safety_features: {
|
||
|
|
access_control: true,
|
||
|
|
error_handling: true,
|
||
|
|
async_support: true
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// Error types specific to directory operations
|
||
|
|
type DirectoryError {
|
||
|
|
String code;
|
||
|
|
String message;
|
||
|
|
Any context;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Permissions model
|
||
|
|
type DirectoryPermission {
|
||
|
|
Boolean read = False;
|
||
|
|
Boolean write = False;
|
||
|
|
Boolean execute = False;
|
||
|
|
String owner;
|
||
|
|
String group;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Core Directory type with comprehensive system interaction
|
||
|
|
type Directory {
|
||
|
|
String absolute_path;
|
||
|
|
String name;
|
||
|
|
Integer item_count;
|
||
|
|
DirectoryPermission permissions;
|
||
|
|
|
||
|
|
// Core operations with error handling
|
||
|
|
+proc create() -> [Boolean, DirectoryError];
|
||
|
|
+proc exists() -> [Boolean, DirectoryError];
|
||
|
|
+proc delete() -> [Boolean, DirectoryError];
|
||
|
|
+proc move(String destination) -> [Boolean, DirectoryError];
|
||
|
|
+proc copy(String destination) -> [Boolean, DirectoryError];
|
||
|
|
|
||
|
|
// Advanced file system interactions
|
||
|
|
+proc list_contents() -> [String<>, DirectoryError];
|
||
|
|
+proc find(String pattern) -> [String<>, DirectoryError];
|
||
|
|
+proc watch() -> [Runnable, DirectoryError]; // File system watcher
|
||
|
|
}
|
||
|
|
|
||
|
|
// Platform-specific implementation configuration
|
||
|
|
implementation {
|
||
|
|
// Base implementation with platform abstraction
|
||
|
|
+proc create(String path) -> [Directory, DirectoryError] {
|
||
|
|
proc native_create() -> [Directory, DirectoryError] {
|
||
|
|
// Platform-specific directory creation
|
||
|
|
match (SystemPlatform.current()) {
|
||
|
|
Windows { rtn WindowsFS.create_directory(path); }
|
||
|
|
Posix { rtn PosixFS.create_directory(path); }
|
||
|
|
MacOS { rtn MacFS.create_directory(path); }
|
||
|
|
error {
|
||
|
|
rtn DirectoryError(
|
||
|
|
code: "PLATFORM_UNSUPPORTED",
|
||
|
|
message: "Cannot create directory on this platform"
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
rtn native_create();
|
||
|
|
}
|
||
|
|
|
||
|
|
// Sophisticated error handling and async support
|
||
|
|
+proc exists(String path) -> [Boolean, DirectoryError] {
|
||
|
|
proc check_directory() -> [Boolean, DirectoryError] {
|
||
|
|
try {
|
||
|
|
|
||
|
|
} attempt {
|
||
|
|
ok {
|
||
|
|
my.result.set(SystemFS.path_exists(path));
|
||
|
|
my.result.and(SystemFS.is_directory(path));
|
||
|
|
rtn my.result;
|
||
|
|
}
|
||
|
|
error {
|
||
|
|
rtn DirectoryError(
|
||
|
|
code: "ACCESS_DENIED",
|
||
|
|
message: "Cannot access directory",
|
||
|
|
context: path
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
rtn check_directory();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Cross-platform utility functions
|
||
|
|
+fn normalize_path(String path) -> [String];
|
||
|
|
+fn get_current_directory() -> [Directory];
|
||
|
|
+fn get_temp_directory() -> [Directory];
|
||
|
|
|
||
|
|
// Advanced system integration
|
||
|
|
platform {
|
||
|
|
windows {
|
||
|
|
// Windows-specific optimizations
|
||
|
|
+fn get_special_folder(String folder_type) -> [Directory];
|
||
|
|
}
|
||
|
|
|
||
|
|
posix {
|
||
|
|
// Unix/Linux specific methods
|
||
|
|
+fn get_home_directory() -> [Directory];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Security and access control
|
||
|
|
security {
|
||
|
|
+fn validate_access(Directory dir, DirectoryPermission required) -> [Boolean];
|
||
|
|
+fn set_permissions(Directory dir, DirectoryPermission new_permissions) -> [Boolean];
|
||
|
|
}
|
||
|
|
}
|