Newline character as list delimiter?
See original GitHub issueCant figure out how to parse a line by line file (CSV, or other list…)
from pyleri import Choice, Grammar, Keyword, List, Optional, Ref, Regex, Sequence, Token
import os
class MyGrammar(Grammar):
element = Regex(r"\w+")
START = List(element, "\n", opt=True)
grammar = MyGrammar()
result = grammar.parse("word\nword\n").as_str()
print(result)
error at position 5, expecting:
Tried with combination of \n, \n, os.linesep…
No luck
Any idea?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Split string using a newline delimiter with Python [duplicate]
str.split , by default, splits by all the whitespace characters. If the actual string has any other whitespace characters, you might want to...
Read more >Python - Split String by Newline Character
To split a string by newline character in Python, pass the newline character "\n" as a delimiter to the split() function. It returns...
Read more >Python Split String by New Line
We will use re package to split the string with one or more new line characters as delimiter. The regular expression that represents...
Read more >Split a string on newline characters in Python | bobbyhadz
The str.splitlines method splits the string on newline characters and returns a list containing the lines in the string. The method does not...
Read more >Python | Ways to split strings using newline delimiter
Given a string, write a Python program to split strings on the basis of newline delimiter. Given below are a few methods to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Maybe your use-case can be solved with
Repeat
instead of aList
:However, if it get’s more complicated you might run into to problems since
pyleri
handles all white-space (including line breaks) equally. This could be solved rather easy though, for example we could allow a user to define the white-space used in a grammar byRE_WHITESPACE
, like we do withRE_KEYWORDS
.@wqp89324, pyleri is currently using strip without any arguments for handling white-space between nodes.