I am learning to write a simple parser-combinator. I write the rules from the bottom up and write the block tests to check how I am going. However, I am blocked when using repsep () with a space as a separator.
object MyParser extends RegexParsers { lazy val listVal:Parser[List[String]]=elem('{')<~repsep("""\d+""".r,"""\s+""".r)~>elem('}') }
This rule has been simplified to illustrate the problem. When I feed the parser "{1 2 3}", it always complains that it does not match:
[1.4] Error: `} 'is expected, but 2 found
I am wondering how to write a rule correctly, as I described?
thank
, RegexParsers - . , . (), , - (\s+), val whiteSpace: Regex = ... RegexParsers. - , override def skipWhitespace = false.
RegexParsers
\s+
val whiteSpace: Regex = ...
override def skipWhitespace = false
: , , :
repsep("""\d+""".r,"""\s+""".r)
:
rep("""\d+""".r)
, RegexParsers , , .
, repsep , , , , , ( AST).
repsep
Source: https://habr.com/ru/post/1766688/More articles:Странный выход с Irvine WriteString - assemblyWhy is my asp.net utility recycled when a folder is deleted? - asp.netKill activity in a stream - androidМожно ли остановить UISearchBar от прокрутки в UITableView? - iphonePython 2D Image Generation - pythonErrors in Math.pow in Java - java140 Characters, is it a string or text? - ruby | fooobar.comwhy is my cost-effective injection ruby not working? - ruby | fooobar.comC # EventLog. Delete selected EventLogEntry - c #java.lang.SecurityException: Unable to find login configuration - tomcatAll Articles