diff --git a/melt/assert.scm b/melt/assert.scm deleted file mode 100644 index 8c79276..0000000 --- a/melt/assert.scm +++ /dev/null @@ -1,65 +0,0 @@ -#!chezscheme -(library (melt assert) - (export mmessage - massert) - (import (scheme)) - - ;; there are three level errors - ;; 'error 'warn 'fatal - - ;; 'error: the input is not correct, but the program will continue - ;; 'warn: the input may induce some error - ;; 'fatal: the program will breakdown and quit - - ;; error format: - ;; : --> : || - ;; warn format: - ;; : - ;; fatal format: - ;; : - - - (define-syntax massert - (syntax-rules () - )) - ;; TODO add fatal control - (define (mmessage type msg . args) - (define foreground (string-append (string #\033) "[38;5;")) - (define background (string-append (string #\033) "[48;5;")) - (define restore (string-append (string #\033) "[0m")) - (define argposition (if (not (null? args)) (car args) -1)) - (define er-input (if (not (or (null? args) (null? (cdr args)))) (car (cdr args)) 'er-input)) - (define ex-input (if (not (or (null? args) (null? (cdr (cdr args))))) (car (cdr (cdr args))) 'ex-input)) - (cond - [(eq? type 'error) - (display (string-append foreground "196mError: " restore msg " ")) - (display (string-append foreground "15;1m--> " restore)) - (display argposition) - (display " ") - (display (string-append foreground "15;1m: " restore "get ")) - (display er-input) - (display " ") - (display (string-append foreground "15;1m|| " restore "but expect ")) - (display ex-input) - (display "\n")] - [(eq? type 'warn) - (display (string-append foreground "11m" "Warn: " restore msg "\n"))] - [(eq? type 'fatal) - (display (string-append foreground "196;1m" "FATAL: " restore msg "\n"))] - [else (error 'type "in (melt assert), mmessage's type should be error, warn or fatal")])) - - ;; TODO: add more inspection - (define (massert type msg predict procedure args) - (if (not (apply predict (list (apply procedure args)))) - (cond - [(eq? type 'error) - (mmessage 'error msg 1 'x 'y)] - [(eq? type 'warn) - (mmessage 'warn msg)] - [(eq? type 'fatal) - (mmessage 'fatal msg)]))) - - - - - ) diff --git a/melt/asset.scm b/melt/asset.scm deleted file mode 100644 index 8515ea3..0000000 --- a/melt/asset.scm +++ /dev/null @@ -1,24 +0,0 @@ -(library (melt asset) - (export asset-cp - asset-list-cp) - (import (scheme) - (melt srfi match) - (melt lib file) - (melt structure)) - - (import type-asset) - - ;; for single object - ;; copy the src file to the target-directory - (define (asset-cp asset-obj) - (let ((src-directory (asset-source asset-obj)) - (target-directory (asset-target asset-obj))) - (cp-rf src-directory - (string-append target-directory - (directory-separator-string) - src-directory)))) - - (define (asset-list-cp asset-list) - (map asset-cp asset-list)) - - ) diff --git a/melt/command.scm b/melt/command.scm deleted file mode 100644 index 1fc7bd0..0000000 --- a/melt/command.scm +++ /dev/null @@ -1,66 +0,0 @@ -(library (melt command) - (export %builtin-commands - %user-commands - - add-command - show-commands - command-query) - (import (scheme) - (melt data) - (melt lib console) - (melt structure)) - - (import type-command) - (import type-data) - - (define %builtin-commands (create-data)) - - (define %user-commands (create-data)) - - (define (add-command command . command-data ) - (update-data! (if (null? command-data) - %user-commands - (car command-data)) - (create-data (list (command-name command)) - (list command)))) - - ;; remove one command in command-data - (define (remove-command command . command-data) - (update-data! (if (null? command-data) - %user-commands - (car command-data)) - (list (command-name command)))) - - ;; display command names and its description - (define (show-commands commands) - (define (show-command command) - (gem-display (gem "[2C" "") - (gem "[37;1m" (symbol->string (command-name command))) - ":\n" - (gem "[5C" "") - (gem "[38;5;166m" (command-desc command)) - "\n")) - (do ((command-list (data-keys commands) (cdr command-list))) - ((null? command-list) #t) - (show-command (cdr (assq (car command-list) (data-cont commands)))))) - - ;; query command in commadn-datas, return command ann command help procedure - (define (command-query command command-datas) - (if (memv command (data-keys command-datas)) - (command-proc (cdr (assq command (data-cont command-datas)))) - #f)) - - ;; ---------------------------------------------------------- - ;; ******************** commands insert ********************* - (import (melt command init)) - (import (melt command exec)) - (import (melt command serve)) - - (add-command init - %builtin-commands) - (add-command exec - %builtin-commands) - (add-command serve - %builtin-commands) - - ) diff --git a/melt/command/exec.scm b/melt/command/exec.scm deleted file mode 100644 index c549e50..0000000 --- a/melt/command/exec.scm +++ /dev/null @@ -1,43 +0,0 @@ -(library (melt command exec) - (export exec) - (import (scheme) - (melt structure) - (melt invoke) - (melt glob) - (melt lib console) - (melt utils)) - - (import type-command) - ;; display the build command usage - (define (exec-help) - (gem-display (gem "[37;1m" "melt") - (gem "[38;5;67m" " exe") - (gem "[38;5;253m" " \n")) - (gem-display "If the" - (gem "[38;5;253m" " ") - "is not provided, use" - (gem "[38;5;190m" " melt.scm ") - "instead. \n")) - - ;; the build command - (define exec-cli - (lambda args - (cond - [(null? args) - (gem-display (gem "[37:1m" "please give me the ") - (gem "[38;5;253m" "melt.scm!\n"))] - [else - (let ((chain-file (car args))) - (if (file-exists? chain-file) - (begin - (load chain-file) - (execute-chain %%chain)) - (begin - (format #t "Coundn't find config file !! ~%expect ~a but got nothing !~%" (basename chain-file)))))]))) - - (define exec - (make-command 'exec - "melt command to execute one list actions, mostly build the site." - exec-cli)) - - ) diff --git a/melt/command/init.scm b/melt/command/init.scm deleted file mode 100644 index 3e380ab..0000000 --- a/melt/command/init.scm +++ /dev/null @@ -1,52 +0,0 @@ -(library (melt command init) - (export init) - (import (scheme) - (melt structure) - (melt lib console)) - - (import type-command) - - (define (init-help) - (gem-display (gem "[37;1m" "melt") - (gem "[38;5;67m" " init ") - (gem "[38;5;253m" "name \n")) - (gem-display "if the" - (gem "[38;5;253m" " name ") - "is not provided, it will generate .melt in working directory \n")) - - ;; create some files - (define (initprocedure) - (mkdir ".melt") - (system "touch .melt/settings.scm") - (system "touch .melt/melt.scm") - (mkdir ".melt/fasl") - (mkdir ".melt/resource")) - - - ;; todo - (define (build-welcome-message) - 'todo) - - ;; interface to be invoked in ui - (define init-cli - (lambda args - (cond - [(null? args) - (init-help)] - [(string? (car args)) - (let ((name (car args))) - (cond - [(equal? name "-h") - (init-help)] - [(equal? name ".") - (initprocedure)] - [else - (begin - (mkdir name) - (cd name) - (initprocedure))]))]))) - - (define init - (make-command 'init - "init command to generate basic settings" - init-cli))) diff --git a/melt/command/post.scm b/melt/command/post.scm index c5a5cc8..29e32fe 100644 --- a/melt/command/post.scm +++ b/melt/command/post.scm @@ -5,6 +5,8 @@ (melt uutil) (melt lib console) (melt config) + (melt data) + (melt cell) (melt command)) (define (post data) @@ -32,12 +34,12 @@ (let* ((str-num-sequence (map car (get-md-post-title-list "post"))) (numbers (sort > (map string->number str-num-sequence)))) (if (not (null? title)) - (write-template (car title) - (string-append (config-value-query 'post data) - "/" - (number->string (+ 1 (car numbers))) ".md")) - (gemd:error "please provide a title\n"))))) - + (begin (write-template (car title) + (string-append (data-value-query 'post data) + "/" + (number->string (+ 1 (car numbers))) ".md")) + (gemd:info (string-append "generate new post: " (car title)))) + (gemd:error "please provide a title."))))) (define (write-template title path) (call-with-output-file @@ -52,22 +54,22 @@ ;; command list (define (action-list data) (lambda args - (if (not (null? args)) - (if (equal? (car args) "-h") - (gem:display - (gem:text "[38;5;15m" "A subcommand to list post sequence\n"))) - (list-post data)))) + (cond + [(null? args) + ((list-post data)) + (gemd:info "List complete :)")] + [(and (eq? (length args) 1) (equal? (car args) "-h")) + (gemd:help "A subcommand to list post sequence.")]))) (define (list-post data) (lambda () - (do ((title-list (sort (lambda (pre aft) (string>? (car pre) (car aft))) (get-md-post-title-list (config-value-query 'post data))) + (do ((title-list (sort (lambda (pre aft) (string>? (car pre) (car aft))) (get-md-post-title-list (data-value-query 'post data))) (cdr title-list))) - ((null? title-list) (gem:display (gem:text "[37m" "=====\n"))) + ((null? title-list) (gemd:info "command complete.")) (gemd:item (string-append (gem:text "[38;5;15m" (car (car title-list))) " ==> " - (gem:text "[38;5;15m" (cdr (car title-list))) - "\n"))))) + (gem:text "[38;5;15m" (cdr (car title-list)))))))) ;; ==================================================================== @@ -84,11 +86,23 @@ ;; use external shell to call editor (define (call-editor data) (lambda (number) - (system (string-append (config-value-query 'editor data) - " " - (config-value-query 'post data) - "/" - number ".md")))) - - + (define editor (make-cell (data-value-query 'editor data) + (lambda (value) (if value + (begin + (gemd:info (string-append "Got editor: " value)) + (editor value (lambda (x) x)) + value) + (begin + (gemd:warn "Editor not available") + #f))))) + (gemd:info "invoking external editor ...") + (if (editor) + (begin + (system (string-append (editor) + " " + (data-value-query 'post data) + "/" + number ".md")) + (gemd:info "successfully quit.")) + (gemd:help "Please add editor config in your config file.")))) ) diff --git a/melt/config.ss b/melt/config.ss index 2f510b4..a2c1639 100644 --- a/melt/config.ss +++ b/melt/config.ss @@ -1,30 +1,17 @@ (library (melt config) (export config-update-option! - config-add-option! - config-value-query - config-options-query) + melt:config-options-query) (import (scheme) (melt data)) - ;; update one option or add the option with default value - (define (config-update-option! key value data) - (let ((para (data-guard-query key data))) - (if para - (para value) - (config-add-option! key value data)))) - ;; add one option with default value - (define (config-add-option! key value data) - (update-data! (create-data '(key) (list value)) data)) - - ;; return the value of #f if it doesn't exist - (define (config-value-query key data) - (data-value-query key data)) + (define (config-update-option! key value data) + (update-data! (create-data (list key) (list value)) data)) ;; if no arg provided, return the whole options list - ;; if provide a key(option), return #t if exists and #f otherwise - (define (config-options-query data) + ;; if provide a key(option), return the value if exists and #f otherwise + (define (melt:config-options-query data) (lambda para (cond [(null? para) diff --git a/melt/data.scm b/melt/data.scm deleted file mode 100644 index b5af9b1..0000000 --- a/melt/data.scm +++ /dev/null @@ -1,63 +0,0 @@ -(library (melt data) - (export create-data - update-data! - data-value-query) - (import (scheme) - (melt structure) - (melt utils)) - - (import type-data) - - ;; keys are a list symbols - ;; values are corresponded to the keys - (define create-data - (lambda args - (cond - [(null? args) - (make-data '() - '())] - [else - ((lambda (keys values) - (make-data keys (map cons keys values))) - (car args) - (car (cdr args)))]))) - - ;; it receive three types of args: data-type, alist, keys list. - ;; first two is used to update the data - ;; the third is used to delete the data - (define update-data! - (lambda (data arg) - (cond - [(data? arg) - (do ((keys (data-keys arg) (cdr keys)) - (alist (data-cont arg))) - ((null? keys) (data-cont data)) - (if (memv (car keys) (data-keys data)) - (begin - (update-data! data `(,(car keys))) - (update-data! data `(,(assq (car keys) - alist)))) - (begin - (data-keys-set! data (cons (car keys) - (data-keys data))) - (data-cont-set! data (cons (assq (car keys) alist) - (data-cont data))))))] - [(alist? arg) - (if (not (null? arg)) - (update-data! data (create-data (map car arg) - (map cdr arg))))] - [(list? arg) - (do ((keys arg (cdr keys))) - ((null? keys) (data-cont data)) - (data-cont-set! data (remove (assq (car keys) - (data-cont data)) - (data-cont data))) - (data-keys-set! data (remove (car keys) (data-keys data))))] - [else (display "Didn't do anything!\n")]))) - - (define (data-value-query key data) - (if (memv key (data-keys data)) - (cdr (assq key (data-cont data))) - #f)) - - ) diff --git a/melt/glob.scm b/melt/glob.scm deleted file mode 100644 index 40b69db..0000000 --- a/melt/glob.scm +++ /dev/null @@ -1,20 +0,0 @@ -#!chezscheme -(library (melt glob) - (export %%chain - %%settings) - (import (scheme) - (melt structure) - (melt invoke) - (melt data) - (melt asset)) - - (import type-chain) - (import type-hook) - (import type-site) - - (define %%chain (init-chain #t - (lambda () (display "Building ...\n")) - (create-data))) - - (define %%settings (create-data)) - ) diff --git a/melt/glob.ss b/melt/glob.ss index ca21859..d4a6d0a 100644 --- a/melt/glob.ss +++ b/melt/glob.ss @@ -4,6 +4,7 @@ (export %%invocation %%user-commands %%builtin-commands + %%config user:command-add! user:show-commands user:command-query @@ -11,10 +12,8 @@ inter:command-query inter:show-commands - user:config-query - user:config-add-option! - user:config-update-option! - ) + user:config-options-query + user:config-update-option!) (import (scheme) (melt invoke) (melt data) @@ -24,11 +23,8 @@ ;; /////config ////// (define %%config (create-data)) - (define (user:config-query key) - (config-value-query key %%config)) - - (define (user:config-add-option! key value) - (config-add-option! key value %%config)) + (define user:config-options-query + (melt:config-options-query %%config)) (define (user:config-update-option! key value) (config-update-option! key value %%config)) diff --git a/melt/glob/parser.scm b/melt/glob/parser.scm deleted file mode 100644 index ffac01f..0000000 --- a/melt/glob/parser.scm +++ /dev/null @@ -1,37 +0,0 @@ -(library (melt glob parser) - (export sxml-parser - commonmark-parser) - (import (scheme)) - - (module sxml-parser - [sxml-parser] - - (import (melt asset)) - (import (melt lib file)) - (import (melt utils)) - (import (melt parser)) - - ;; define default sxml parser - (define sxml-parser - (create-parser 'sxml - (lambda (file-name) - (let ((contents ((lambda (file-name) - (define fasl (string-append (cd) ".melt/cache" (directory-separator-string) (basename file-name))) - (define port (if (file-exists? fasl) - (open-file-input-port fasl) - (begin - (mkdir-r (string-append (cd) ".melt/cache")) - (fasl-file file-name fasl) - (open-file-input-port fasl)))) - (define content (eval (fasl-read port))) - (close-input-port port) - content) file-name))) - (list (alist-delete 'content contents) - (cdr (assq 'content contents)))))))) - - (module commonmark-parser - [common-mark] - - (define common-mark "hello")) - - ) diff --git a/melt/invoke.scm b/melt/invoke.scm deleted file mode 100644 index 66a3d89..0000000 --- a/melt/invoke.scm +++ /dev/null @@ -1,230 +0,0 @@ -#!chezscheme -(library (melt invoke) - (export init-chain - execute-chain - chain-data-keys - chain-data-alist - chain-data-query - chain-data-update! - chain-condition-value - chain-hooks-list-query - chain-hooks-update! - - create-hook - hook-execute - get-hook-args - get-hook-proc - get-hook-keys - get-hook-alist - add-hook!) - (import (scheme) - (melt utils) - (melt structure) - (melt data)) - - (import type-hook) - (import type-chain) - (import type-data) - - ;; create hook , if type is data, the arg must be data type - ;; otherwise if type is proc, the arg must be (procdure . args-list) - (define create-hook - (lambda (name type arg) - (cond - [(eq? type 'data) - (make-hook name 'data #f arg)] - [(eq? type 'proc) - (make-hook name 'proc arg #f)] - [else (error type "type must be 'data or 'proc!")]))) - - ;; accept a chain record return the data key list - (define (chain-data-keys chain) - (if (chain? chain) - (data-keys (chain-data chain)) - (error chain "argument should be type chain!"))) - - ;; accept a chain record return the data alist - (define (chain-data-alist chain) - (if (chain? chain) - (data-cont (chain-data chain)) - (error chain "argument should be type chain!"))) - - ;; if the key not in chain keys, return #f - ;; otherwise return the value - (define (chain-data-query key chain) - (if (chain? chain) - (data-value-query key (chain-data chain)) - (error chain "in chain-data-query : invoke.scm"))) - - ;; keys and datas must be a list and must be match - ;; if the keys doesn't exist, create it! - ;; otherwise alter it! - (define chain-data-update! - (case-lambda - [(chain data) - (update-data! (chain-data chain) - data)] - [(chain keys values) - (chain-data-update! chain (create-data keys values))])) - - ;; condition is described in structure - ;; execution is one procedure - ;; data is the data type - (define init-chain - (lambda (condition execution data) - (if (not (data? data)) - (error 'data "in init-chain : data should be 'data type")) - (let ((chain (make-chain condition (list execution) data))) - (cond - [(memv 'chain (chain-data-keys chain)) - (error 'data "You shouldn't use 'chain as key!")] - [(memv 'hooks (chain-data-keys chain)) - (error 'data "You shouldn't use 'hooks as key!")]) - - (chain-data-update! chain '(chain) `(,chain)) - (chain-data-update! chain '(hooks) `(,(create-data '(data proc) - '(() ())))) - chain))) - - ;; execute chain - (define (execute-chain chain) - (if (chain-condition-value chain) - (do ((execute-list (chain-execution chain) (cdr execute-list))) - ((null? execute-list) #t) - ((car execute-list))))) - - ;; if the condition is procedure, execute it to get the value - ;; if the condition is a value, return it - (define (chain-condition-value chain) - (let ((condition (chain-condition chain))) - (cond - [(procedure? condition) - (condition)] - [else condition]))) - - ;; return type proc hook's procedure - (define (get-hook-proc hook) - (if (and (hook? hook) - (eq? 'proc (hook-type hook))) - (car (hook-proc-arg hook)) - (error hook "argument must be hook type or hook must be 'proc type! : get-hook-proc"))) - - ;; return type proc hook's arguments - (define (get-hook-args hook) - (if (and (hook? hook) - (eq? 'proc (hook-type hook))) - (cdr (hook-proc-arg hook)) - (error hook "argument must be hook type or hook must be 'proc type! : get-hook-args"))) - - ;; return type data hook's keys in its data field - (define (get-hook-keys hook) - (if (and (hook? hook) - (eq? 'data (hook-type hook))) - (data-keys (hook-data hook)) - (error hook "argument must be hook type or hook must be 'data type! : get-hook-keys"))) - - ;; return type data hook's assoc list - (define (get-hook-alist hook) - (if (and (hook? hook) - (eq? 'data (hook-type hook))) - (data-cont (hook-data hook)) - (error hook "argument must be hook type or hook must be 'data type! : get-hook-alist"))) - - ;; execute the hook - (define (hook-execute hook) - (if (eq? 'proc (hook-type hook)) - (apply (get-hook-proc hook) - (if (list? (get-hook-args hook)) - (get-hook-args hook) - (error 'hook-execute "the arguments must be wrapped in a list"))) - (error 'hook "hook type is not 'proc! : hook-execute"))) - - ;; get the proc or data type hooks list, it's a list of names - (define (chain-hooks-list-query hook-type-key chain) - (if (not (memv hook-type-key '(proc data))) - (error 'hook-type-key "key is not 'proc or 'data! : chain-hooks-list-query")) - (let ((chain-hooks (chain-data-query 'hooks chain))) - (data-value-query hook-type-key chain-hooks))) - - ;; not export this function. - (define (chain-hooks-update! chain hook symbol) - (define symbol-list '(before after data)) - - ;; just return the updated data, doesn't modify anything - (define (update-chain-hook-procedure chain hook symbol) - (let ((hook-name-list (chain-hooks-list-query 'proc chain)) - (name (hook-name hook))) - (update-data! (chain-data-query 'hooks chain) - (create-data '(proc) - (list (cond [(eq? 'before symbol) - (cons name - hook-name-list)] - [(eq? 'after symbol) - (append hook-name-list - (list name))])))))) - - (define (update-chain-hook-data chain hook symbol) - (let ((hook-name-list (chain-hooks-list-query 'data chain)) - (name (hook-name hook))) - (update-data! (chain-data-query 'hooks chain) - (create-data '(data) - `(,(cons name hook-name-list)))))) - ;; check the input - (cond - [(not (chain? chain)) - (error 'chain "must be a chain record!")] - [(not (hook? hook)) - (error 'hook "must be a hook record!")] - [(not (memv symbol symbol-list)) - (error 'symbol "must be 'before, 'after or 'data(if hook type is data) symbol!")]) - - (cond - [(eq? 'proc (hook-type hook)) - (update-chain-hook-procedure chain hook symbol)] - [(eq? 'data (hook-type hook)) - (update-chain-hook-data chain hook symbol)] - [else (error 'hook "hook type is not correct!")])) - - ;; add-hook to the chain - (define add-hook! - (case-lambda - [(chain hook symbol) - (define symbol-list '(before after data)) - (cond - [(not (chain? chain)) - (error 'chain "must be a chain record!")] - [(not (hook? hook)) - (error 'hook "must be a hook record!")] - [(not (memv symbol symbol-list)) - (error 'symbol "must be 'before, 'after or 'data(if hook type is data) symbol!")]) - ;; update the data and the hooks name list - (cond - [(eq? symbol 'before) - (execution-set! chain - (cons (lambda () - (hook-execute hook)) - (chain-execution chain))) - (chain-hooks-update! chain hook symbol)] - [(eq? symbol 'after) - (execution-set! chain - (append (chain-execution chain) - (list (lambda () - (hook-execute hook))))) - (chain-hooks-update! chain hook symbol)] - [(eq? symbol 'data) - (if (eq? 'data (hook-type hook)) - (begin - (chain-data-update! chain (hook-data hook)) - (chain-hooks-update! chain hook symbol)) - (error 'hook "type is not data!"))] - [else (error symbol "the symbol must be 'before 'after or 'data!")])] - ;; accept two arg, it's an abbr - [(chain hook) - (cond - [(eq? 'data (hook-type hook)) - (add-hook! chain hook 'data)] - [(eq? 'proc (hook-type hook)) - (add-hook! chain hook 'after)] - [else (error 'hook "incorrect hook type!")])])) - - ) diff --git a/melt/invoke.ss b/melt/invoke.ss index 20d5014..7aba3e5 100644 --- a/melt/invoke.ss +++ b/melt/invoke.ss @@ -7,6 +7,8 @@ invoke-guard invoke-procs invoke-data + invoke-data-query + invoke-data-guard-query invoke-update-data! invoke-delete-data! invoke-add-proc! @@ -21,7 +23,7 @@ (lambda (invocation) (let ((proc-alist (data->alist (invoke-procs invocation)))) (do ((procs-list (map cdr (sort (lambda (pre aft) - (> (car pre) (car aft))) + (< (car pre) (car aft))) proc-alist)) (cdr procs-list))) ((null? procs-list) (void)) @@ -53,6 +55,14 @@ (define (invoke-data invocation) (data-value-query 'data (invocation))) + ;; data-query + (define (invoke-data-query key invocation) + (data-value-query key (invoke-data invocation))) + + ;; get the data guard + (define (invoke-data-guard-query key invocation) + (data-guard-query key (invoke-data invocation))) + ;; update data (define (invoke-update-data! key value invocation) (let ((data (invoke-data invocation))) diff --git a/melt/lesh.scm b/melt/lesh.scm deleted file mode 100644 index b110c89..0000000 --- a/melt/lesh.scm +++ /dev/null @@ -1,21 +0,0 @@ -(library (melt lesh) - (export ) - (import (scheme)) - - ;; help system will - (module lesh-system - [help-type] - - ;; help-type will tell the basic information for the type - (define (help-type arg) - (cond - [(string? arg) (cond - ([equal? arg "site"] - (display "this is the help doc for site!\n")) - (else (type-list)))] - [else (display "Sorry! No doc provided!\n")])) - - (define (type-list) - (display "Types are listed :\n") - (display "|| site || reader || page || post || asset ||\n"))) - ) diff --git a/melt/lib/commonmark.scm b/melt/lib/commonmark.scm deleted file mode 100644 index adefb9f..0000000 --- a/melt/lib/commonmark.scm +++ /dev/null @@ -1,119 +0,0 @@ -#!chezscheme -(library (melt lib commonmark) - (export commonmark->sxml - split-paragraph - transform-token - tokenize-module) - (import (scheme) - (melt utils)) - - ;;-----------------------------------------------define record ########### - ;; define the media type - (define-record-type token - (nongenerative melt-token) - (fields - ;; type is a symbol - (immutable type token-type) - ;; attr is an list and each element is a list - ;; which has two elements - (immutable attr token-attr) - ;; the content is also a list - (immutable cont token-cont))) - - ;;-----------------------------------------------define key words ######## - ;; define special characters - (define &&key-words (alist->hash-table - '((#\* . star) - (#\_ . under-score) - (#\- . minus) - (#\+ . plus) - (#\! . she) - (#\# . sharp) - (#\newline . newline) - (#\` . back-quote)))) - - ;; transform one token to an sxml tag - (define (transform-token token) - (define (attr-expand t-list) - (if (null? t-list) - '() - (cons '@ t-list))) - (if (token-attr token) - (if (token-cont token) - `(,(token-type token) ,(attr-expand (token-attr token)) ,(token-cont token)) - `(,(token-type token) ,(attr-expand (token-attr token)))) - (if (token-cont token) - `(,(token-type token) ,(token-cont token)) - (list (token-type token))))) - - ;; judge whether a line is a blank line - ;; the line doesn't contain a newlne character - (define (blank-line? line) - (call/cc (lambda (cc) - (do ((char-list (string->list line) (cdr char-list))) - ((null? char-list) #t) - (let ((char (car char-list))) - (if (not - (or (equal? #\tab char) - (equal? #\space char))) - (cc #f))))))) - - ;; read one file, generate a list of paragraphs - (define (split-paragraph path) - (call-with-port - (open-file-input-port path (file-options) (buffer-mode block) (native-transcoder)) - (lambda (port) - (define paragraphs '()) - (do ((paragraph '() (append paragraph line)) - (line (get-line port) (get-line port))) - ((eof-object? line) - (set! paragraphs (append paragraphs (list paragraph))) - paragraphs) - (if (blank-line? line) - (begin - (set! paragraphs (append paragraphs (list paragraph))) - (set! paragraph '()) - (set! line '())) - (set! line (list line))))))) - - (module tokenize-module - (tokenize - ) - - (define tokenize-p - (let ((tokens '()) - (temp-char-list '())) - (values (lambda (line-or-port) - (call-with-port (if (port? line-or-port) - line-or-port - (open-string-input-port line-or-port)) - (lambda (port) - (do ((char (read-char port) (read-char port))) - ((eof-object? char) #t) - (cond - [(equal? char #\#) - (append! temp-char-list (list char))]))))) - (lambda () - (values tokens))))) - - (define tokenize - (lambda (paragraphs) - (do ((paragraphs paragraphs (cdr paragraphs)) - (tokens (list))) - ((null? paragraphs) tokens) - (set! tokens - (append tokens (list (make-token 'p #f (apply string-append (car paragraphs))))))))) - - ) - - - - (import tokenize-module) - (define commonmark->sxml - (lambda (path) - (define lines (split-paragraph path)) - (define tokens (tokenize lines)) - (display tokens) - (map transform-token tokens))) - - ) diff --git a/melt/lib/console.scm b/melt/lib/console.scm deleted file mode 100644 index 7d14bdc..0000000 --- a/melt/lib/console.scm +++ /dev/null @@ -1,37 +0,0 @@ -#!chezscheme -(library (melt lib console) - (export special-sequence - gem-display - gem-command - gem) - (import (scheme)) - - ;; apply one shell sequence, and it won't reset it - (define (gem-command shell-sequence) - (string-append (string #\033) - shell-sequence)) - - ;; generate code sequence - (define (gem shell-sequence . text) - (string-append (gem-command shell-sequence) - (if (null? text) - "" - (car text)) - (gem-command "[0m"))) - - ;; just append strings and display it - (define gem-display - (lambda args - (display (apply string-append args)))) - - ;; some special sequence - (module special-sequence - [g-white - gem-reset - g-bar] - - (define g-bar "█") - (define g-white "[37m") - (define gem-reset "[0m")) - - ) diff --git a/melt/lib/console.ss b/melt/lib/console.ss index 863b85b..4662fb9 100644 --- a/melt/lib/console.ss +++ b/melt/lib/console.ss @@ -60,9 +60,9 @@ ;; display list text (define (gemd:item text) - (gem:display (gem:text "[37m" "*") - (gem:text "[38;5;238m[48;5;15m" "item") - (gem:text "[37m" "* ") + (gem:display (gem:text "[37m" "|") + (gem:text "[38;5;103m" "item") + (gem:text "[37m" "| ") text "\n")) ;; display help info diff --git a/melt/lib/file.scm b/melt/lib/file.scm deleted file mode 100644 index f50a644..0000000 --- a/melt/lib/file.scm +++ /dev/null @@ -1,76 +0,0 @@ -(library (melt lib file) - (export copy-file - cp-f - cp-rf - mkdir-r - directory-separator-string) - (import (scheme) - (melt utils)) - - (define (directory-separator-string) - (string (directory-separator))) - - ;; copy file - ;; the mode is for the output port - (define copy-file - (case-lambda - [(src-file target-file) - (let ((input-port (open-file-input-port src-file)) - (output-port (open-file-output-port target-file))) - (put-bytevector output-port (get-bytevector-all input-port)) - (close-port input-port) - (close-port output-port))] - [(src-file target-file mode) - (let ((input-port (open-file-input-port src-file)) - (output-port (open-file-output-port target-file mode))) - (put-bytevector output-port (get-bytevector-all input-port)) - (close-port input-port) - (close-port output-port))])) - - - ;; accept strings as arguments - ;; if the target exsites, replace it. - (define (cp-f src-file target-file) - (if (not (file-exists? src-file)) (error src-file "File not exists!")) - (mkdir-r (path-parent target-file)) - (copy-file src-file target-file (file-options no-fail))) - - ;; copy recursively and force - (define (cp-rf src-file target-file) - (if (file-exists? src-file) - (cond - [(file-regular? src-file) - (cp-f src-file target-file)] - [(file-directory? src-file) - (mkdir-r target-file) - (do ((file-list (directory-list src-file) (cdr file-list)) - (element (car (directory-list src-file)) (car file-list))) - ((null? file-list) - (cp-rf (string-append src-file (directory-separator-string) element) - (string-append target-file (directory-separator-string) element)) - #t) - (cp-rf (string-append src-file (directory-separator-string) element) - (string-append target-file (directory-separator-string) element)))]) - (error src-file "File not exists"))) - - ;; create directory recursively - ;; if one directory exists, just enter it and create rest directory - ;; it will never report an error!! - (define (mkdir-r dir) - ;; Create the dir just like use makedir bash command but clever - (define dir-list (decompose-path-name dir)) - (let ((file-name (if (path-absolute? dir) - (string-append "/" (car dir-list)) - (car dir-list)))) - (while (eq? '() dir-list) - (if (file-exists? file-name) - (if (not (file-directory? file-name)) - (begin - (format (current-error-port) "There exists conficts file!!~%") - (break))) - (mkdir file-name)) - (set! dir-list (cdr dir-list)) - (if (not (eq? '() dir-list)) - (set! file-name (string-append file-name "/" (car dir-list))))) - #t)) - ) diff --git a/melt/lib/sxml.scm b/melt/lib/sxml.scm deleted file mode 100644 index 5937332..0000000 --- a/melt/lib/sxml.scm +++ /dev/null @@ -1,117 +0,0 @@ -#!chezscheme -;; convert sxml to html -(library (melt lib sxml) - (export sxml->html - sxml->html-string) - (import (scheme) - (melt utils) - (melt srfi match)) - - - (define %void-elements - '[area - base - br - col - command - embed - hr - img - input - keygen - link - meta - param - source - track - wbr]) - - ;; Return #t if TAG is a void element. - (define (void-element? tag) - (pair? (memq tag %void-elements))) - - ;; something like '<' -> ≤ - ;; This need to be update from time to time - ;; --- mark --- - (define %escape-chars - (alist->hash-table - '((#\" . "quot") - (#\& . "amp") - (#\< . "lt") - (#\> . "gt")))) - - ;; Write the HTML escaped form of sxml to PORT. - ;; chars is a string - (define (string->escaped-html chars port) - (define (escape c) - (let ((escaped (hash-ref %escape-chars c))) - (if escaped - (format port "&~a;" escaped) - (display c port)))) - (string-for-each escape chars)) - - ;; Write the HTML escaped form of OBJ to PORT - (define (object->escaped-html obj port) - (string->escaped-html - (call-with-string-output-port - (lambda (x) (display obj x))) - port)) - - ;; Write the HTML escaped form of VALUE to PORT. - (define (attribute-value->html value port) - (if (string? value) - (string->escaped-html value port) - (object->escaped-html value port))) - - ;; Write ATTR and VALUE to PORT - ;; attr must be a symbol. the value could be string or symbol - (define (attribute->html attr value port) - (format port "~a=\"" attr) - (attribute-value->html value port) - (display #\" port)) - - (define (element->html tag attrs body port) - ;; Write the HTML TAG to PORT, where TAG has the attributes in the - ;; list ATTRS and the child nodes in BODY. - (format port "<~a" tag) - (for-each (match-lambda - ((attr value) - (display #\space port) - (attribute->html attr value port))) - attrs) - (if (and (null? body) (void-element? tag)) - (display "/>" port) - (begin - (display #\> port) - (for-each (lambda (x) - (sxml->html x port)) body) - (format port "" tag)))) - - (define (doctype->html doctype port) - (format port "" doctype)) - - (define (sxml->html tree port) - ;;Write the serialized HTML form of TREE to PORT. - (match tree - (() 'unspecified) - (('doctype type) - (doctype->html type port)) - (((? symbol? tag) ('@ attrs ...) body ...) - (element->html tag attrs body port)) - (((? symbol? tag) body ...) - (element->html tag '() body port)) - ((nodes ...) - (for-each (lambda (x) - (sxml->html x port)) nodes)) - ((? string? text) - (string->escaped-html text port)) - ;; Render arbitrary Scheme objects, too. - (obj (object->escaped-html obj port)))) - - ;; Render SXML as an HTML string. - (define (sxml->html-string sxml) - (call-with-string-output-port - (lambda (port) - (sxml->html sxml port)))) - - ) diff --git a/melt/post.scm b/melt/post.scm deleted file mode 100644 index b53e78d..0000000 --- a/melt/post.scm +++ /dev/null @@ -1,26 +0,0 @@ -(library (melt post) - (export post-meta-query - post-attr-query - create-post) - (import (scheme) - (melt structure) - (melt utils) - (melt data)) - - (import type-post) - (import type-data) - - ;; accept two assoc list - (define create-post - (case-lambda - [(meta attr cont) - (make-post meta attr cont)])) - - ;; query the data in post and return the key value pair if exists - (define (post-meta-query key post) - (assq key (data-cont (post-meta post)))) - - (define (post-attr-query key post) - (assq key (data-cont (post-attr post)))) - - ) diff --git a/melt/post.ss b/melt/post.ss index 8e8c7eb..6845add 100644 --- a/melt/post.ss +++ b/melt/post.ss @@ -2,8 +2,7 @@ (melt post) (export post-meta-query post-attr-query - create-post - compose-post) + create-post) (import (scheme) (melt structure) (melt utils) @@ -11,17 +10,11 @@ (import type-post) - ;; accept two assoc list + ;; accept two assoc list one sxml tree (define create-post (case-lambda [(meta attr cont) - (make-post meta attr cont)])) - - ;; use assoc list to compose a post - (define (compose-post meta-alist attr-alist cont-sxml) - (make-post (create-data meta-alist) - (create-data attr-alist) - cont-sxml)) + (make-post (create-data meta) (create-data attr) cont)])) ;; query the data in post and return the value if exists (define (post-meta-query key post) diff --git a/melt/prelude.scm b/melt/prelude.scm deleted file mode 100644 index b7bdafd..0000000 --- a/melt/prelude.scm +++ /dev/null @@ -1,5 +0,0 @@ -(library (melt prelude) - (export) - (import (scheme)) - - ) diff --git a/melt/settings.scm b/melt/settings.scm deleted file mode 100644 index f64782f..0000000 --- a/melt/settings.scm +++ /dev/null @@ -1,14 +0,0 @@ -(library (melt settings) - (export settings-update! - settings-query) - (import (scheme) - (melt glob) - (melt data)) - - ;; accept an alist or single list as argument - (define (settings-update! a-list) - (update-data! %%settings a-list)) - - (define (settings-query key) - (data-value-query key %%settings)) - ) diff --git a/melt/site.scm b/melt/site.scm index eb18187..4b7f30e 100644 --- a/melt/site.scm +++ b/melt/site.scm @@ -1,53 +1,53 @@ -(library (melt site) +(library + (melt site) (export create-site - load-source) + load-source) (import (scheme) (melt structure) - (melt invoke) + (melt invoke) (melt utils) - (melt data) - (melt asset) - (melt page)) - + (melt data) + (melt asset) + (melt page)) + (import type-site) ;; TODO: complete the create-site procedure (define create-site (lambda args - (cond - [(null? args) - (make-site (create-data '(index) - (list (lambda (directory chain) - ((create-writer (string-append directory "/index.html")) - (compose (cdr (page-list-query 'index - (chain-data-query 'page chain))) - (chain-data-query 'renderer chain)))))) - (create-data) - (create-data '(domain) - '("localhost")))] - [else - (let ((layout (car args)) - (comt (car (cdr args))) - (attr (car (cdr (cdr args))))) - (make-site layout comt attr))]))) - + (cond + [(null? args) + (make-site (create-data '(index) + (list (lambda (directory invocation) + ((create-writer (string-append directory "/index.html")) + (compose (cdr (page-list-query 'index + (invoke-data-query 'page invocation))) + (invoke-data-query 'renderer invocation)))))) + (create-data) + (create-data '((domain . "localhost"))))] + [else + (let ((layout (car args)) + (comt (car (cdr args))) + (attr (car (cdr (cdr args))))) + (make-site layout comt attr))]))) + ;; get the layout lambda (define (load-source name) - (define (read-fasl-lambda path) - (define binary-port (open-file-input-port path)) - (define obj (eval (fasl-read binary-port))) - (close-input-port binary-port) - obj) - (define fasl-name (string-append ".melt/fasl/" name)) - (define res-name (string-append ".melt/resource/" name ".scm")) - (if (file-exists? res-name) - (begin - (if (file-exists? fasl-name) - (delete-file fasl-name)) - (fasl-file res-name fasl-name) - (read-fasl-lambda fasl-name)) - (if (file-exists? fasl-name) - (read-fasl-lambda fasl-name) - (error name "file not exists"))) - ) + (define (read-fasl-lambda path) + (define binary-port (open-file-input-port path)) + (define obj (eval (fasl-read binary-port))) + (close-input-port binary-port) + obj) + (define fasl-name (string-append ".melt/fasl/" name)) + (define res-name (string-append ".melt/resource/" name ".scm")) + (if (file-exists? res-name) + (begin + (if (file-exists? fasl-name) + (delete-file fasl-name)) + (fasl-file res-name fasl-name) + (read-fasl-lambda fasl-name)) + (if (file-exists? fasl-name) + (read-fasl-lambda fasl-name) + (error name "file not exists"))) + ) ) diff --git a/melt/structure.scm b/melt/structure.scm deleted file mode 100644 index dc8f2c7..0000000 --- a/melt/structure.scm +++ /dev/null @@ -1,239 +0,0 @@ -(library (melt structure) - (export type-parser - type-post - type-renderer - type-page - - type-site - type-asset - - type-hook - type-trigger - type-chain - type-data - - type-command) - - (import (scheme)) - - ;; it now is an uniform utility! can be stroed in - ;; one place and use multiple times! - (module type-parser - [make-parser - parser? - parser-type - parser-proc - parser-refp] - (define-record-type - parser - (nongenerative melt-parser) - (fields - ;; the symbol which means the file type - ;; the symbol is used as file extension - (immutable type parser-type) - ;; proc is the procedure which take charge with - ;; the source file - (immutable proc parser-proc) - ;; refp==>refine procedure : update the resource file - ;; it need to be designed carefully, because it will alter - ;; the source file - (immutable refp parser-refp)))) - - ;; there maybe a lot of procedure between - ;; this two components. - - ;; the post recieve the data from parser - ;; and then process the data to satisfy its - ;; need. So the data stored in a post is all - ;; the data one post needs. No more change but - ;; use. - - ;; the meta and attr is all an assoc list - (module type-post - [make-post - post? - post-meta post-meta-set! - post-attr post-attr-set! - post-cont post-cont-set!] - (define-record-type - post - (nongenerative melt-post) - (fields - ;; it contains the attribute about the - ;; source file! - ;; the meta and attr are all the data - ;; but cont is sxml tree - (mutable meta post-meta post-meta-set!) - (mutable attr post-attr post-attr-set!) - (mutable cont post-cont post-cont-set!)))) - - ;; used to render the page component - (module type-renderer - [make-renderer - renderer? - renderer-type - renderer-proc proc-set! - renderer-data data-set!] - (define-record-type - renderer - (nongenerative melt-renderer) - (fields - ;; the type is an unique id to distinguish the render - (immutable type renderer-type) - ;; proc==>process process function used to render the - ;; page - (mutable proc renderer-proc proc-set!) - ;; data is the data which maybe be needed, it's the data type. - (mutable data renderer-data data-set!)))) - - ;; page is used to compose one page - ;; and use the proc to write ti to disk - ;; all the information relevant should - ;; be done before page, page only store - ;; information about the page it self. - (module type-page - [make-page - page? - page-meta page-meta-set! - page-cont page-cont-set! - page-comt page-comt-set!] - (define-record-type - page - (nongenerative melt-page) - (fields - ;; meta ==> store some useful value for the page - ;; cont ==> is the template for the page; actually it - ;; is a procedure accept itself a page obj, and generate - ;; sxml tree - ;; comt ==> it is a list of symbols map the renderer type - ;; need to be registered first - (mutable meta page-meta page-meta-set!) - (mutable cont page-cont page-cont-set!) - (mutable comt page-comt page-comt-set!)))) - - ;; site type is only for definition - (module type-site - [make-site - site? - site-layout layout-set! - site-comt comt-set! - site-attr attr-set!] - (define-record-type - site - (nongenerative melt-site) - (fields - ;; it stores data type data - ;; this defines how the published site to be generated! - (mutable layout site-layout layout-set!) - ;; comt==>component : it describes the composement of the - ;; site and the action on each component. for example: the site map - ;; it's also a data type - (mutable comt site-comt comt-set!) - ;; it is the attribute of the site like domain name - ;; it is a data type - (mutable attr site-attr attr-set!)))) - - (module type-asset - [make-asset - asset? - asset-source - asset-target] - (define-record-type - asset - (nongenerative melt-asset) - (fields - (immutable source asset-source) - (immutable target asset-target)))) - - ;; hook is the small data cell or execute cell - (module type-hook - [make-hook - hook? - hook-name - hook-type - hook-proc-arg proc-arg-set! - hook-data hook-data-set!] - (define-record-type - hook - (nongenerative melt-hook) - (fields - ;; hook's name - (immutable name hook-name) - ;; if the type is 'data, proc-arg contain data - ;; else if the type is 'proc, proc-arg is defined as following - (immutable type hook-type) - ;; proc-arg is a dot pair - ;; (procedure . args) - ;; the hook function - ;; the arguments, it must be wrapped in a list - (mutable proc-arg hook-proc-arg proc-arg-set!) - ;; it sotres hook data, it must be type data - (mutable data hook-data hook-data-set!)))) - - ;; the trigger module for future - (module type-trigger - [make-trigger - trigger? - trigger-cond - trigger-act] - (define-record-type - trigger - (nongenerative melt-trigger) - (fields - (immutable cond trigger-cond) - (immutable act trigger-act)))) - - - ;; define the execution priority and data transform - (module type-chain - [make-chain - chain? - chain-condition condition-set! - chain-execution execution-set! - chain-data chain-data-set!] - (define-record-type - chain - (nongenerative melt-chain) - (fields - ;; condition must be #t or #f - ;; or a procedure which return #t - ;; or #f and accept no argument - (mutable condition chain-condition condition-set!) - ;; it is a list of procedure without arguments - (mutable execution chain-execution execution-set!) - ;; data type - (mutable data chain-data chain-data-set!)))) - - (module type-data - [make-data - data? - data-keys data-keys-set! - data-cont data-cont-set!] - (define-record-type - data - (nongenerative melt-data) - (fields - ;; a list of symbols - (mutable keys data-keys data-keys-set!) - ;; an assoc list which contains keys in the - ;; keys field - (mutable cont data-cont data-cont-set!)))) - - (module type-command - [make-command - command? - command-name - command-desc - command-proc] - (define-record-type - command - (nongenerative melt-command) - (fields - ;; symbol, which specifics string in command line - (immutable name command-name) - ;; string, one line description - (immutable description command-desc) - ;; procedure for the command, accept arguments - (immutable procedure command-proc)))) - - ) diff --git a/melt/test/invoke-test.scm b/melt/test/invoke-test.scm deleted file mode 100644 index efcbb21..0000000 --- a/melt/test/invoke-test.scm +++ /dev/null @@ -1,13 +0,0 @@ -(import (melt structure)) -(import type-chain) -(import (melt data)) -(import (melt invoke)) - -(define x (init-chain #t (lambda () (display "hello")) (create-data))) -(add-hook! x (create-hook 'text2 'proc `(,(lambda () (display "\nncie"))))) -(add-hook! x (create-hook 'test1 'data (create-data '(x) '(2)))) - - - - - diff --git a/melt/test/markdown/makefile b/melt/test/markdown/makefile deleted file mode 100644 index 98b2633..0000000 --- a/melt/test/markdown/makefile +++ /dev/null @@ -1,5 +0,0 @@ -clean: - rm -f context Hello.html paragraph paragraph-test - -do: - scheme markdown-test.scm diff --git a/melt/test/markdown/markdown-parser.scm b/melt/test/markdown/markdown-parser.scm deleted file mode 100644 index b802609..0000000 --- a/melt/test/markdown/markdown-parser.scm +++ /dev/null @@ -1,5 +0,0 @@ -(import (melt parser markdown)) -(import (melt structure)) -(import type-parser) - -(define parse (parser-proc markdown)) diff --git a/melt/test/markdown/markdown-test.scm b/melt/test/markdown/markdown-test.scm deleted file mode 100644 index 321b4c3..0000000 --- a/melt/test/markdown/markdown-test.scm +++ /dev/null @@ -1,23 +0,0 @@ -(import (scheme)) -(import (melt lib markdown)) -(import (melt lib sxml)) - -(define-syntax test-input - (syntax-rules () - [(_ output input body) - (call-with-output-file output - (lambda (port) - (sxml->html - (call-with-input-file input - body) - port)))])) - -; (test-input "paragraph-test" "test3" (lambda (port) (compose-paragraph (list) port))) - -; (test-input "paragraph" "test" (lambda (port) (compose-paragraph (list) port))) - -; (test-input "context" "test" (lambda (port) (list (context-switch 'line port) (context-switch 'line port)))) - - -(test-input "Hello.html" "test" (lambda (port) (markdown->sxml port))) - diff --git a/melt/test/markdown/test b/melt/test/markdown/test deleted file mode 100644 index 3c25853..0000000 --- a/melt/test/markdown/test +++ /dev/null @@ -1,67 +0,0 @@ -~~~ -hello: nice -nice: 2018 -data: 2019-03-19 -tag : Note 笔记 -~~~ -# 树 - -这个结构和链表(线性表)不同, 最大时间复杂度为$O(log N)$. 这里主要介绍**二叉查找树**. - -## 树的定义方法 - -一个树首先是一些节点的集合 - -如果集合不为空, 那么它必有一个**根**节点以及`0`个或者多个非空的**子树**组成. 其中每一个子树都被来自根$r$的一条**有向边**链接. 每一棵子树都被称为**根**的**子**(child), 而$r$则是**父**(parent). 没有*子*节点的节点被称为**叶**(leaf), 而具有相同父节点的节点之间互相称做*兄弟*(sibling). - -从节点 到 的路径(path)定义为节点的一个序列, ,保证节点为的父节点. 该路径长度为这个节点序列上边的条数. 对于任意一个节点, 它的**深度**为从根节点到该节点的路径的长度. 因此根几点的深度为0. 任意节点的**高**是这个节点到一个**叶**节点最长的**路径长度**(考虑到路径的定义, 这里的叶节点只能是这个节点的子节点). 这里根的高就是整个树的长度, 并且每个树叶就是高0. - -如果存在一条从到的路径, 那么是的一位祖先(ancestor), 相反地2是1的后裔(descendant). 如果, 那么为**真**祖先和**真**后裔. - -> 这里也意味着根节点既是自己的祖先也是自己的后裔. `zhe是一个code` 而这个是一个**粗体**, 这个是一个_斜体_. > 普通的字符 -一个延续, 尽管有了一个换行 -这里还是一个换行 - -断开了, 作为普通的段落处理. -> 不普通的字符 - - -## 数据结构实现 - -由于每个树的子节点个数不定, 所以最好能够在运行时灵活分配空间. 这里的实现解决方法就是将所有的子节点都放在一个**链表**(线性表)中. - -一个典型结构声明为: -```c -typedef vodi * Ele; - -typedef -struct Node { - Ele Element; - Node FirstChild; - Node NextSibling; -} Tree; -``` -这里分为两个考虑, 使用`FirstChild`来处理这个节点的子节点链表. 使用`NextSibling`来处理这个节点的兄弟节点链表. - -这个就是一般的定义了. - -## 遍历策略 - -`先序遍历`就是先处理该节点, 然后再处理它的子节点. - -`后续遍历`就是优先处理该节点的子节点, 然后再处理该节点. - -# 二叉树(binary tree) - -首先, 它是一个树, 其次, 规定它每个节点的子节点个数不超过2个. 这里将这两个节点命名为`Tnode1`和`Tnode2`. 这两个节点可以任意出现(可以随意消失也可以随意出现). 还有一个是二叉树的优化版本叫做平衡二叉树, 又称为二叉查找树(binary search tree). 它的平均深度为$Olog N$. - -## 实现 - -和树一样, 只不过子节点指针限制为两个指针而已. - -## 应用 - -这里面再介绍一个`中序遍历`. 针对于二叉树. 先处理左节点再处理本身最后处理右节点. - - -## 搜索树 diff --git a/melt/test/markdown/test2 b/melt/test/markdown/test2 deleted file mode 100644 index 8872474..0000000 --- a/melt/test/markdown/test2 +++ /dev/null @@ -1,19 +0,0 @@ -```java -public class ActivityName extends AppCompatActiity{ - @Override - protected void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - // 使用R.layout.名字 来设置活动的布局 - setContentView(R.layout.layoutfortheActivity); - } -} -``` -*** ---- - -资源放在什么文件夹下就使用`R.文件夹.name`来在 java 中引用. 在 xml 中使用`@`来引用. - -## /app/res 目录下的布局 - -所有以`drawable`开头的目录都是存放**图片**的. 所有以`mipmap`开头的目录都是用来存放**应用图标**的, 所有`values`开头的文件夹都是用来存放**字符串, 样式, 颜色**等**配置**的. 所有以`layout`开头的文件夹都是用来存放**布局文件**的. diff --git a/melt/test/markdown/test3 b/melt/test/markdown/test3 deleted file mode 100644 index 7016503..0000000 --- a/melt/test/markdown/test3 +++ /dev/null @@ -1,2 +0,0 @@ - -所有以`drawable`开头的目录都是存放**图片**的. 所有以`mipmap`开头的目录都是用来存放**应用图标**的, 所有`values`开头的文件夹都是用来存放**字符串, 样式, 颜色**等**配置**的. 所有以`layout`开头的文件夹都是用来存放**布局文件**的. diff --git a/melt/ui.scm b/melt/ui.scm index 6d39897..38c1513 100644 --- a/melt/ui.scm +++ b/melt/ui.scm @@ -14,7 +14,7 @@ (gemd:info (string-append (gem:text "[37;1m" "melt") (gem:text "[38;5;15m" " version ") - (gem:text "[38;5;165m" "0.0.5")) )) + (gem:text "[38;5;165m" "0.0.5-2")) )) ;; the basic information (define (introduction) diff --git a/melt/uutil.scm b/melt/uutil.scm index d3e6e76..2b9f570 100644 --- a/melt/uutil.scm +++ b/melt/uutil.scm @@ -33,7 +33,7 @@ (scone! post-ls (parse-posts (car obj-ls) parser-list)) (let ((raw-sxml (parse-with-parsers (car obj-ls) parser-list))) (if raw-sxml - (scone! post-ls (compose-post + (scone! post-ls (create-post `((path . ,(car obj-ls)) (name . ,(path-last (path-root (car obj-ls))))) (car raw-sxml) diff --git a/melt/version.scm b/melt/version.scm deleted file mode 100644 index 4ee24fd..0000000 --- a/melt/version.scm +++ /dev/null @@ -1,25 +0,0 @@ -#!chezscheme -(library (melt version) - (export show-version-history) - (import (scheme) - (melt lib console)) - - (define (show-version-history) - (do ((cur-list version-history (cdr cur-list))) - ((null? cur-list) #t) - (let ((ver (car cur-list))) - (format #t (string-append "Melt " (gem "[37m" (car ver)) " --- " (gem "[38;5;220m" (cdr ver)) "~%"))))) - - ;; there are three numbers in the version string X. Y. Z - ;; -- the X is the Milestone , when it updates, this means - ;; it now is a new release and it may be not compatibale with - ;; previous release. - ;; -- the Y is the stable release during X, add some functions or bug fix. - ;; -- the Z is the trial number. Each tested feature will be in here. - (define version-history - '[("0.0.1" . "navigate to chezscheme!") - ("0.0.2" . "add markdown lib! now it will work!") - ("0.0.3" . "add markdown parser and sxml parser!")]) - - - )