Skip to content

Commit

Permalink
make contributor syntax uniform
Browse files Browse the repository at this point in the history
Related to #5

TODO: refactor duplicated code in tree-parser.rkt
  • Loading branch information
benknoble committed Jul 28, 2023
1 parent e89d243 commit 5cc19e0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
15 changes: 5 additions & 10 deletions dia/attribution2.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Format:
#lang abe/attribution2 exported-attributions-id
- Appraisal tree [N%]
- [contributors] Appraisal tree [N%]
...
Meaning:
Expand All @@ -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.
|#

Expand Down Expand Up @@ -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))))
20 changes: 20 additions & 0 deletions dia/tree-parser.rkt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#lang racket

(provide read-attribution-tree
read-attribution-tree2
read-idea-attribution-tree
read-idea-antecedents-tree)

Expand All @@ -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? _)
Expand Down Expand Up @@ -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:].]+)%\\]"
Expand Down

0 comments on commit 5cc19e0

Please sign in to comment.