Show More
@@ -0,0 +1,1 b'' | |||||
|
1 | error |
@@ -6,14 +6,18 b'' | |||||
6 | (defparameter *l10n-strings* |
|
6 | (defparameter *l10n-strings* | |
7 | (mapcan (lambda (lang) |
|
7 | (mapcan (lambda (lang) | |
8 | (cons (intern (string-upcase lang) :keyword) |
|
8 | (cons (intern (string-upcase lang) :keyword) | |
9 | (read-code-from-string |
|
9 | (list (apply #'append | |
10 |
( |
|
10 | (read-code-from-string | |
11 | (concatenate 'string "strings/" lang ".sexp"))))) |
|
11 | (load-src | |
|
12 | (concatenate 'string "strings/" lang ".sexp"))))))) | |||
12 | *languages*)) |
|
13 | *languages*)) | |
13 |
|
14 | |||
14 | (defun lformat (target key &rest args) |
|
15 | (defun lformat (target key &rest args) | |
15 | (let* ((lang (intern (string-upcase (first (system-locale:languages))) |
|
16 | (let* ((lang (intern (string-upcase (first (system-locale:languages))) | |
16 | :keyword)) |
|
17 | :keyword)) | |
17 | (strings (or (getf *l10n-strings* lang) |
|
18 | (strings (or (getf *l10n-strings* lang) | |
18 |
(getf *l10n-strings* :en))) |
|
19 | (getf *l10n-strings* :en))) | |
19 |
( |
|
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 | (defvar *app-name* "") |
|
4 | (defvar *app-name* "") | |
5 |
|
5 | |||
6 | (defun entry-point-no-args () |
|
6 | (defun entry-point-no-args () | |
|
7 | (setf *delivered* t) | |||
7 | (entry-point uiop:*command-line-arguments*)) |
|
8 | (entry-point uiop:*command-line-arguments*)) | |
8 |
|
9 | |||
9 | (defun entry-point (args) |
|
10 | (defun entry-point (args) | |
@@ -51,8 +52,12 b'' | |||||
51 | (lformat t :usage *app-name*)) |
|
52 | (lformat t :usage *app-name*)) | |
52 |
|
53 | |||
53 | (defun parse-file (filename) |
|
54 | (defun parse-file (filename) | |
54 | (p:parse 'txt2web-grammar |
|
55 | (handler-case | |
55 | (alexandria:read-file-into-string filename))) |
|
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 | (defun report-error (fmt &rest args) |
|
62 | (defun report-error (fmt &rest args) | |
58 | (format t "ERROR: ~A~%" (apply #'format nil fmt args)) |
|
63 | (format t "ERROR: ~A~%" (apply #'format nil fmt args)) |
@@ -72,3 +72,60 b'' | |||||
72 | ;; No idea why these are not exported |
|
72 | ;; No idea why these are not exported | |
73 | (export '<<) |
|
73 | (export '<<) | |
74 | (export '>>) |
|
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 | (in-package txt2web) |
|
2 | (in-package txt2web) | |
3 |
|
3 | |||
|
4 | (defvar *delivered* nil) | |||
|
5 | ||||
4 | (defun src-file (filename) |
|
6 | (defun src-file (filename) | |
5 | (uiop/pathname:merge-pathnames* |
|
7 | (uiop/pathname:merge-pathnames* | |
6 | filename |
|
8 | filename |
@@ -10,3 +10,6 b' Options:' | |||||
10 |
|
10 | |||
11 | Note that the files in extras/ are not actually used. They're just there for the reference~%") |
|
11 | Note that the files in extras/ are not actually used. They're just there for the reference~%") | |
12 |
|
12 | |||
|
13 | (:error "Error at~:[~; end of input~]~2%~ | |||
|
14 | ~2@T~<~@;~A~:>~%~ | |||
|
15 | ~2@T~V@T^ (Line ~D, Column ~D, Position ~D)~2%") No newline at end of file |
@@ -10,3 +10,6 b'' | |||||
10 |
|
10 | |||
11 | Файлы в extras на самом деле компилятором не используются. Используйте только как образец.~%") |
|
11 | Файлы в extras на самом деле компилятором не используются. Используйте только как образец.~%") | |
12 |
|
12 | |||
|
13 | (:error "Ошибка в~:[~; конце файла~]~2%~ | |||
|
14 | ~2@T~<~@;~A~:>~%~ | |||
|
15 | ~2@T~V@T^ (Строка ~D, Столбец ~D, Символ ~D)~2%") No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now