Pattern matching

38 views
Skip to first unread message

Steve

unread,
Nov 6, 2012, 4:42:03 AM11/6/12
to loop...@googlegroups.com
Hi

I am trying the following code, which should return a list of html tags.
My thinking is to: 
check for '</'  to find an end tag, which I ignore since there should also be a start tag, just recurse upon the rest following the '>'
check for '<' to find a start tag, which I add to the list, then recurse upon the rest following the '>'
and (currently) ignore everything else.

When run the code just prints and empty list, rather than [html].

#returns lists of tags
test_html(input) =>
   ('</':etag:'>':rest) : test_html(rest)
   ('<':tag:'>':rest) : [tag] + test_html(rest)
   * : []

main ->
   print(test_html(content))
   where content: '<html>123</html>'

Even using '<html>' or '</html>' as content yields the same result: []

Any ideas? It would appear to execute the wildcard case, rather than matching the previous rule.
But I would expect the patterns to be check in the order (top to bottom) they appear in the code.

Thanks for any help!
Steve

Dhanji R. Prasanna

unread,
Nov 8, 2012, 1:55:26 AM11/8/12
to loop...@googlegroups.com
Hi, let me investigate--seems odd. Did you look at the test case for pattern matching? It does a similar thing with parsing new lines.

Steve

unread,
Nov 8, 2012, 3:23:48 AM11/8/12
to loop...@googlegroups.com
Hi

I think it has to do with using '>' in both patterns. When I remove one of the pattern matching lines I get the expected result.
I used the flag to dump the generated byte code and not being familar with byte code used a tool to decompile.
It did look pretty weird! Strangely the code only seemed to be testing for '>'?

Stephan
Reply all
Reply to author
Forward
0 new messages