Hacker News new | past | comments | ask | show | jobs | submit login

Oh it can be. Typically, if I need to do some text transformation or extraction, I start by getting sample data and renaming it to a .txr suffix. Then just generalize that data into the TXR pattern that matches it and gets out what is needed.

As an example, I was doing some kernel work and needed patches to conform to the kernel's "checkpatch.pl" script. Unfortunately, this thing outputs diagnostics in a way that Vim's quickfix doesn't understand; I wanted to be able to navigate among the numerous sources of errors in the editor.

First I looked at the checkpatch.pl script hoping that of course they would have the diagnostic output in one place, right? Nope: formatting of messages is scattered throughout the script by cut-and-paste coding.

TXR to the rescue:

Sample output:

   WARNING: line over 80 characters
   #279: FILE: arch/arm/common/knllog.c:1519:
   +static void knllog_dump_backtrace_entry(unsigned long where, unsigned long from

   WARNING: line over 80 characters
   #321: FILE: arch/arm/include/asm/unwind.h:50:
   +extern void unwind_backtrace_callback(struct pt_regs *regs, struct task_struct

   WARNING: line over 80 characters
   #322: FILE: arch/arm/include/asm/unwind.h:51:
   + void dump_backtrace_entry_fn(unsigned long where,

   WARNING: line over 80 characters
   #323: FILE: arch/arm/include/asm/unwind.h:52:
   + unsigned long from,
Quick and easy TXR to the rescue:

  @(repeat)
  @type: @message
  #@code: FILE: @path:@lineno:
  @(output)
  @path:@lineno:@type (#@code):@message
  @(end)
  @(end)
Result (redirected into errors.err, loads with vim -q):

  arch/arm/common/knllog.c:1519:WARNING (#279):line over 80 characters
  arch/arm/include/asm/unwind.h:50:WARNING (#321):line over 80 characters
  arch/arm/include/asm/unwind.h:51:WARNING (#322):line over 80 characters
  arch/arm/include/asm/unwind.h:52:WARNING (#323):line over 80 characters
  arch/arm/include/asm/unwind.h:53:WARNING (#324):line over 80 characters
  arch/arm/kernel/unwind.c:352:ERROR (#337):inline keyword should sit between storage class and type
The nice thing is that we know what the above does when we revisit it six months later.



Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: