[Jprogramming] canonical pathname
Oleg Kobchenko
olegykj at yahoo.com
Fri Jul 4 14:27:37 HKT 2008
Stack is necessary for parsing nested structures.
Similar patterns for stack,
gerund at .select/
were used for a JSON and Pythonish shift-reduce parsers
by Raul Miller
http://www.jsoftware.com/pipermail/chat/2007-April/000465.html
http://www.jsoftware.com/pipermail/programming/2007-April/005903.html
With this approach our c14n is just
; ]`(}.@])`, at .(('/.';'/..')i.[) / &.|. <;.1 A
/a/b/f
(with '/' reuse from a private message from Rob Hodgkinson).
Here's another simpler exercise: nested parens parser:
??? '(a+(b+c))+d'
+-------------+-+-+
|+-+-+-------+|+|d|
||a|+|+-+-+-+|| | |
|| | ||b|+|c||| | |
|| | |+-+-+-+|| | |
|+-+-+-------+| | |
+-------------+-+-+
I think there was a discussion a few years back,
but don't recall which methods were used. Links welcome.
--- On Thu, 7/3/08, Oleg Kobchenko <olegykj at yahoo.com> wrote:
The stack idea is interesting. Here's a tacit stack version:
A=: '/a/b/c/d/../../e/./f/../../f'
if=: @.
else=: `
eq=: 1 : '(<,m) = ['
; '/'&,each ,else(}.@])if('..'eq)else]if('.'eq)/ &.|. <;._1 A
/a/b/f
--- On Thu, 7/3/08, bill lam <bbill.lam at gmail.com> wrote:
Raul Miller wrote:
> On 7/2/08, Oleg Kobchenko <olegykj at yahoo.com> wrote:
>> I know. It's just an idea. However, I believe canonicalization
>> should be possible with E. split and reassembling.
>
> That's a good point.
>
> And my rxrplc solutions would mess up unc paths.
>
> So, perhaps:
>
> pfx=: '/' #~ 2 <. i.&0@:=&'/'
> trim1=: (<,'.') -.~ a: -.~ '/' <;._1@, ]
> trim2=: (#~ 0 1 (*. _1&|.)@:-. at E. (<'..')&=)^:_
> trim=: pfx, [:}.@; '/',L:0 trim2 at trim1
>
> trim '/a/b/c/d/../../e/./f/../../f'
> /a/b/f
> trim 'abc/../..'
> ..
> trim '/a/.../././././.'
> /a/...
> trim '//unc/paths/should/../must/remain/valid'
> //unc/paths/must/remain/valid
>
Thank all for providing suggestion. It's good to see what how it works
alternatively. My approach was to tokenise by <;.1, then push everything into
stack except
a. discard token '/.'
b. pop stack for token '/..'
In linux, /.. or /. is just /, The name 'abspath' is used in perl or python.
More information about the Programming
mailing list