Show More
@@ -0,0 +1,1 b'' | |||
|
1 | error |
@@ -6,14 +6,18 b'' | |||
|
6 | 6 | (defparameter *l10n-strings* |
|
7 | 7 | (mapcan (lambda (lang) |
|
8 | 8 | (cons (intern (string-upcase lang) :keyword) |
|
9 | (read-code-from-string | |
|
10 |
( |
|
|
11 | (concatenate 'string "strings/" lang ".sexp"))))) | |
|
9 | (list (apply #'append | |
|
10 | (read-code-from-string | |
|
11 | (load-src | |
|
12 | (concatenate 'string "strings/" lang ".sexp"))))))) | |
|
12 | 13 | *languages*)) |
|
13 | 14 | |
|
14 | 15 | (defun lformat (target key &rest args) |
|
15 | 16 | (let* ((lang (intern (string-upcase (first (system-locale:languages))) |
|
16 | 17 | :keyword)) |
|
17 | 18 | (strings (or (getf *l10n-strings* lang) |
|
18 |
(getf *l10n-strings* :en))) |
|
|
19 |
( |
|
|
19 | (getf *l10n-strings* :en))) | |
|
20 | (string (getf strings key))) | |
|
21 | (if string | |
|
22 | (apply #'format target string args) | |
|
23 | (error "Unknown localization string ~S for language ~S" key lang)))) |
@@ -4,6 +4,7 b'' | |||
|
4 | 4 | (defvar *app-name* "") |
|
5 | 5 | |
|
6 | 6 | (defun entry-point-no-args () |
|
7 | (setf *delivered* t) | |
|
7 | 8 | (entry-point uiop:*command-line-arguments*)) |
|
8 | 9 | |
|
9 | 10 | (defun entry-point (args) |
@@ -51,8 +52,12 b'' | |||
|
51 | 52 | (lformat t :usage *app-name*)) |
|
52 | 53 | |
|
53 | 54 | (defun parse-file (filename) |
|
54 | (p:parse 'txt2web-grammar | |
|
55 | (alexandria:read-file-into-string filename))) | |
|
55 | (handler-case | |
|
56 | (p:parse 'txt2web-grammar | |
|
57 | (alexandria:read-file-into-string filename)) | |
|
58 | (p:esrap-parse-error (e) | |
|
59 | (format t "~A~%" e) | |
|
60 | (uiop:quit 1)))) | |
|
56 | 61 | |
|
57 | 62 | (defun report-error (fmt &rest args) |
|
58 | 63 | (format t "ERROR: ~A~%" (apply #'format nil fmt args)) |
@@ -72,3 +72,60 b'' | |||
|
72 | 72 | ;; No idea why these are not exported |
|
73 | 73 | (export '<<) |
|
74 | 74 | (export '>>) |
|
75 | ||
|
76 | (in-package esrap) | |
|
77 | (defmethod print-object :around ((condition esrap-error) stream) | |
|
78 | (when (not txt2web::*delivered*) | |
|
79 | (return-from print-object | |
|
80 | (call-next-method))) | |
|
81 | (when (or *print-escape* | |
|
82 | *print-readably* | |
|
83 | (and *print-lines* (<= *print-lines* 5))) | |
|
84 | (return-from print-object)) | |
|
85 | ||
|
86 | ;; FIXME: this looks like it won't do the right thing when used as | |
|
87 | ;; part of a logical block. | |
|
88 | (if-let ((text (esrap-error-text condition)) | |
|
89 | (position (esrap-error-position condition))) | |
|
90 | (labels ((safe-index (index) | |
|
91 | (min (max index 0) (length text))) | |
|
92 | (find-newline (&key (start 0) (end (length text)) (from-end t)) | |
|
93 | (let ((start (safe-index start)) | |
|
94 | (end (safe-index end))) | |
|
95 | (cond | |
|
96 | ((when-let ((position (position #\Newline text | |
|
97 | :start start :end end | |
|
98 | :from-end from-end))) | |
|
99 | (1+ position))) | |
|
100 | ((and from-end (zerop start)) | |
|
101 | start) | |
|
102 | ((and (not from-end) (= end (length text))) | |
|
103 | end))))) | |
|
104 | ;; FIXME: magic numbers | |
|
105 | (let* ((line (count #\Newline text :end position)) | |
|
106 | (column (- position (or (find-newline :end position) 0) 1)) | |
|
107 | (min-start (- position 160)) | |
|
108 | (max-end (+ position 24)) | |
|
109 | (line-start (or (find-newline :start min-start | |
|
110 | :end position) | |
|
111 | (safe-index min-start))) | |
|
112 | (start (cond | |
|
113 | ((= (safe-index min-start) line-start) | |
|
114 | line-start) | |
|
115 | ((find-newline :start min-start | |
|
116 | :end (1- line-start))) | |
|
117 | (t | |
|
118 | ||
|
119 | line-start))) | |
|
120 | (end (or (find-newline :start position | |
|
121 | :end max-end | |
|
122 | :from-end nil) | |
|
123 | (safe-index max-end))) | |
|
124 | (*print-circle* nil)) | |
|
125 | (txt2web::lformat stream :error | |
|
126 | (= position (length text)) | |
|
127 | (list (subseq text start end)) | |
|
128 | (- position line-start) | |
|
129 | (1+ line) (1+ column) position))) | |
|
130 | ||
|
131 | (format stream "~2&<text and position not available>~2%"))) |
@@ -1,6 +1,8 b'' | |||
|
1 | 1 | |
|
2 | 2 | (in-package txt2web) |
|
3 | 3 | |
|
4 | (defvar *delivered* nil) | |
|
5 | ||
|
4 | 6 | (defun src-file (filename) |
|
5 | 7 | (uiop/pathname:merge-pathnames* |
|
6 | 8 | filename |
General Comments 0
You need to be logged in to leave comments.
Login now