From c1936bf47cc7a299aea8b340395691405cd2ca98 Mon Sep 17 00:00:00 2001 From: Gabor Melis Date: Tue, 23 Jun 2026 10:06:38 +0200 Subject: [PATCH] make STRINGs start with alphanumeric chars ... or consist of a single non-alphanumeric character. For example, this allows parsing (_x_) as emphasis. --- parser.lisp | 5 +- tests/grammar/blocks/heading.lisp | 2 +- tests/grammar/inlines/emph.lisp | 90 +++++++++++++++++++++++++++++++ tests/grammar/inlines/link.lisp | 2 +- tests/grammar/inlines/string.lisp | 4 +- tests/package.lisp | 5 +- 6 files changed, 101 insertions(+), 7 deletions(-) diff --git a/parser.lisp b/parser.lisp index e6c47fc..cdd16db 100644 --- a/parser.lisp +++ b/parser.lisp @@ -469,7 +469,10 @@ (defrule maybe-alphanumeric (& alphanumeric) (:constant "")) -(defrule string (and normal-char (* (or normal-char (and (+ #\_) maybe-alphanumeric)))) +(defrule string (or (and alphanumeric (* (or normal-char + (and (+ #\_) maybe-alphanumeric)))) + ;; This could be (+ NORMAL-CHAR), but that's a bit slower. + normal-char) (:text t)) (defrule maybe-space-char (& space-char) diff --git a/tests/grammar/blocks/heading.lisp b/tests/grammar/blocks/heading.lisp index 75d14cd..b2168da 100644 --- a/tests/grammar/blocks/heading.lisp +++ b/tests/grammar/blocks/heading.lisp @@ -71,7 +71,7 @@ World! (:LIST-ITEM (:PLAIN "First" " " "line"))) (:PLAIN " " "The" " " "header" " " - " " "=========="))) + " " "=" "=" "=" "=" "=" "=" "=" "=" "=" "="))) (def-grammar-test atx-heading-in-a-list ;; bug 35 ;;; marked bug as invalid, since original markdown is inconsistent diff --git a/tests/grammar/inlines/emph.lisp b/tests/grammar/inlines/emph.lisp index 8f681e4..fe961a9 100644 --- a/tests/grammar/inlines/emph.lisp +++ b/tests/grammar/inlines/emph.lisp @@ -103,3 +103,93 @@ :expected '((:BULLET-LIST (:LIST-ITEM (:PLAIN "First" " " "line"))) (:PARAGRAPH (:EMPH "Some" " " "text")))) + +(def-grammar-test emph-in-parens + :rule 3bmd-grammar::doc + :text "(_x_)" + :expected '((:PLAIN "(" (:EMPH "x") ")"))) + +(def-grammar-test emph-in-braces + :rule 3bmd-grammar::doc + :text "{_x_}" + :expected '((:PLAIN "{" (:EMPH "x") "}"))) + +(def-grammar-test emph-in-double-quotes + :rule 3bmd-grammar::doc + :text "\"_x_\"" + :expected '((:PLAIN "\"" (:EMPH "x") "\""))) + +(def-grammar-test emph-in-single-quotes + :rule 3bmd-grammar::doc + :text "'_x_'" + :expected '((:PLAIN "'" (:EMPH "x") "'"))) + +(def-grammar-test emph-after-comma + :rule 3bmd-grammar::doc + :text ",_x_" + :expected '((:PLAIN "," (:EMPH "x")))) + +(def-grammar-test emph-after-period + :rule 3bmd-grammar::doc + :text "._x_" + :expected '((:PLAIN "." (:EMPH "x")))) + +(def-grammar-test emph-after-semicolon + :rule 3bmd-grammar::doc + :text ";_x_" + :expected '((:PLAIN ";" (:EMPH "x")))) + +(def-grammar-test emph-after-colon + :rule 3bmd-grammar::doc + :text ":_x_" + :expected '((:PLAIN ":" (:EMPH "x")))) + +(def-grammar-test emph-after-question-mark + :rule 3bmd-grammar::doc + :text "?_x_" + :expected '((:PLAIN "?" (:EMPH "x")))) + +(def-grammar-test emph-after-equal + :rule 3bmd-grammar::doc + :text "=_x_" + :expected '((:PLAIN "=" (:EMPH "x")))) + +(def-grammar-test emph-after-plus + :rule 3bmd-grammar::doc + :text "+_x_" + :expected '((:PLAIN "+" (:EMPH "x")))) + +(def-grammar-test emph-after-minus + :rule 3bmd-grammar::doc + :text "-_x_" + :expected '((:PLAIN "-" (:EMPH "x")))) + +(def-grammar-test emph-after-caret + :rule 3bmd-grammar::doc + :text "^_x_" + :expected '((:PLAIN "^" (:EMPH "x")))) + +(def-grammar-test emph-after-slash + :rule 3bmd-grammar::doc + :text "/_x_" + :expected '((:PLAIN "/" (:EMPH "x")))) + +(def-grammar-test emph-after-bar + :rule 3bmd-grammar::doc + :text "|_x_" + :expected '((:PLAIN "|" (:EMPH "x")))) + +(def-grammar-test emph-after-percent + :rule 3bmd-grammar::doc + :text "%_x_" + :expected '((:PLAIN "%" (:EMPH "x")))) + +(def-grammar-test emph-after-dollar + :rule 3bmd-grammar::doc + :text "$_x_" + :expected '((:PLAIN "$" (:EMPH "x")))) + +(def-grammar-test emph-after-at + :rule 3bmd-grammar::doc + :text "@_x_" + :expected '((:PLAIN "@" (:EMPH "x")))) diff --git a/tests/grammar/inlines/link.lisp b/tests/grammar/inlines/link.lisp index 27a1f1b..a20d221 100644 --- a/tests/grammar/inlines/link.lisp +++ b/tests/grammar/inlines/link.lisp @@ -140,5 +140,5 @@ x" :expected '((:PARAGRAPH (:REFERENCE-LINK :LABEL ("link") :TAIL NIL)) (:PLAIN (:REFERENCE-LINK :LABEL ("link") :TAIL NIL) - ":" " " "http://example.com/" " " "\"title\"" " " + ":" " " "http://example.com/" " " "\"" "title\"" " " "junk"))) diff --git a/tests/grammar/inlines/string.lisp b/tests/grammar/inlines/string.lisp index 0281b47..f311029 100644 --- a/tests/grammar/inlines/string.lisp +++ b/tests/grammar/inlines/string.lisp @@ -16,8 +16,8 @@ (def-grammar-test string-test-3 :rule 3bmd-grammar::string :text "@a_symbol@ string with spaces." - :expected "@a_symbol@" - :remaining-text " string with spaces.") + :expected "@" + :remaining-text "a_symbol@ string with spaces.") (def-grammar-test string-test-4 :rule 3bmd-grammar::string diff --git a/tests/package.lisp b/tests/package.lisp index eae505c..f75750b 100644 --- a/tests/package.lisp +++ b/tests/package.lisp @@ -95,8 +95,9 @@ ,@(if warn ;; just supporting 1 warning for now `((is (= 1 (length signalled-warnings))) - (let ((signalled-warning (format nil "~a" - (car signalled-warnings)))) + (let* ((*print-right-margin* most-positive-fixnum) + (signalled-warning + (format nil "~a" (car signalled-warnings)))) (is (string= signalled-warning ,warn)))) `((is (not signalled-warnings))))