Accessing Scala Parser regular expression match data

前端 未结 4 1313
孤街浪徒
孤街浪徒 2021-02-08 07:55

I wondering if it\'s possible to get the MatchData generated from the matching regular expression in the grammar below.

object DateParser extends JavaTokenParser         


        
4条回答
  •  北海茫月
    2021-02-08 08:18

    When a Regex is used in a RegexParsers instance, the implicit def regex(Regex): Parser[String] in RegexParsers is used to appoly that Regex to the input. The Match instance yielded upon successful application of the RE at the current input is used to construct a Success in the regex() method, but only its "end" value is used, so any captured sub-matches are discarded by the time that method returns.

    As it stands (in the 2.7 source I looked at), you're out of luck, I believe.

提交回复
热议问题