From 2bbc035f5dcc3ecd62724b9d1de0e7e3ea902379 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 20 Nov 2018 14:52:59 -0800 Subject: Simplifying the filesystem code (no longer entangled with nomsupath) and using that to simplify the tools. Now the tools directly take lists of file paths rather than things that might go through nomsupath or directories or get processed by filetype. Use your shell for globbing stuff like `nomsu tools/test.nom core/*.nom` --- tools/replace.nom | 55 +++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) (limited to 'tools/replace.nom') diff --git a/tools/replace.nom b/tools/replace.nom index 1ec8ecc..66ca690 100755 --- a/tools/replace.nom +++ b/tools/replace.nom @@ -9,36 +9,35 @@ use "lib/os.nom" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -%args = (command line args) -%inplace = (no) -if (%args.1 is "-i"): - %inplace = (yes) - %args::remove index 1 +barf "Deprecated." -if ((size of %args) < 3): +if ((size of %args.extra_args) < 3): say "Usage: nomsu tools/replace.nom [-i] tree_to_replace replacement files..." lua> "os.exit(1)" -%pattern = (parse (%args::remove index 1)) -%replacement = (parse (%args::remove index 1)) -for %path in %args: - for %filename in (files for %path): - unless (any [%filename::matches "%.nom$", %filename == "-", %filename == "stdin"]): - do next %filename - %tree = (parse (read file %filename) from %filename) - %tree2 = (%tree with %pattern ~> %replacement) - if (%tree2 == %tree): - say "No changes in \%filename" - do next %filename - - %text = "\ - ..#!/usr/bin/env nomsu -V\(%tree.version or (Nomsu version)) - \(%tree2 as nomsu)" +%pattern = ((%args.extra_args.1) parsed) +%replacement = ((%args.extra_args.2) parsed) +for %filename in %args.extra_args at %i: + if (%i < 3): do next %i + %file = (read file %filename) + unless %file: barf "File does not exist: \%filename" + %nomsu = (NomsuCode from (Source %filename 1 (size of %file)) %file) + %tree = (%nomsu parsed) + # TODO: fix this to use variable substitution + %tree2 = (..) + %tree::map (..) + for %subtree: + if (%subtree == %pattern): + return %replacement + if (%tree2 == %tree): + say "No changes in \%filename" + do next %filename + + %text = ((%tree2 as nomsu)::text) + when: + %args."-i": + say "Replaced in \%filename" + write %text to file %filename - when: - %inplace: - say "Replaced in \%filename" - write %text to file %filename - - else: - say %text + else: + say %text -- cgit v1.2.3