Quantcast

java.lang.IllegalArgumentException: char range operator '-' only allowed on single character strings

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

java.lang.IllegalArgumentException: char range operator '-' only allowed on single character strings

Dave Berry
Any easy way to track down which rule is causing this error, in Scala. I have a large complicated grammar that has many unicode character ranges specified. They appear to be correct, but apparently they are not.

Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.lang.IllegalArgumentException: char range operator '-' only allowed on single character strings

mathias
Administrator
Hi Dave,

do have a stacktrace for the exception?

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 08.07.2011, at 03:00, Dave Berry [via parboiled users] wrote:

> Any easy way to track down which rule is causing this error, in Scala. I have a large complicated grammar that has many unicode character ranges specified. They appear to be correct, but apparently they are not.
>
> Thanks
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/java-lang-IllegalArgumentException-char-range-operator-only-allowed-on-single-character-strings-tp3150234p3150234.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.lang.IllegalArgumentException: char range operator '-' only allowed on single character strings

Dave Berry
Additional info:

changed the exception to:

  def -(upperBound: String): Rule0 = throw new IllegalArgumentException("char range operator '-' only allowed on single character strings: '"+upperBound+"':"+toString+":"+matcher.getLabel+":"+matcher.getTag)

this now prints out:

java.lang.IllegalArgumentException: char range operator '-' only allowed on single character strings: '?':Rule0: Sequence:Sequence:null

so the upperBound is "?", but no where in my code do I have a rule with the upperBound = "?" or "\u003F"

Do you use the minus function internally?

Here is the stacktrace:

java.lang.IllegalArgumentException: char range operator '-' only allowed on single character strings: '?':Rule0: Sequence:Sequence:null
        at org.parboiled.scala.rules.Rule0.$minus(Rule0.scala:54)
        at net.exaxis.xpqt.xml.XmlParser$$anonfun$Char$1.apply(XmlParser.scala:43)
        at net.exaxis.xpqt.xml.XmlParser$$anonfun$Char$1.apply(XmlParser.scala:43)
        at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
        at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
        at org.parboiled.scala.package$$anonfun$withCurrentRuleLabel$1.apply(package.scala:167)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
        at org.parboiled.scala.package$.withCurrentRuleLabel(package.scala:166)
        at org.parboiled.scala.Parser$class.rule(Parser.scala:74)
        at org.parboiled.scala.Parser$class.rule(Parser.scala:46)
        at net.exaxis.xpqt.xml.XmlParser.rule(XmlParser.scala:38)
        at net.exaxis.xpqt.xml.XmlParser.Char(XmlParser.scala:43)
        at net.exaxis.xpqt.xml.XmlParser$$anonfun$Comment$1.apply(XmlParser.scala:71)
        at net.exaxis.xpqt.xml.XmlParser$$anonfun$Comment$1.apply(XmlParser.scala:71)
        at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
        at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
        at org.parboiled.scala.package$$anonfun$withCurrentRuleLabel$1.apply(package.scala:167)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
        at org.parboiled.scala.package$.withCurrentRuleLabel(package.scala:166)
        at org.parboiled.scala.Parser$class.rule(Parser.scala:74)
        at org.parboiled.scala.Parser$class.rule(Parser.scala:46)
        at net.exaxis.xpqt.xml.XmlParser.rule(XmlParser.scala:38)
        at net.exaxis.xpqt.xml.XmlParser.Comment(XmlParser.scala:71)
        at net.exaxis.xpqt.xml.XmlParser$$anonfun$Misc$1.apply(XmlParser.scala:95)
        at net.exaxis.xpqt.xml.XmlParser$$anonfun$Misc$1.apply(XmlParser.scala:95)
        at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
        at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
        at org.parboiled.scala.package$$anonfun$withCurrentRuleLabel$1.apply(package.scala:167)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
        at org.parboiled.scala.package$.withCurrentRuleLabel(package.scala:166)
        at org.parboiled.scala.Parser$class.rule(Parser.scala:74)
        at org.parboiled.scala.Parser$class.rule(Parser.scala:46)
        at net.exaxis.xpqt.xml.XmlParser.rule(XmlParser.scala:38)
        at net.exaxis.xpqt.xml.XmlParser.Misc(XmlParser.scala:95)
        at net.exaxis.xpqt.xml.XmlParser$$anonfun$prolog$1.apply(XmlParser.scala:85)
        at net.exaxis.xpqt.xml.XmlParser$$anonfun$prolog$1.apply(XmlParser.scala:85)
        at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
        at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
        at org.parboiled.scala.package$$anonfun$withCurrentRuleLabel$1.apply(package.scala:167)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
        at org.parboiled.scala.package$.withCurrentRuleLabel(package.scala:166)
        at org.parboiled.scala.Parser$class.rule(Parser.scala:74)
        at org.parboiled.scala.Parser$class.rule(Parser.scala:46)
        at net.exaxis.xpqt.xml.XmlParser.rule(XmlParser.scala:38)
        at net.exaxis.xpqt.xml.XmlParser.prolog(XmlParser.scala:85)
        at net.exaxis.xpqt.xml.XmlParser$$anonfun$document$1.apply(XmlParser.scala:41)
        at net.exaxis.xpqt.xml.XmlParser$$anonfun$document$1.apply(XmlParser.scala:41)
        at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
        at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
        at org.parboiled.scala.package$$anonfun$withCurrentRuleLabel$1.apply(package.scala:167)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
        at org.parboiled.scala.package$.withCurrentRuleLabel(package.scala:166)
        at org.parboiled.scala.Parser$class.rule(Parser.scala:74)
        at org.parboiled.scala.Parser$class.rule(Parser.scala:46)
        at net.exaxis.xpqt.xml.XmlParser.rule(XmlParser.scala:38)
        at net.exaxis.xpqt.xml.XmlParser.document(XmlParser.scala:41)
        at net.exaxis.xpqt.xml.ns.XmlNameSpaceParser.validateXml(XmlNameSpaceParser.scala:96)
        at net.exaxis.xpqt.xml.BaseXmlTester$$anonfun$testXml$1.apply(BaseXmlTester.scala:49)
        at net.exaxis.xpqt.xml.BaseXmlTester$$anonfun$testXml$1.apply(BaseXmlTester.scala:42)
        at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:34)
        at scala.collection.mutable.ArrayOps.foreach(ArrayOps.scala:38)
        at net.exaxis.xpqt.xml.BaseXmlTester.testXml(BaseXmlTester.scala:42)
        at net.exaxis.xpqt.xml.SunXmlTest.testInvalid(SunXmlTest.scala:44)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
        at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172)
        at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.lang.IllegalArgumentException: char range operator '-' only allowed on single character strings

mathias
Administrator
Hi Dave,

the origin of this error is line 43 of your XmlParser.scala file.
Can you post the relevant portion of your Parser for this?

It really shouldn't be to hard to track this one down...

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 08.07.2011, at 17:38, Dave Berry [via parboiled users] wrote:

> Additional info:
>
> changed the exception to:
>
>   def -(upperBound: String): Rule0 = throw new IllegalArgumentException("char range operator '-' only allowed on single character strings: '"+upperBound+"':"+toString+":"+matcher.getLabel+":"+matcher.getTag)
>
> this now prints out:
>
> java.lang.IllegalArgumentException: char range operator '-' only allowed on single character strings: '?':Rule0: Sequence:Sequence:null
>
> so the upperBound is "?", but no where in my code do I have a rule with the upperBound = "?" or "\u003F"
>
> Do you use the minus function internally?
>
> Here is the stacktrace:
>
> java.lang.IllegalArgumentException: char range operator '-' only allowed on single character strings: '?':Rule0: Sequence:Sequence:null
>         at org.parboiled.scala.rules.Rule0.$minus(Rule0.scala:54)
>         at net.exaxis.xpqt.xml.XmlParser$$anonfun$Char$1.apply(XmlParser.scala:43)
>         at net.exaxis.xpqt.xml.XmlParser$$anonfun$Char$1.apply(XmlParser.scala:43)
>         at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
>         at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
>         at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
>         at org.parboiled.scala.package$$anonfun$withCurrentRuleLabel$1.apply(package.scala:167)
>         at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
>         at org.parboiled.scala.package$.withCurrentRuleLabel(package.scala:166)
>         at org.parboiled.scala.Parser$class.rule(Parser.scala:74)
>         at org.parboiled.scala.Parser$class.rule(Parser.scala:46)
>         at net.exaxis.xpqt.xml.XmlParser.rule(XmlParser.scala:38)
>         at net.exaxis.xpqt.xml.XmlParser.Char(XmlParser.scala:43)
>         at net.exaxis.xpqt.xml.XmlParser$$anonfun$Comment$1.apply(XmlParser.scala:71)
>         at net.exaxis.xpqt.xml.XmlParser$$anonfun$Comment$1.apply(XmlParser.scala:71)
>         at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
>         at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
>         at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
>         at org.parboiled.scala.package$$anonfun$withCurrentRuleLabel$1.apply(package.scala:167)
>         at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
>         at org.parboiled.scala.package$.withCurrentRuleLabel(package.scala:166)
>         at org.parboiled.scala.Parser$class.rule(Parser.scala:74)
>         at org.parboiled.scala.Parser$class.rule(Parser.scala:46)
>         at net.exaxis.xpqt.xml.XmlParser.rule(XmlParser.scala:38)
>         at net.exaxis.xpqt.xml.XmlParser.Comment(XmlParser.scala:71)
>         at net.exaxis.xpqt.xml.XmlParser$$anonfun$Misc$1.apply(XmlParser.scala:95)
>         at net.exaxis.xpqt.xml.XmlParser$$anonfun$Misc$1.apply(XmlParser.scala:95)
>         at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
>         at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
>         at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
>         at org.parboiled.scala.package$$anonfun$withCurrentRuleLabel$1.apply(package.scala:167)
>         at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
>         at org.parboiled.scala.package$.withCurrentRuleLabel(package.scala:166)
>         at org.parboiled.scala.Parser$class.rule(Parser.scala:74)
>         at org.parboiled.scala.Parser$class.rule(Parser.scala:46)
>         at net.exaxis.xpqt.xml.XmlParser.rule(XmlParser.scala:38)
>         at net.exaxis.xpqt.xml.XmlParser.Misc(XmlParser.scala:95)
>         at net.exaxis.xpqt.xml.XmlParser$$anonfun$prolog$1.apply(XmlParser.scala:85)
>         at net.exaxis.xpqt.xml.XmlParser$$anonfun$prolog$1.apply(XmlParser.scala:85)
>         at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
>         at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
>         at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
>         at org.parboiled.scala.package$$anonfun$withCurrentRuleLabel$1.apply(package.scala:167)
>         at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
>         at org.parboiled.scala.package$.withCurrentRuleLabel(package.scala:166)
>         at org.parboiled.scala.Parser$class.rule(Parser.scala:74)
>         at org.parboiled.scala.Parser$class.rule(Parser.scala:46)
>         at net.exaxis.xpqt.xml.XmlParser.rule(XmlParser.scala:38)
>         at net.exaxis.xpqt.xml.XmlParser.prolog(XmlParser.scala:85)
>         at net.exaxis.xpqt.xml.XmlParser$$anonfun$document$1.apply(XmlParser.scala:41)
>         at net.exaxis.xpqt.xml.XmlParser$$anonfun$document$1.apply(XmlParser.scala:41)
>         at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
>         at org.parboiled.scala.Parser$$anonfun$1.apply(Parser.scala:74)
>         at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
>         at org.parboiled.scala.package$$anonfun$withCurrentRuleLabel$1.apply(package.scala:167)
>         at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
>         at org.parboiled.scala.package$.withCurrentRuleLabel(package.scala:166)
>         at org.parboiled.scala.Parser$class.rule(Parser.scala:74)
>         at org.parboiled.scala.Parser$class.rule(Parser.scala:46)
>         at net.exaxis.xpqt.xml.XmlParser.rule(XmlParser.scala:38)
>         at net.exaxis.xpqt.xml.XmlParser.document(XmlParser.scala:41)
>         at net.exaxis.xpqt.xml.ns.XmlNameSpaceParser.validateXml(XmlNameSpaceParser.scala:96)
>         at net.exaxis.xpqt.xml.BaseXmlTester$$anonfun$testXml$1.apply(BaseXmlTester.scala:49)
>         at net.exaxis.xpqt.xml.BaseXmlTester$$anonfun$testXml$1.apply(BaseXmlTester.scala:42)
>         at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:34)
>         at scala.collection.mutable.ArrayOps.foreach(ArrayOps.scala:38)
>         at net.exaxis.xpqt.xml.BaseXmlTester.testXml(BaseXmlTester.scala:42)
>         at net.exaxis.xpqt.xml.SunXmlTest.testInvalid(SunXmlTest.scala:44)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>         at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>         at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>         at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
>         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
>         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>         at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>         at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>         at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
>         at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
>         at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
>         at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
>         at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172)
>         at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104)
>         at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70)
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/java-lang-IllegalArgumentException-char-range-operator-only-allowed-on-single-character-strings-tp3150234p3152193.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.lang.IllegalArgumentException: char range operator '-' only allowed on single character strings

Dave Berry
In reply to this post by mathias
Here is the rule Char that is mentioned in the stacktrace just before the exception is thrown. I had wrapped the Character Ranges in () thinking it might be a precedence problem, but that did nothing.


  def Char = rule {  "\u0009" | "\u000A" | "\u000D" | ("\u0020" - "\uD7FF") | ("\uE000" - "\uFFFD") }
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.lang.IllegalArgumentException: char range operator '-' only allowed on single character strings

Dave Berry
In reply to this post by mathias
Here is line 43.

  def Char = rule {  "\u0009" | "\u000A" | "\u000D" | ("\u0020" - "\uD7FF") | ("\uE000" - "\uFFFD") }
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.lang.IllegalArgumentException: char range operator '-' only allowed on single character strings

mathias
Administrator
In reply to this post by Dave Berry
Hmm, this is weird.
Your rules compiles and runs fine in a test parser of mine.

It might be an implicit conversion problem.
If you want you can simply get rid of the problem by explicitly turning the relevant strings into char matching rules like this:

    def Char = rule {  "\u0009" | "\u000A" | "\u000D" | (ch("\u0020") - "\uD7FF") | (ch("\uE000") - "\uFFFD") }

Or you can track down why in your case the implicit conversion in Parser.scala line 455 does not properly kick in.
Maybe you can trace it with a debugger? (IntelliJ IDEA can do such things...)

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 08.07.2011, at 17:52, Dave Berry [via parboiled users] wrote:

> Here is the rule Char that is mentioned in the stacktrace just before the exception is thrown. I had wrapped the Character Ranges in () thinking it might be a precedence problem, but that did nothing.
>
>
>   def Char = rule {  "\u0009" | "\u000A" | "\u000D" | ("\u0020" - "\uD7FF") | ("\uE000" - "\uFFFD") }
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/java-lang-IllegalArgumentException-char-range-operator-only-allowed-on-single-character-strings-tp3150234p3152231.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.lang.IllegalArgumentException: char range operator '-' only allowed on single character strings

Dave Berry
The problem was between the keyboard and the chair :-)

Since I started with the JSON example I still had the def whitespace declared and the implicit def toRule.
That is what was getting in the way. I had taken care of whitespace in the grammar and still had the implicit def in there and they did not get along.

Here is the jUnit with the Whitespace and toRule. It causes the exact error. Comment them out and it goes away.

Thanks for the help.


package net.exaxis.test

import org.junit._
import Assert._
import org.parboiled.scala._


class CommentParserTest extends Parser {
  def Char = rule {  "\u0009" | "\u000A" | "\u000D" | "\u0020" - "\uD7FF" | "\uE000" - "\uFFFD" }

  def Comment = rule { "" }
 
  def WhiteSpace = rule { zeroOrMore(anyOf(" \n\r\t\f")) }

  /**
   * We redefine the default string-to-rule conversion to also match trailing whitespace if the string ends with
   * a blank, this keeps the rules free from most whitespace matching clutter
   */
  override implicit def toRule(string: String) = {
    if (string.endsWith(" "))
      str(string.trim) ~ WhiteSpace
    else
      str(string)
  }
 
  def validateUnicodeCharacters(uniString: String ) : String = {
    val sb = new StringBuilder
    val parsingResult = RecoveringParseRunner(Comment).run(uniString)

    if (parsingResult.hasErrors){
        for (parseError <- parsingResult.parseErrors){
          sb.append(parseError.getStartIndex)
          sb.append(",")
          sb.append(parseError.getEndIndex)
          sb.append(":")
          sb.append(parseError.getErrorMessage)
          sb.append("\n")
        }
    }
    sb.toString
  }
 
  @Test
  def CommentParserTest()={
    val xml = new StringBuilder
    xml.append("")

    val errors = validateUnicodeCharacters(xml.toString)
      if (errors.length>0){
        fail(errors)
      }
  }

}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.lang.IllegalArgumentException: char range operator '-' only allowed on single character strings

Dave Berry
The comment rule is a rule for xml comments and it looks like it got filtered out on the blog.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.lang.IllegalArgumentException: char range operator '-' only allowed on single character strings

mathias
Administrator
In reply to this post by Dave Berry
Dave,

I'm glad you were able to resolve the issue.

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 08.07.2011, at 21:21, Dave Berry [via parboiled users] wrote:

> The problem was between the keyboard and the chair :-)
>
> Since I started with the JSON example I still had the def whitespace declared and the implicit def toRule.
> That is what was getting in the way. I had taken care of whitespace in the grammar and still had the implicit def in there and they did not get along.
>
> Here is the jUnit with the Whitespace and toRule. It causes the exact error. Comment them out and it goes away.
>
> Thanks for the help.
>
>
> package net.exaxis.test
>
> import org.junit._
> import Assert._
> import org.parboiled.scala._
>
>
> class CommentParserTest extends Parser {
>   def Char = rule {  "\u0009" | "\u000A" | "\u000D" | "\u0020" - "\uD7FF" | "\uE000" - "\uFFFD" }
>
>   def Comment = rule { "" }
>  
>   def WhiteSpace = rule { zeroOrMore(anyOf(" \n\r\t\f")) }
>
>   /**
>    * We redefine the default string-to-rule conversion to also match trailing whitespace if the string ends with
>    * a blank, this keeps the rules free from most whitespace matching clutter
>    */
>   override implicit def toRule(string: String) = {
>     if (string.endsWith(" "))
>       str(string.trim) ~ WhiteSpace
>     else
>       str(string)
>   }
>  
>   def validateUnicodeCharacters(uniString: String ) : String = {
>     val sb = new StringBuilder
>     val parsingResult = RecoveringParseRunner(Comment).run(uniString)
>
>     if (parsingResult.hasErrors){
>         for (parseError <- parsingResult.parseErrors){
>           sb.append(parseError.getStartIndex)
>           sb.append(",")
>           sb.append(parseError.getEndIndex)
>           sb.append(":")
>           sb.append(parseError.getErrorMessage)
>           sb.append("\n")
>         }
>     }
>     sb.toString
>   }
>  
>   @Test
>   def CommentParserTest()={
>     val xml = new StringBuilder
>     xml.append("")
>
>     val errors = validateUnicodeCharacters(xml.toString)
>       if (errors.length>0){
>         fail(errors)
>       }
>   }
>
> }
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/java-lang-IllegalArgumentException-char-range-operator-only-allowed-on-single-character-strings-tp3150234p3152858.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

Loading...