From cc5790b327fb9c3f39a1d54c99fd69dfa819e7ad Mon Sep 17 00:00:00 2001 From: Ethan Brown Date: Tue, 11 Jun 2013 09:43:48 -0700 Subject: [PATCH] Added printf support. --- README.md | 33 +++++++++++++++++++-------------- jawk.js | 2 ++ package.json | 5 +++-- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 52300c9..481a4ae 100644 --- a/README.md +++ b/README.md @@ -17,17 +17,22 @@ concept of awk (a terse, data-driven language), and implements that with JavaScr JavavScript every day (and if you work in the web world, you probably do), and you love awk, and you're tired of remembering a million syntactic idiosyncracies, well, awk just might be for you. -What's Working / Not Working ----------------------------- - -This list represents a high-level punch-list of what functionality has been implemented, and what functionality -is left to do. - -- [X] BEGIN and END rules -- [X] Regular expression rules -- [X] RS variable -- [X] Field variables ($0 - $n and NF) -- [X] NR and RS variables -- [ ] stdin input -- [ ] Multi-line functions -- [ ] Expression rules (`$1='foo' { print() }`) +What's Working +-------------- + +This list represents a high-level punch-list of what functionality has been implemented. + +- BEGIN and END rules +- Regular expression rules +- RS variable +- Field variables ($0 - $n and NF) +- NR and RS variables +- printf support + +What's Not Working +------------------ + +- stdin input +- Multi-line functions +- Expression rules (`$1='foo' { print() }`) + diff --git a/jawk.js b/jawk.js index 09afd3d..e4c8633 100755 --- a/jawk.js +++ b/jawk.js @@ -2,6 +2,7 @@ var fs = require('fs'), vm = require('vm'), + printf = require('printf'), readlines = require('./lib/readlines').readlines; var opts = require('nomnom') @@ -53,6 +54,7 @@ var jawkContext = vm.createContext({ RS: '\\s+', NR: 0, print: function(s) { console.log( s===undefined ? jawkContext.$0 : s ); }, + printf: function() { console.log( printf.apply( this, arguments ) ); }, length: function(x) { return x===undefined ? jawkContext.$0.length : x.length; } }); diff --git a/package.json b/package.json index 309dde3..af4b91b 100755 --- a/package.json +++ b/package.json @@ -5,10 +5,11 @@ "contributors": [ "Ethan Brown " ], - "version": "0.0.2beta", + "version": "0.0.3beta", "license": "GPL", "dependencies": { - "nomnom": "~1.6" + "nomnom": "~1.6", + "printf": "~0.1" }, "keywords": [ "awk",