Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path ops: isdir and absolute #126

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/aya/ext/sys/SystemInstructionStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import aya.instruction.named.NamedOperator;
import aya.obj.Obj;
import aya.obj.list.List;
import aya.obj.number.Num;
import aya.util.FileUtils;

public class SystemInstructionStore implements NamedInstructionStore {
Expand Down Expand Up @@ -44,6 +45,17 @@ public void execute(BlockEvaluator blockEvaluator) {
}
}
},

// Is dir?
new NamedOperator("sys.isdir", "true if the path exists and is a directory") {
@Override
public void execute(BlockEvaluator blockEvaluator) {
final String path_str = blockEvaluator.pop().str();
File file = FileUtils.resolvePath(path_str).toFile();
blockEvaluator.push(Num.fromBool(file.exists() && file.isDirectory()));
}
},


// Get working dir
new NamedOperator("sys.wd", "get absolute path of working dir") {
Expand Down Expand Up @@ -154,6 +166,17 @@ public void execute(BlockEvaluator blockEvaluator) {
blockEvaluator.push(List.fromString(FileUtils.resolveHome(arg.str())));
}
},


// Absolute Path
new NamedOperator("sys.abspath", "convert path string to absolute path. Normalize the path if '.' or '..' specifiers exist") {
@Override
public void execute(BlockEvaluator blockEvaluator) {
final String path_str = blockEvaluator.pop().str();
final Path p = FileUtils.resolvePath(path_str).normalize();
blockEvaluator.push(List.fromString( p.toFile().getAbsolutePath()) );
}
},

// Change the prompt text
new NamedOperator("sys.alterprompt", "change the prompt text") {
Expand Down
Loading