|
15 | 15 |
|
16 | 16 | (defparameter *comment-table-1* nil) |
17 | 17 | (defparameter *comment-table-2* nil) |
| 18 | +(defparameter *lex-errors-msgs-1* nil) |
| 19 | +(defparameter *lex-errors-msgs-2* nil) |
| 20 | +(defparameter *lexems-1* nil) |
| 21 | +(defparameter *lexems-2* nil) |
18 | 22 |
|
19 | 23 | (defun main () |
20 | 24 | (let ((cmd-args (uiop:command-line-arguments))) |
|
25 | 29 | (defun differ-v01 (file1 file2) |
26 | 30 | (init-stats) |
27 | 31 | (let (*comment-table-1* |
28 | | - *comment-table-2*) |
| 32 | + *comment-table-2* |
| 33 | + *lex-errors-msgs-1* |
| 34 | + *lex-errors-msgs-2* |
| 35 | + *lexems-1* |
| 36 | + *lexems-2*) |
29 | 37 | (multiple-value-bind (res1 res2) |
30 | 38 | (compare-two-files file1 file2) |
31 | 39 | (generate-json-outputs res1 res2)))) |
32 | 40 |
|
33 | 41 | (defun str-differ-v01 (str1 str2) |
34 | 42 | (init-stats) |
35 | 43 | (let (*comment-table-1* |
36 | | - *comment-table-2*) |
| 44 | + *comment-table-2* |
| 45 | + *lex-errors-msgs-1* |
| 46 | + *lex-errors-msgs-2* |
| 47 | + *lexems-1* |
| 48 | + *lexems-2*) |
37 | 49 | (multiple-value-bind (res1 res2) |
38 | 50 | (compare-two-str str1 str2) |
39 | 51 | (generate-json-outputs res1 res2)))) |
|
47 | 59 | (with-open-file (stream "comments2.json" :direction :output |
48 | 60 | :if-exists :supersede) |
49 | 61 | (get-json-comments *comment-table-2* stream))) |
50 | | - (with-open-file (stream "res1.json" :direction :output |
51 | | - :if-exists :supersede) |
52 | | - (get-json-res res1 stream)) |
53 | | - (with-open-file (stream "res2.json" :direction :output |
54 | | - :if-exists :supersede) |
55 | | - (get-json-res res2 stream)) |
56 | | - (with-open-file (stream "stats.json" :direction :output |
57 | | - :if-exists :supersede) |
58 | | - (get-stats-res stream))) |
| 62 | + (when *lex-errors-msgs-1* |
| 63 | + (with-open-file (stream "lexems1.json" :direction :output |
| 64 | + :if-exists :supersede) |
| 65 | + (get-lexems-json *lexems-1* stream)) |
| 66 | + (with-open-file (stream "lexer-errors-msgs1.json" :direction :output |
| 67 | + :if-exists :supersede) |
| 68 | + (get-lexer-errors-msgs-json *lex-errors-msgs-1* stream))) |
| 69 | + (when *lex-errors-msgs-2* |
| 70 | + (with-open-file (stream "lexems2.json" :direction :output |
| 71 | + :if-exists :supersede) |
| 72 | + (get-lexems-json *lexems-2* stream)) |
| 73 | + (with-open-file (stream "lexer-errors-msgs2.json" :direction :output |
| 74 | + :if-exists :supersede) |
| 75 | + (get-lexer-errors-msgs-json *lex-errors-msgs-2* stream))) |
| 76 | + (when (and res1 res2) |
| 77 | + (with-open-file (stream "res1.json" :direction :output |
| 78 | + :if-exists :supersede) |
| 79 | + (get-json-res res1 stream)) |
| 80 | + (with-open-file (stream "res2.json" :direction :output |
| 81 | + :if-exists :supersede) |
| 82 | + (get-json-res res2 stream)) |
| 83 | + (with-open-file (stream "stats.json" :direction :output |
| 84 | + :if-exists :supersede) |
| 85 | + (get-stats-res stream)))) |
59 | 86 |
|
60 | 87 | (defun simple-differ-str (str1 str2 &optional (out1 t ) (out2 t) (out3 t)) |
61 | 88 | (init-stats) |
62 | 89 | (let (*comment-table-1* |
63 | | - *comment-table-2*) |
| 90 | + *comment-table-2* |
| 91 | + *lex-errors-msgs-1* |
| 92 | + *lex-errors-msgs-2* |
| 93 | + *lexems-1* |
| 94 | + *lexems-2*) |
64 | 95 | (multiple-value-bind (res1 res2) |
65 | 96 | (compare-two-str str1 str2) |
66 | 97 | (when *comment-table-1* |
| 98 | + (format t "Comment Table of str1:~%") |
67 | 99 | (get-json-comments *comment-table-1* t)) |
68 | 100 | (when *comment-table-2* |
69 | 101 | (get-json-comments *comment-table-2* t)) |
70 | | - (get-json-res res1 out1) |
71 | | - (get-json-res res2 out2) |
72 | | - (get-stats-res out3)))) |
| 102 | + (when *lex-errors-msgs-1* |
| 103 | + (format t "~%Lex-errors-msgs-1:~%") |
| 104 | + (get-lexer-errors-msgs-json *lex-errors-msgs-1* t) |
| 105 | + (format t "~%Lexems-1:~%") |
| 106 | + (get-lexems-json *lexems-1* t)) |
| 107 | + (when *lex-errors-msgs-2* |
| 108 | + (format t "~%Lex-errors-msgs-1:~%") |
| 109 | + (get-lexer-errors-msgs-json *lex-errors-msgs-2* t) |
| 110 | + (format t "~%Lexems-1:~%") |
| 111 | + (get-lexems-json *lexems-2* t)) |
| 112 | + (when (and res1 res2) |
| 113 | + (format t "~%Res1:~%") |
| 114 | + (get-json-res res1 out1) |
| 115 | + (format t "~%Res2:~%") |
| 116 | + (get-json-res res2 out2) |
| 117 | + (format t "~%Stats:~%") |
| 118 | + (get-stats-res out3))))) |
73 | 119 |
|
74 | 120 | (defun compare-two-files (filepath1 filepath2) |
75 | 121 | (let ((str1 (read-file-into-string filepath1)) |
|
79 | 125 | (defun compare-two-str (str1 str2) |
80 | 126 | (let ((ast-tree-1 (get-abstract-sem-tree-from-string str1 1)) |
81 | 127 | (ast-tree-2 (get-abstract-sem-tree-from-string str2 2))) |
82 | | - (compare-results) |
| 128 | + (when (and ast-tree-1 ast-tree-2) |
| 129 | + (compare-results)) |
83 | 130 | (values ast-tree-1 ast-tree-2))) |
84 | 131 |
|
85 | 132 | (defun get-abstract-sem-tree-from-string (str cur-file) |
86 | 133 | (multiple-value-bind (res-lexems comments lex-errors) |
87 | 134 | (lexer str) |
88 | | - (when lex-errors |
89 | | - (error "Lex errors !!! ~A" lex-errors)) |
90 | 135 | (when (> (hash-table-count comments) 0) |
91 | 136 | (cond ((= cur-file 1) |
92 | 137 | (setf *comment-table-1* comments)) |
93 | 138 | ((= cur-file 2) |
94 | 139 | (setf *comment-table-2* comments)) |
95 | 140 | (t (error "Error value of cur-file")))) |
| 141 | + (when lex-errors |
| 142 | + (cond ((= cur-file 1) |
| 143 | + (setf *lex-errors-msgs-1* lex-errors) |
| 144 | + (setf *lexems-1* res-lexems)) |
| 145 | + ((= cur-file 2) |
| 146 | + (setf *lex-errors-msgs-2* lex-errors) |
| 147 | + (setf *lexems-2* res-lexems)) |
| 148 | + (t (error "Error value of cur-file"))) |
| 149 | + (return-from get-abstract-sem-tree-from-string nil)) |
96 | 150 | (abstract-sem-tree-gen (parser res-lexems) :curr-file cur-file))) |
0 commit comments