Changeset 30159 for lang/elisp

Show
Ignore:
Timestamp:
02/16/09 23:40:08 (4 years ago)
Author:
imakado
Message:

クオートされているyamlを読み込めるようにした

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/elisp/pit/branches/fix-regexp/pit.el

    r29403 r30159  
    6969(defalias 'alist/update 'alist/merge) 
    7070 
     71(defvar pit/profile-regexp 
     72  (rx bol 
     73      (? (or "\"" "'")) 
     74      "profile" 
     75      (? (or "\"" "'")) 
     76      ":" 
     77      (* space) 
     78      (? (or "\"" "'")) 
     79      (group 
     80       (+ (not (any "'" "\"")))))) 
     81 
    7182(defun pit/profile () 
    7283  (when (file-exists-p pit/config) 
     
    7485            (with-temp-buffer 
    7586              (insert-file-contents pit/config) 
    76               (when (re-search-forward "^profile:[ ]*\\(.+\\)" nil t) 
     87              (when (re-search-forward pit/profile-regexp nil t) 
    7788                (match-string 1)))) 
    7889           (profile/file 
     
    181192                '((" +$" "") 
    182193                  ("---" "(setq result '(") 
    183                   ("^\\([^ ].+\\):" "(\\1 (") 
    184                   ("^[ ]+\\(.+\\):[ ]+?\\(.+\\)" "(\\1 . \"\\2\")") 
     194                  ("\\(?:^\\(?:[\"']\\)?\\([^'\": ]+\\)['\"]?:\\)" "(\\1 (") 
     195                  ("\\(?:^ +\\(?:[\"']\\)?\\([^'\"\n]+\\)\\(?:[\"']\\)?:\\(?: +\\)?\\(?:[\"']\\)?\\([^'\"\n]+\\).*\\)" 
     196                   "(\\1 . \"\\2\")") 
    185197                  ("\\()\\)\n\\(^[^'].+(\\)" "))\\1\n\\2"))) 
    186198          (goto-char (point-max)) 
     
    190202      result))) 
    191203 
     204;;; Test 
     205(defvar pit/test-profile-yaml 
     206  "--- 
     207profile: default") 
     208 
     209(defvar pit/test-profile-yaml-quoted 
     210  "--- 
     211\"profile\": 'default'") 
     212 
     213 
     214(dont-compile 
     215  (when (fboundp 'expectations) 
     216    (expectations 
     217      (desc "pit/load") 
     218      (expect "default" 
     219        (with-temp-buffer 
     220          (insert pit/test-profile-yaml) 
     221          (goto-char (point-min)) 
     222          (when (re-search-forward pit/profile-regexp nil t) 
     223            (match-string 1)))) 
     224 
     225      (expect "default" 
     226        (with-temp-buffer 
     227          (insert pit/test-profile-yaml-quoted) 
     228          (goto-char (point-min)) 
     229          (when (re-search-forward pit/profile-regexp nil t) 
     230            (match-string 1)))) 
     231      ))) 
     232 
     233 
    192234(provide 'pit) 
    193235