-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from benknoble/module-langs-for-source-files
1. Create a set of unstable module langs (suffixed 2) that read trees as the main body of the module (some important modifiers are expected directly after the lang line, though arbitrary whitespace can separate them). This is a first draft to solve #4. 2. Standardize contributor syntax as in #5.
- Loading branch information
Showing
7 changed files
with
216 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#lang racket | ||
|
||
(provide (rename-out [mb #%module-begin]) #%datum #%top #%top-interaction #%app) | ||
|
||
#| (Unstable) Module language for antecedents | ||
Format: | ||
#lang abe/antecedents2 exported-antecedents-id [ideas-module imported-ideas-id] | ||
- antecedents tree [antecedents] | ||
Meaning: | ||
- The body is an "antecedents" tree of roughly the same shape where the leaves | ||
have comma-separated antecedents in place of percentages. | ||
- Attribute antecedents by combining them with imported-ideas-id from | ||
ideas-module, which records the idea appraisals (see #lang abe/ideas2). | ||
- Export (provide) the exported-antecedents-id bound to the final attributions. | ||
|# | ||
|
||
(require syntax/parse/define | ||
abe/dia) | ||
|
||
(define-syntax-parse-rule | ||
(mb export:id {~datum <=} [ideas-mod:expr imported-ideas:id] {~datum <=} tree-data:expr) | ||
(#%module-begin | ||
(provide export) | ||
(require (only-in ideas-mod imported-ideas)) | ||
(define antes 'tree-data) | ||
(define export (make-hash)) | ||
(attribute-antecedents imported-ideas antes export) | ||
(unless (validate-attributions export) | ||
(error 'validate-attributions "bad attributions: ~a" export)))) | ||
|
||
(module reader syntax/module-reader abe/antecedents2 | ||
#:whole-body-readers? #t | ||
#:read reader | ||
#:read-syntax syntax-reader | ||
|
||
(require racket/match | ||
syntax/strip-context | ||
abe/tree-parser) | ||
|
||
(define (syntax-reader src in) | ||
(port-count-lines! in) | ||
(define name (read-syntax src in)) | ||
(unless (symbol? (syntax-e name)) | ||
(raise (exn:fail:read | ||
(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 import (read-syntax src in)) | ||
(match (syntax->datum import) | ||
[(list (not (? keyword?)) (? symbol?)) (void)] | ||
[_ (raise (exn:fail:read | ||
(format "expected [module identifier]\n read: ~s" import) | ||
(current-continuation-marks) | ||
(list (srcloc src (syntax-line name) (syntax-column name) (syntax-position name) (syntax-span name)))))]) | ||
(define tree (read-idea-antecedents-tree in)) | ||
(strip-context #`(#,name <= #,import <= #,tree))) | ||
(define (reader in) | ||
(syntax->datum (syntax-reader #f in)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#lang racket | ||
|
||
(provide (rename-out [mb #%module-begin]) #%datum #%top #%top-interaction #%app) | ||
|
||
#| (Unstable) Module language for attributions | ||
Format: | ||
#lang abe/attribution2 exported-attributions-id | ||
- [contributors] Appraisal tree [N%] | ||
... | ||
Meaning: | ||
- The body is an "appraisal" tree. Roughly, markdown bulleted list in tree form, | ||
with bracketed percentags [N%] at the end of the line. | ||
- Validate appraisals. | ||
- Tally attributions. | ||
- Validate attributions. | ||
- Export (provide) the exported-attributions-id bound to the attributions. | ||
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. | ||
|# | ||
|
||
(require syntax/parse/define | ||
abe/dia) | ||
|
||
(define-syntax-parse-rule | ||
(mb export:id {~datum <=} tree-data:expr) | ||
(#%module-begin | ||
(provide export) | ||
(define tree 'tree-data) | ||
(unless (validate-appraisal tree) | ||
(error 'validate-appraisal "bad appraisal: ~a" tree)) | ||
(define export (make-hash)) | ||
(tally tree node-weight bump #:results export) | ||
(unless (validate-attributions export) | ||
(error 'validate-attributions "bad attributions: ~a" export)))) | ||
|
||
(module reader syntax/module-reader abe/attribution2 | ||
#:whole-body-readers? #t | ||
#:read reader | ||
#:read-syntax syntax-reader | ||
|
||
(require syntax/strip-context | ||
abe/tree-parser) | ||
|
||
(define (syntax-reader src in) | ||
(port-count-lines! in) | ||
(define name (read-syntax src in)) | ||
(unless (symbol? (syntax-e name)) | ||
(raise (exn:fail:read | ||
(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-tree2 in)) | ||
(strip-context #`(#,name <= #,tree))) | ||
(define (reader in) | ||
(syntax->datum (syntax-reader #f in)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#lang racket | ||
|
||
(provide (rename-out [mb #%module-begin]) #%datum #%top #%top-interaction #%app) | ||
|
||
#| (Unstable) Module language for ideas | ||
Format: | ||
#lang abe/ideas2 exported-ideas-id | ||
- Ideas appraisal tree [N%] | ||
Meaning: | ||
- The body is an "appraisal" tree. Roughly, markdown bulleted list in tree | ||
form, with bracketed percentags [N%] at the end of the line. | ||
- Validate appraisals. | ||
- Tally idea attributions. | ||
- Validate attributions. | ||
- Export (provide) the exported-ideas-id bound to the attributions. | ||
|# | ||
|
||
(require syntax/parse/define | ||
abe/dia) | ||
|
||
(define-syntax-parse-rule | ||
(mb export:id {~datum <=} tree-data:expr) | ||
(#%module-begin | ||
(provide export) | ||
(define tree 'tree-data) | ||
(unless (validate-appraisal tree) | ||
(error 'validate-appraisal "bad appraisal: ~a" tree)) | ||
(define export (make-hash)) | ||
(tally tree node-weight bump #:results export) | ||
(unless (validate-attributions export) | ||
(error 'validate-attributions "bad attributions: ~a" export)))) | ||
|
||
(module reader syntax/module-reader abe/ideas2 | ||
#:whole-body-readers? #t | ||
#:read reader | ||
#:read-syntax syntax-reader | ||
|
||
(require syntax/strip-context | ||
abe/tree-parser) | ||
|
||
(define (syntax-reader src in) | ||
(port-count-lines! in) | ||
(define name (read-syntax src in)) | ||
(unless (symbol? (syntax-e name)) | ||
(raise (exn:fail:read | ||
(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-idea-attribution-tree in)) | ||
(strip-context #`(#,name <= #,tree))) | ||
(define (reader in) | ||
(syntax->datum (syntax-reader #f in)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters