From 31a373441addb56701c82415aa521ab424da2da5 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 13 Jun 2018 19:20:24 -0700 Subject: [PATCH] lex quotation marks correctly --- brag/examples/quotation-marks.rkt | 2 ++ brag/rules/lexer.rkt | 2 ++ brag/test/test-all.rkt | 1 + brag/test/test-quotation-marks.rkt | 6 ++++++ 4 files changed, 11 insertions(+) create mode 100644 brag/examples/quotation-marks.rkt create mode 100755 brag/test/test-quotation-marks.rkt diff --git a/brag/examples/quotation-marks.rkt b/brag/examples/quotation-marks.rkt new file mode 100644 index 0000000..bbfa2a2 --- /dev/null +++ b/brag/examples/quotation-marks.rkt @@ -0,0 +1,2 @@ +#lang brag +start: "a" "\"" "'" 'a' '"' '\'' \ No newline at end of file diff --git a/brag/rules/lexer.rkt b/brag/rules/lexer.rkt index 107159c..9f73e61 100755 --- a/brag/rules/lexer.rkt +++ b/brag/rules/lexer.rkt @@ -40,6 +40,7 @@ (:* (:or "\\'" "\\n" "\\t" (:~ "'" "\\"))) "'") (token-LIT (case lexeme + [("'\\''") "\"'\""] [("'\\n'") "'\n'"] [("'\\t'") "'\t'"] [else lexeme]))] @@ -47,6 +48,7 @@ (:* (:or "\\\"" "\\n" "\\t" (:~ "\"" "\\"))) "\"") (token-LIT (case lexeme + [("\"\\\"\"") "\"\"\""] [("\"\\n\"") "\"\n\""] [("\"\\t\"") "\"\t\""] [else lexeme]))] diff --git a/brag/test/test-all.rkt b/brag/test/test-all.rkt index 43b37d2..7ce7c43 100755 --- a/brag/test/test-all.rkt +++ b/brag/test/test-all.rkt @@ -13,6 +13,7 @@ "test-lexer.rkt" "test-old-token.rkt" "test-parser.rkt" + "test-quotation-marks.rkt" "test-simple-arithmetic-grammar.rkt" "test-simple-line-drawing.rkt" "test-weird-grammar.rkt" diff --git a/brag/test/test-quotation-marks.rkt b/brag/test/test-quotation-marks.rkt new file mode 100755 index 0000000..48a1730 --- /dev/null +++ b/brag/test/test-quotation-marks.rkt @@ -0,0 +1,6 @@ +#lang racket/base +(require brag/examples/quotation-marks + brag/support + rackunit) + +(check-equal? (parse-tree "a\"'a\"'") '(start "a" "\"" "'" "a" "\"" "'"))