takentaal/takentaal.g4

128 lines
2.1 KiB
Text
Raw Normal View History

/**
* This file defines the grammar for takentaal.
* It is divided into parser rules (lowercase) and lexer rules (uppercase).
* The parser splits an input into tokens accoring to the lexer rules.
* At any point, all lexer rules are considered. If multiple rules match,
* a lexer rule is chosen as follows:
* - the rule that matches the longest input is chosen
* - any implicit rule, e.g. 'a', is chosen
* - the first defined rule is chosen.
* Since this grammar has to match unquoted texts and text are usually longer
* than other token matches, the TEXT rule disallows many characters as the
* first character to start with.
*/
2024-08-12 10:47:19 +02:00
grammar takentaal;
takentaal
: header
plan
2024-08-12 10:47:19 +02:00
;
header
: 'takentaal v0.1.0' EOL
2024-08-12 10:47:19 +02:00
;
plan
: PLAN_TOKEN S* amount TEXT EOL
description
task+
2024-08-12 10:47:19 +02:00
;
description
: (TEXT EOL)*
2024-08-12 10:47:19 +02:00
;
task
: TASK_TOKEN S* amount TEXT EOL
description
subtask*
2024-08-12 10:47:19 +02:00
;
subtask
: SUBTASK_TOKEN S* amount TEXT EOL
description
2024-08-12 10:47:19 +02:00
;
2024-08-12 10:50:10 +02:00
amount
: START_AMOUNT S* INT END_AMOUNT
|
2024-08-13 12:09:18 +02:00
;
2024-08-12 10:47:19 +02:00
PLAN_TOKEN
: '#'
2024-08-12 10:47:19 +02:00
;
TASK_TOKEN
: '##'
;
SUBTASK_TOKEN
: (SUBTASK_NEW_TOKEN | SUBTASK_PARTIAL_TOKEN | SUBTASK_COMPLETE_TOKEN | SUBTASK_OBSOLETE_TOKEN)
2024-08-12 10:47:19 +02:00
;
SUBTASK_NEW_TOKEN
: '-'
2024-08-12 10:47:19 +02:00
;
SUBTASK_PARTIAL_TOKEN
: '/'
2024-08-12 10:47:19 +02:00
;
SUBTASK_COMPLETE_TOKEN
: '*'
2024-08-12 10:47:19 +02:00
;
SUBTASK_OBSOLETE_TOKEN
: '!'
2024-08-12 10:47:19 +02:00
;
S
: ' ' -> skip
;
2024-08-12 10:47:19 +02:00
WS
: [ ] -> skip
;
EOL
: ' '* '\n'+
2024-08-12 10:47:19 +02:00
;
2024-08-12 10:50:10 +02:00
INT
: DIGIT+
2024-08-12 10:47:19 +02:00
;
fragment DIGIT
: [0-9]
2024-08-27 11:37:18 +02:00
;
START_AMOUNT
: '{'
2024-08-13 12:09:18 +02:00
;
END_AMOUNT
: '}'
2024-08-12 10:47:19 +02:00
;
// all special characters, including ' ' and digits are subtracted from the printable character range
// '!' '#' '-' '/' '*'
fragment STARTCHAR
: ["$-)+-,.:-z|~\u00A0-\u33FF]
;
// A text should not end with a space, so the ENDHAR omits the space
fragment ENDCHAR
: ["-~\u00A0-\u33FF]
2024-08-12 10:47:19 +02:00
;
fragment CHAR
: [ -~\u00A0-\u33FF] // ASCII and UNICODE
;
// A text cannot start with a special character or has to be placed in quotes
TEXT
: STARTCHAR (CHAR* ENDCHAR)?
2024-08-13 12:09:18 +02:00
;