How to fix an error in parsing paths using scala parser? -
i writing scala parser parse following input(x number): /hdfs://xxx.xx.xx.x:xxxx/path1/file1.jpg+1
trait pathidentifier extends regexparsers{ def pathident: parser[string] ="""^/hdfs://([\d\.]+):(\d+)/([\w/]+/(\w+\.\w+)$)""".r } class parseexp extends javatokenparsers pathidentifier { def expr: parser[any] = term~rep("+"~term | "-"~term) def term: parser[any] = factor~rep("*"~factor | "/"~factor) def factor: parser[any] = pathident | floatingpointnumber | "("~expr~")" } i getting following error:
[1.1] failure: `(' expected `/' found can't figure out problem!
there 2 problems here. first trying match string starts /hfds input starts /hdfs. secondly regular expression have try match input anchors put (^ , $). means when parser pathident used, try match input until reader has no more values return.
in input there +1 after .jpg , \w not match +, that's why parse failure. should remove them.
running expression expr parser, get:
[1.43] parsed: ((/hdfs://111.22.33.4:5555/path1/file1.jpg~list())~list((+~(1~list())))) which indeed factor followed empty repetition of factors (/hdfs://111.22.33.4:5555/path1/file1.jpg~list())) followed repetition of term + factor (1) followed empty repetition of factors (list((+~(1~list())))).
Comments
Post a Comment