1
我寫一個階解析器來解析以下的輸入(x是一個數字): /hdfs://xxx.xx.xx.x:xxxx/path1/file1.jpg+1如何修復使用scala解析器解析路徑中的錯誤?
trait pathIdentifier extends RegexParsers{
def pathIdent: Parser[String] ="""^/hdfs://([\d\.]+):(\d+)/([\w/]+/(\w+\.\w+)$)""".r
}
class ParseExp extends JavaTokenParsers with pathIdentifier {
def expr: Parser[Any] = term~rep("+"~term | "-"~term)
def term: Parser[Any] = factor~rep("*"~factor | "/"~factor)
def factor: Parser[Any] = pathIdent | floatingPointNumber | "("~expr~")"
}
我我得到以下錯誤:
[1.1] failure: `(' expected but `/' found
找不到問題!
@Rubbic解析'(/hdfs://111.22.33.4:5555/path1/file1.jpg+1)'適合我。 –
我得到這個錯誤:-bash:語法錯誤附近意想不到的標記'/hdfs://111.33.50.2:8020/path1/path2/file1.jpg+1'我沒有得到它沒有括號 – Rubbic
'(/ hdfs://111.22.33.4:5555/path1/file1.jpg + 1)'是圓括號內的'expr'(因子分析器的第三個選項)。什麼是你想要解析的確切輸入? –