From 5cc19e054a1ad57240e33284598b0ae27fb8732e Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Thu, 1 Jun 2023 12:56:38 -0400 Subject: [PATCH] make contributor syntax uniform Related to https://github.com/drym-org/dia/issues/5 TODO: refactor duplicated code in tree-parser.rkt --- dia/attribution2.rkt | 15 +++++---------- dia/tree-parser.rkt | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/dia/attribution2.rkt b/dia/attribution2.rkt index 0cb7efc..8f390e9 100644 --- a/dia/attribution2.rkt +++ b/dia/attribution2.rkt @@ -7,7 +7,7 @@ Format: #lang abe/attribution2 exported-attributions-id - - Appraisal tree [N%] + - [contributors] Appraisal tree [N%] ... Meaning: @@ -19,14 +19,9 @@ with bracketed percentags [N%] at the end of the line. - Validate attributions. - Export (provide) the exported-attributions-id bound to the attributions. -To identify attributions, the first sequence of non-space characters after a -bullet is used. For capital, this means that descriptive bullets without a -project name should be given a faux project name. - -Additionally, a sequence of non-space characters followed by the text " and " -and another sequence of non-space characters is considered an attributive "pair" -and is attributed as a single unit, to account for teamwork. Groups of sizes -larger than 2 are not yet supported. +To identify attributions, contributors are listed, comma-separated, in +[square-brackets] at the beginning of a bullet. This holds for labor, too, to +name the project but permit additional description. |# @@ -61,7 +56,7 @@ larger than 2 are not yet supported. (format "expected identifier\n read: ~s" name) (current-continuation-marks) (list (srcloc src (syntax-line name) (syntax-column name) (syntax-position name) (syntax-span name)))))) - (define tree (read-attribution-tree in)) + (define tree (read-attribution-tree2 in)) (strip-context #`(#,name <= #,tree))) (define (reader in) (syntax->datum (syntax-reader #f in)))) diff --git a/dia/tree-parser.rkt b/dia/tree-parser.rkt index ed9c628..8106daf 100644 --- a/dia/tree-parser.rkt +++ b/dia/tree-parser.rkt @@ -1,6 +1,7 @@ #lang racket (provide read-attribution-tree + read-attribution-tree2 read-idea-attribution-tree read-idea-antecedents-tree) @@ -25,6 +26,12 @@ corresponding kind of tree. (make-indent-based-tree (flow (regexp-replace* #px"[[:blank:]]" _ " "))) (tree-map label->attribution leaf->attribution))) +(define-flow (read-attribution-tree2 ip) + (~> port->lines + (filter non-empty-string? _) + (make-indent-based-tree (flow (regexp-replace* #px"[[:blank:]]" _ " "))) + (tree-map label->attribution leaf->attribution2))) + (define-flow (read-idea-attribution-tree ip) (~> port->lines (filter non-empty-string? _) @@ -116,6 +123,19 @@ on format. (cons (if name2 (list name1 name2) name1) attribution)])) +(define (leaf->attribution2 x) + (match x + ;; uniform contribution syntax (https://github.com/drym-org/dia/issues/5): + ;; * [comma-separated contributors] contribution [allocation%] + ;; Arbitrary spaces are permitted between start of line and start of + ;; bulleted item. + [(regexp #px"^\\s*\\* \\[([^]]+)\\].*\\[([[:digit:].]+)%\\]" + (list _ contributors (app string->number attribution))) + (cons (~> (contributors) + (string-split ", ") + (if (~> cdr null?) car _)) + attribution)])) + (define (label->attribution x) (match x [(regexp #px"^\\s*\\* (.*) \\[([[:digit:].]+)%\\]"