Lurker News

Comments (144) 66 threads

Earlier comments
ZeroFries#
I like the idea.

Does not seem to handle my main use case however (transforming a schema entry in Rails to a list of symbols).
Eg:
Input:
t.integer "Id"
t.integer "Active"
t.string "Email", null: false
t.string "CryptedPassword", null: false
t.datetime "created_at"
t.datetime "updated_at"
Example:
:Id
Output:
:Id
:Active
:Email
:CryptedPassword
:created
:updated

jay-anderson1 reply#
This is pretty neat. Since were asking for features: smarter date conversions. For instance on the input: '2015-04-24', and for example output: '26 April 2015'. The if another line has '2015-03-01' it would output '1 March 2015'. This seems like a somewhat difficult problem, but it'd be magical if it worked.
mdpopescu#
Anglo-centric only though, it would be impossible to handle non-English month names.
babeard#
Typo on third example on main page: {name: 'Lennon', intrument: 'guitar'} should be instrument.
theunamedguy1 reply#
Great tool, but too bad it can't handle code very well.

An example (converting C++ to C):

    Input:
    void FileStream::write(char* , int);
    void VirtualMachine::cycle(int);

    Example:
    void FileStream_write(char* , int);

    Output:
    void FileStream_write(char* , int);
    void VirtualMachine_cycle(int* , );
Also, is it open-source?
kazinator#
TXR script:

  @(repeat)
  @type @class::@ident(@params);
  @  (output)
  @type @{class}_@ident(@params);
  @  (end)
  @(end)
Do this kind of thing regularly over C code, when it's too much for Vim macros.

I do it out of Vim. That is: first, select a range of text, then pipe it out:

  !txr some_transform_script.txr -
Done. For example, when adding functions to TXR Lisp's library, I start with a declaration like:

  static val foo(val x, val y);
I pipe this through a script which will produce this:

  reg_fun(intern(lit("foo"), user_package), func_n2(foo));
("Intern a symbol called "foo" in the user_package, and register a two-argument function object with this symbol, hosted from the C function foo.")

It's a little complicated:

  @(deffilter sym ("_" "-"))
  @(collect)
  @  (cases)
  @/(static )?/val @fun(void);@(bind arg nil)
  @  (or)
  @/(static )?/val @fun(@(coll)@{type /[^ ,]+/} @{arg /[^ ,)]+/}@(until))@(end));
  @  (end)
  @(output)
    reg_fun(intern(lit("@{fun :filter sym}"), user_package), func_n@(length arg)(@fun));
  @(end)
  @(end)
I filter underscores to dashes, because I want a C function like foo_bar to look like foo-bar in the Lisp dialect. The (void) argument list is handled as a special case.

I need to parse the arguments because the output part needs to know how many there are. Note how "func_n2" is generated, where the 2 comes from the argument count.

Load more comments