lex quotation marks correctly

hide-top-rule-name
Matthew Butterick 7 years ago
parent 8eb9b32220
commit 31a373441a

@ -0,0 +1,2 @@
#lang brag
start: "a" "\"" "'" 'a' '"' '\''

@ -40,6 +40,7 @@
(:* (:or "\\'" "\\n" "\\t" (:~ "'" "\\"))) (:* (:or "\\'" "\\n" "\\t" (:~ "'" "\\")))
"'") "'")
(token-LIT (case lexeme (token-LIT (case lexeme
[("'\\''") "\"'\""]
[("'\\n'") "'\n'"] [("'\\n'") "'\n'"]
[("'\\t'") "'\t'"] [("'\\t'") "'\t'"]
[else lexeme]))] [else lexeme]))]
@ -47,6 +48,7 @@
(:* (:or "\\\"" "\\n" "\\t" (:~ "\"" "\\"))) (:* (:or "\\\"" "\\n" "\\t" (:~ "\"" "\\")))
"\"") "\"")
(token-LIT (case lexeme (token-LIT (case lexeme
[("\"\\\"\"") "\"\"\""]
[("\"\\n\"") "\"\n\""] [("\"\\n\"") "\"\n\""]
[("\"\\t\"") "\"\t\""] [("\"\\t\"") "\"\t\""]
[else lexeme]))] [else lexeme]))]

@ -13,6 +13,7 @@
"test-lexer.rkt" "test-lexer.rkt"
"test-old-token.rkt" "test-old-token.rkt"
"test-parser.rkt" "test-parser.rkt"
"test-quotation-marks.rkt"
"test-simple-arithmetic-grammar.rkt" "test-simple-arithmetic-grammar.rkt"
"test-simple-line-drawing.rkt" "test-simple-line-drawing.rkt"
"test-weird-grammar.rkt" "test-weird-grammar.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" "\"" "'"))
Loading…
Cancel
Save