Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
topydo
Commits
a5c5f625
Commit
a5c5f625
authored
Nov 14, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Precompile match regexes.
parent
392f166b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
15 deletions
+12
-15
topydo/lib/TodoParser.py
topydo/lib/TodoParser.py
+12
-15
No files found.
topydo/lib/TodoParser.py
View file @
a5c5f625
...
@@ -23,6 +23,13 @@ import re
...
@@ -23,6 +23,13 @@ import re
import
Utils
import
Utils
_date_match
=
r'\
d{
4}-\
d{
2}-\
d{
2}'
_completed_head_match
=
re
.
compile
(
r'x ((?P<completionDate>'
+
_date_match
+
') )'
+
'((?P<creationDate>'
+
_date_match
+
') )?(?P<rest>.*)'
)
_normal_head_match
=
re
.
compile
(
r'(\
((?P<p
riority>[A-Z])\
) )?
' + '
((
?
P
<
creationDate
>
' + _date_match + '
)
)
?
(
?
P
<
rest
>
.
*
)
')
_tag_match = re.compile('
(
?
P
<
key
>
[
^
:]
*
):(
?
P
<
value
>
.
*
)
')
_project_match = re.compile(r'
\
+
(
\
S
*
\
w
)
')
_context_match = re.compile(r'
@
(
\
S
*
\
w
)
')
def parse_line(p_string):
def parse_line(p_string):
"""
"""
Parses a single line as can be encountered in a todo.txt file.
Parses a single line as can be encountered in a todo.txt file.
...
@@ -45,18 +52,8 @@ def parse_line(p_string):
...
@@ -45,18 +52,8 @@ def parse_line(p_string):
'
tags
': []
'
tags
': []
}
}
date
=
r'\
d{
4}-\
d{
2}-\
d{
2}'
completed_head = _completed_head_match.match(p_string)
completed_head
=
re
.
match
(
normal_head = _normal_head_match.match(p_string)
r'x ((?P<completionDate>'
+
date
+
') )'
+
'((?P<creationDate>'
+
date
+
') )?(?P<rest>.*)'
,
p_string
)
normal_head
=
re
.
match
(
r'(\
((?P<p
riority>[A-Z])\
) )?
' +
'
((
?
P
<
creationDate
>
' + date + '
)
)
?
(
?
P
<
rest
>
.
*
)
',
p_string
)
rest = p_string
rest = p_string
...
@@ -79,15 +76,15 @@ def parse_line(p_string):
...
@@ -79,15 +76,15 @@ def parse_line(p_string):
rest = normal_head.group('
rest
')
rest = normal_head.group('
rest
')
for word in rest.split():
for word in rest.split():
project =
re.match(r'
\
+
(
\
S
*
\
w
)
',
word)
project =
_project_match.match(
word)
if project:
if project:
result['
projects
'].append(project.group(1))
result['
projects
'].append(project.group(1))
context =
re.match(r'
@
(
\
S
*
\
w
)
',
word)
context =
_context_match.match(
word)
if context:
if context:
result['
contexts
'].append(context.group(1))
result['
contexts
'].append(context.group(1))
tag =
re.match('
(
?
P
<
key
>
[
^
:]
*
):(
?
P
<
value
>
.
*
)
',
word)
tag =
_tag_match.match(
word)
if tag:
if tag:
result['
tags
'].append((tag.group('
key
'), tag.group('
value
')))
result['
tags
'].append((tag.group('
key
'), tag.group('
value
')))
continue
continue
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment