From c1166142083c055f7b081bb29d0492d56672d581 Mon Sep 17 00:00:00 2001 From: Jos van den Oever Date: Mon, 2 Sep 2024 14:15:32 +0200 Subject: [PATCH] Split up description text into smaller tokens so they have lowest precedence Tokens that should appear at the start of a line are now prepended with EOL to make them precise. --- example | 4 ++-- takentaal.g4 | 25 ++++++++++--------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/example b/example index 41968b7..9bcd9a7 100644 --- a/example +++ b/example @@ -14,7 +14,7 @@ This description has # ' " [] symbols and ü © Ð Latin-1 chars. ## {1000} Second task -This is the description of the second task. +This is the description of the {} second task for project 10. * {500} First subtask -- {500} \2nd subtask +- {500} 2nd subtask diff --git a/takentaal.g4 b/takentaal.g4 index 9c42dde..47c94bf 100644 --- a/takentaal.g4 +++ b/takentaal.g4 @@ -17,14 +17,17 @@ grammar takentaal; takentaal : header plan + EOL* ; header : 'takentaal v0.1.0' ; +// Any implicit and explity lexer token that may appear in a text should be listed +// in this definition. text - : (S | CHAR | WORD)+ + : (INT | '{' | '}' | S | CHAR | WORD)+ ; plan @@ -49,7 +52,7 @@ subtask ; amount - : START_AMOUNT S* INT END_AMOUNT + : '{' S* INT '}' | ; @@ -62,23 +65,23 @@ TASK_TOKEN ; SUBTASK_TOKEN - : EOL+ (SUBTASK_NEW_TOKEN | SUBTASK_PARTIAL_TOKEN | SUBTASK_COMPLETE_TOKEN | SUBTASK_OBSOLETE_TOKEN) + : (SUBTASK_NEW_TOKEN | SUBTASK_PARTIAL_TOKEN | SUBTASK_COMPLETE_TOKEN | SUBTASK_OBSOLETE_TOKEN) ; SUBTASK_NEW_TOKEN - : '-' + : EOL+ '-' ; SUBTASK_PARTIAL_TOKEN - : '/' + : EOL+ '/' ; SUBTASK_COMPLETE_TOKEN - : '*' + : EOL+ '*' ; SUBTASK_OBSOLETE_TOKEN - : '!' + : EOL+ '!' ; S @@ -102,14 +105,6 @@ fragment DIGIT : [0-9] ; -START_AMOUNT - : '{' - ; - -END_AMOUNT - : '}' - ; - // Match printable characters, except space which is covered by S CHAR : [!-~\u00A0-\u33FF] // ASCII and UNICODE