diff --git a/brag/examples/quotation-marks-and-backslashes.rkt b/brag/examples/quotation-marks-and-backslashes.rkt new file mode 100644 index 0000000..18bc00f --- /dev/null +++ b/brag/examples/quotation-marks-and-backslashes.rkt @@ -0,0 +1,2 @@ +#lang brag +start: "a" "\"" "'" "\\" 'a' '"' '\'' '\\' \ No newline at end of file diff --git a/brag/examples/quotation-marks.rkt b/brag/examples/quotation-marks.rkt deleted file mode 100644 index bbfa2a2..0000000 --- a/brag/examples/quotation-marks.rkt +++ /dev/null @@ -1,2 +0,0 @@ -#lang brag -start: "a" "\"" "'" 'a' '"' '\'' \ No newline at end of file diff --git a/brag/rules/lexer.rkt b/brag/rules/lexer.rkt index 04a8a3b..93c4a4f 100755 --- a/brag/rules/lexer.rkt +++ b/brag/rules/lexer.rkt @@ -36,7 +36,7 @@ (define (unescape-lexeme lexeme quote-char) ;; convert the literal string representation back into an escape char with lookup table - (define unescapes (hash "a" 7 "b" 8 "t" 9 "n" 10 "v" 11 "f" 12 "r" 13 "e" 27 "\"" 34 "'" 39)) + (define unescapes (hash "a" 7 "b" 8 "t" 9 "n" 10 "v" 11 "f" 12 "r" 13 "e" 27 "\"" 34 "'" 39 "\\" 92)) (define pat (regexp (format "(?<=^~a\\\\).(?=~a$)" quote-char quote-char))) (cond [(regexp-match pat lexeme) @@ -49,11 +49,11 @@ ;; handle whitespace & escape chars within quotes as literal tokens: "\n" "\t" '\n' '\t' ;; match the escaped version, and then unescape them before they become token-LITs [(:: "'" - (:* (:or "\\'" esc-chars (:~ "'" "\\"))) + (:or (:* (:or "\\'" esc-chars (:~ "'" "\\"))) "\\\\") "'") (token-LIT (unescape-lexeme lexeme #\'))] [(:: "\"" - (:* (:or "\\\"" esc-chars (:~ "\"" "\\"))) + (:or (:* (:or "\\\"" esc-chars (:~ "\"" "\\"))) "\\\\") "\"") (token-LIT (unescape-lexeme lexeme #\"))] ["(" diff --git a/brag/test/test-quotation-marks-and-backslashes.rkt b/brag/test/test-quotation-marks-and-backslashes.rkt new file mode 100755 index 0000000..e78685d --- /dev/null +++ b/brag/test/test-quotation-marks-and-backslashes.rkt @@ -0,0 +1,6 @@ +#lang racket/base +(require brag/examples/quotation-marks-and-backslashes + brag/support + rackunit) + +(check-equal? (parse-tree "a\"'\\a\"'\\") '(start "a" "\"" "'" "\\" "a" "\"" "'" "\\")) diff --git a/brag/test/test-quotation-marks.rkt b/brag/test/test-quotation-marks.rkt deleted file mode 100755 index 48a1730..0000000 --- a/brag/test/test-quotation-marks.rkt +++ /dev/null @@ -1,6 +0,0 @@ -#lang racket/base -(require brag/examples/quotation-marks - brag/support - rackunit) - -(check-equal? (parse-tree "a\"'a\"'") '(start "a" "\"" "'" "a" "\"" "'"))