Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Incorrect mismatch location reported by RegexParsers #573

Open
@asarkar

Description

@asarkar
implicitdefliteral(s:String):Parser[String]=newParser[String] {defapply(in:Input)= {valsource= in.sourcevaloffset= in.offsetvalstart= handleWhiteSpace(source, offset)vari=0varj= startwhile (i< s.length&& j< source.length&& s.charAt(i)== source.charAt(j)) {      i+=1      j+=1    }if (i== s.length)Success(source.subSequence(start, j).toString, in.drop(j- offset),None)else  {valfound=if (start== source.length())"end of source"else"'"+source.charAt(start)+"'"Failure("'"+s+"' expected but"+found+" found", in.drop(start- offset))    }  }}

Note the error reporting at the end where the index of the mismatch is reported asstart. If the string is"apple", and the input"...apply...", the mismatch is at the character'y', which is pointed to by the variablej, not at the character'a', which is pointed to bystart.

println(parse("apple","apply"))

Failure('apple' expected but 'a' found,CharSequenceReader('a', ...))

A potential fix may be as follows:

valrest= in.drop(start- offset)if (start== source.length())Failure(s"'$s' expected but end of source found", rest)elseFailure(s"'$s' expected but '${source.charAt(j)}' found at index$j", rest)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp