Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lepl.functions.String bug #14

Closed
GoogleCodeExporter opened this issue Apr 17, 2015 · 7 comments
Closed

lepl.functions.String bug #14

GoogleCodeExporter opened this issue Apr 17, 2015 · 7 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
>> print String().parse('"line1\\\nline2"')
>> ['line1\\\nline2']

What is the expected output? What do you see instead?
['line1line2']

What version of the product are you using? On what operating system?
Ubuntu 9.04/python2.6.2/lepl3.3

Thanks!

Original issue reported on code.google.com by aachu...@gmail.com on 15 Oct 2009 at 6:53

@GoogleCodeExporter
Copy link
Author

So the idea is that you want the newline to be dropped? (Just trying to 
understand
what the issue is).

Thanks, Andrew

Original comment by acooke....@gmail.com on 15 Oct 2009 at 10:10

@GoogleCodeExporter
Copy link
Author

I haven't forgotten this - I'm still working out what the best thing to do is 
(I'm
not sure this is a bug, particularly, because it's what I would expect to 
happen, but
I can see what you want, and there should be a way to do that (and there are 
other
related issues that this has started me worrying about)).

But this weekend I hope to at least post some kind fo work-around.

Andrew

Original comment by acooke....@gmail.com on 17 Oct 2009 at 1:00

@GoogleCodeExporter
Copy link
Author

Thanks!

Original comment by aachu...@gmail.com on 17 Oct 2009 at 4:35

@GoogleCodeExporter
Copy link
Author


Here are a couple of alternatives.  The first probably *isn't* what you want - 
it
refuses to match multiple lines.  The second *is* what you want, I think.

{{{
def String1(quote='"', escape='\\', exclude='\n'):
    '''
    This won't match newlines (will fail rather than match multiple lines).
    '''
    q = Literal(quote)
    content = AnyBut(Or(q, Any(exclude)))
    if escape:
        content = Or(content, And(Drop(escape), q))
    content = Repeat(content, add_=True)
    return And(Drop(q), content, Drop(q))

def String2(quote='"', escape='\\', ignore='\n'):
    '''
    This will ignore (drop) newlines.
    '''
    q = Literal(quote)
    content = AnyBut(Or(q, Any(ignore)))
    if escape:
        content = Or(content, And(Drop(escape), q))
    content = Or(content, Drop(Any(ignore)))
    content = Repeat(content, add_=True)
    return And(Drop(q), content, Drop(q))
}}}
{{{
>>> String2().parse('"line1\nline2"')
['line1line2']
}}}

I'll add something like this in the next release (changing from bug to 
enhancement).
 Even better would be a regular expression based version, since that could be used
for tokens.  I'll work on it.

Andrew

Original comment by acooke....@gmail.com on 18 Oct 2009 at 8:06

  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

Oh, ignore the wiki markup (the {{{}}} stuff).

And here's another way to work round it:

>>> string = String() > (lambda x: x[0].replace("\n", ""))
>>> string.parse('"line1\nline2"')
['line1line2']

Original comment by acooke....@gmail.com on 18 Oct 2009 at 8:09

@GoogleCodeExporter
Copy link
Author

Thanks, it's works!

Original comment by aachu...@gmail.com on 8 Nov 2009 at 4:25

@GoogleCodeExporter
Copy link
Author

I just added String1 and String2 above as SingleLineString and SkipString to 
Lepl 4.

Original comment by acooke....@gmail.com on 2 Apr 2010 at 11:55

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant