Skip to content

Commit

Permalink
Merge pull request #126 from aya-lang/path-ops
Browse files Browse the repository at this point in the history
Path ops: isdir and absolute
  • Loading branch information
nick-paul authored Jan 1, 2025
2 parents 4a02a79 + 6179878 commit a733b30
Showing 1 changed file with 23 additions and 0 deletions.
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

0 comments on commit a733b30

Please sign in to comment.