Giter Site home page Giter Site logo

Comments (7)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 1, 2024
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 [email protected] on 15 Oct 2009 at 10:10

from lepl.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 1, 2024
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 [email protected] on 17 Oct 2009 at 1:00

from lepl.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 1, 2024
Thanks!

Original comment by [email protected] on 17 Oct 2009 at 4:35

from lepl.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 1, 2024

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 [email protected] on 18 Oct 2009 at 8:06

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

from lepl.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 1, 2024
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 [email protected] on 18 Oct 2009 at 8:09

from lepl.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 1, 2024
Thanks, it's works!

Original comment by [email protected] on 8 Nov 2009 at 4:25

from lepl.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 1, 2024
I just added String1 and String2 above as SingleLineString and SkipString to 
Lepl 4.

Original comment by [email protected] on 2 Apr 2010 at 11:55

  • Changed state: Fixed

from lepl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.