Comments (7)
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.
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.
Thanks!
Original comment by [email protected]
on 17 Oct 2009 at 4:35
from lepl.
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.
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.
Thanks, it's works!
Original comment by [email protected]
on 8 Nov 2009 at 4:25
from lepl.
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)
- Regexp Inverted Ranges Unreliable HOT 1
- LEPL-2.3.2 installed with easy_install gives "ImportError: No module named regexp" error HOT 1
- Error Handling and Tracing HOT 1
- Better graph support HOT 1
- Offside Rule HOT 1
- '*' Operator Fails (Multiple Arguments?) HOT 2
- Cloning loses matchers HOT 2
- Incorrect loop detection HOT 2
- Undo Actions
- Regexp / Line Aware Improvements HOT 11
- Join function not in __all__ list HOT 1
- Node should implement __ne__ as well as __eq__ or use == rather than != in __eq__ HOT 1
- Can't print empty lepl.List objects. HOT 3
- antlr grammar for lepl HOT 1
- infinite loop in case of block related grammar HOT 4
- Incorrect example in offside rule documentation HOT 1
- cannot mix strings and tokens HOT 5
- cannot parse from a file HOT 4
- lepl.String() does not match empty-string: "" HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lepl.