Reorganize the grammar

- Use START_AMOUNT instead of "{" so it is parsed before TEXT
- Allow only one plan and make the structure hierarchical
- Add a header with version number
- Put the amount at the start of the line to simplify parsing and
  make it easier to align amounts
This commit is contained in:
Jos van den Oever 2024-08-29 17:47:12 +02:00
parent 5298c9e97a
commit 6a68ed3140
2 changed files with 68 additions and 69 deletions

13
example
View file

@ -1,19 +1,20 @@
# Full work plan {5000} takentaal v0.1.0
# {5000} Full work plan
This is the description of the entire work plan. This is the description of the entire work plan.
## First task {1000} ## {1000} First task
This is the description of the first task. This is the description of the first task.
This description has # ' " [] symbols and ü © Ð Latin-1 chars. This description has # ' " [] symbols and ü © Ð Latin-1 chars.
- First subtask {500} - {500} First subtask
/ Second subtask {500} / {500} Second subtask
## Second task {1000} ## Second task {1000}
This is the description of the second task. This is the description of the second task.
* First subtask {500} * {500} First subtask
- Second subtask {500} - {500} Second subtask

View file

@ -1,107 +1,105 @@
grammar takentaal; grammar takentaal;
takentaal takentaal
: (line '\n'+)+ EOF : header
plan
; ;
line header
: plan : 'takentaal v0.1.0' EOL
| task
| subtask
| description
; ;
plan plan
: PLAN_TOKEN TEXT amount? : PLAN_TOKEN S* amount TEXT EOL
; description
task+
task
: TASK_TOKEN TEXT amount?
;
subtask
: subtask_new
| subtask_partial
| subtask_complete
| subtask_obsolete
;
subtask_new
: SUBTASK_NEW_TOKEN TEXT amount?
;
subtask_partial
: SUBTASK_PARTIAL_TOKEN TEXT amount?
;
subtask_complete
: SUBTASK_COMPLETE_TOKEN TEXT amount?
;
subtask_obsolete
: SUBTASK_OBSOLETE_TOKEN TEXT amount?
;
amount
: '{' INT '}'
; ;
description description
: TEXT : (TEXT EOL)*
;
task
: TASK_TOKEN S* amount TEXT EOL
description
subtask*
;
subtask
: SUBTASK_TOKEN S* amount TEXT EOL
description
;
amount
: START_AMOUNT S* INT END_AMOUNT
|
; ;
PLAN_TOKEN PLAN_TOKEN
: '# ' : '#'
; ;
TASK_TOKEN TASK_TOKEN
: '## ' : '##'
;
SUBTASK_TOKEN
: (SUBTASK_NEW_TOKEN | SUBTASK_PARTIAL_TOKEN | SUBTASK_COMPLETE_TOKEN | SUBTASK_OBSOLETE_TOKEN)
; ;
SUBTASK_NEW_TOKEN SUBTASK_NEW_TOKEN
: '- ' : '-'
; ;
SUBTASK_PARTIAL_TOKEN SUBTASK_PARTIAL_TOKEN
: '/ ' : '/'
; ;
SUBTASK_COMPLETE_TOKEN SUBTASK_COMPLETE_TOKEN
: '* ' : '*'
; ;
SUBTASK_OBSOLETE_TOKEN SUBTASK_OBSOLETE_TOKEN
: '! ' : '!'
; ;
S
: ' ' -> skip
;
WS WS
: [ \t]+ -> skip : [ ] -> skip
;
EOL
: '\n'+
; ;
INT INT
: DIGIT+ : DIGIT+
; ;
TEXT DIGIT
: TEXTHEAD TEXTBODY*
;
fragment LETTER
: [a-zA-Z\u0080-\u00FF_]
;
fragment DIGIT
: [0-9] : [0-9]
; ;
fragment TEXTHEAD START_AMOUNT
: LETTER : '{'
| DIGIT
; ;
fragment TEXTBODY END_AMOUNT
: LETTER : '}'
| DIGIT ;
| [\u0021-\u007A\u007C\u007E ] // ASCII without {}
| [\u00A0-\u33FF] // UNICODE STARTCHAR
: [ -"$-/:-\u007A\u007C-\u007E]
;
CHAR
: [ -\u007E\u00A0-\u33FF] // ASCII and UNICODE
;
TEXT
: STARTCHAR CHAR*
; ;