Skip to content

Commit

Permalink
Fix recognition of multiline summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
jotaen committed Mar 28, 2022
1 parent c1f6520 commit 9eaca84
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 54 deletions.
72 changes: 30 additions & 42 deletions klog.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -63,56 +63,44 @@ contexts:
pop: 99999

# When the line is indented, it’s an entry.
- match: '^{{indentation}}'
push:
- match: '{{duration_positive}}'
scope: constant.numeric meta.klog.duration.positive
push: entry_summary
- match: '{{duration_negative}}'
scope: keyword.control meta.klog.duration.negative
push: entry_summary
- match: '{{range}}'
scope: string.quoted meta.klog.range.closed
push: entry_summary
- match: '{{open_range}}'
scope: string.quoted meta.klog.range.open
push: entry_summary

# Exit on blank line.
- match: '{{blankline}}'
pop: 99999

# Ignore if it doesn’t match an entry value. Otherwise it would
# show an error if the user is still typing the value.
- match: '.*'
pop: 1

# Show error if the line contains something else.
- match: '.*'
- match: '^{{indentation}}{{duration_positive}}(?=\s|$)'
scope: constant.numeric meta.klog.duration.positive
push: entry_summary
- match: '^{{indentation}}{{duration_negative}}(?=\s|$)'
scope: keyword.control meta.klog.duration.negative
push: entry_summary
- match: '^{{indentation}}{{range}}(?=\s|$)'
scope: string.quoted meta.klog.range.closed
push: entry_summary
- match: '^{{indentation}}{{open_range}}(?=\s|$)'
scope: string.quoted meta.klog.range.open
push: entry_summary

# Error if next line doesn’t start with whitespace.
- match: '^[^\s].*'
scope: invalid
pop: 99999

entry_summary:
# Parse the remainder of the first line, and continue on the next.
- match: '(?=\s|$)'
push:
- meta_scope: comment meta.klog.summary.text
- include: tag
- meta_scope: comment meta.klog.summary.text
- include: tag

# Exit on blank line.
- match: '{{blankline}}'
pop: 99999

# When it’s indented multiple times, it’s a multiline
# entry summary.
- match: '^{{indentation}}\s'
# Exit on blank line.
- match: '{{blankline}}'
pop: 99999

# Exit otherwise.
- match: '^'
pop: 3
# Exit if next line is indented just once.
# It’s important to work with the `\1` matcher, otherwise
# it wouldn’t handle the indendation style correctly.
# `\1` can only be used in conjunction with `pop`, not `push`.
- match: '^(?=\1[^\s])'
pop: 1

# Show error, if the continuation on the first line is invalid.
- match: '.*'
# Error if next line doesn’t start with whitespace.
- match: '^[^\s].*'
scope: invalid
pop: 99999

tag:
- match: '\#[\p{L}\d_]+'
Expand Down
41 changes: 29 additions & 12 deletions resources/test.klg
Original file line number Diff line number Diff line change
@@ -1,37 +1,54 @@
2022-01-01 (5h!)
Test #record with #tags. No should-total -> (5h!)
This is an all-valid record.
This is an all-valid record. It’s indented with tabs.
4h <- no #duration!
0m
0h
10m
22h
3h12m
22h -1h
3h12m 3h12m
4h Do #something No should-total -> (5h!)
4h <- this is continued summary text,
and not the next #entry!
And so is this.
4h
Multiline #summaries can
also start
on the next line.
4h30m Do #something
+4h30m #Do something
+4h30m #Do something <- summary is separated by one tab
-1h20m
-1h Test
0:00 - 1:00
04:00-17:00 asdf #foo_bar
<4:00 - 17:00> asdf #foo #bar
4:00am - 5:00pm asdf
4:00am - 5:00pm 1:00 - 2:00
4:00am-5:00pm>
15:00>-? Foo
15:00 - ??? Foo

2022-01-01
This record is indented with 2 spaces.
4h <- This is an entry value.
4h <- this is continues summary text.
This record is #indented with 2 spaces.
4h <- This is an #entry value.
4h <- this is continued #summary text.
-3h But this is an #entry again.

2022-01-01
This record is indented with 3 spaces.
4h <- Entry value.
4h <- Continued summary text.
-3h Entry value.

2022-01-01
This record is indented with 4 spaces.
4h <- Entry value.
4h <- Continued summary text.
-3h <- Entry value.

2022-01-01
This record is indented with tabs.
4h <- Entry value.
4h <- Continued summary text.
-3h <- Entry value.

2022-01-01
2022-01-01
^^^^^^^^^^ This is summary, not a date.

Expand All @@ -43,6 +60,6 @@ This record is indented with 2 spaces.
1999/01/01 Unrecognised: Headline cannot contain arbitrary text.
a Illegal: record summary lines cannot start with whitespace.
5h Illegal: First indentation must be once.
4hfoo Illegal: no space between value and summary.
asdf 4h Unrecognised, if the value is invalid. (This is not marked as illegal, though.)
4hfoo Unrecognised: for the same reason as above.
a Illegal: cannot have un-indented line after entries.

0 comments on commit 9eaca84

Please sign in to comment.