From 0b9d516c26758be900e5a376894f279e73790449 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Mon, 2 Feb 2026 12:59:09 +0100 Subject: [PATCH] Add escaping for doxygen token comment Many characters have special meaning and break formatting --- templates/include/prism/ast.h.erb | 2 +- templates/template.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/templates/include/prism/ast.h.erb b/templates/include/prism/ast.h.erb index 9115f20eaa..0612341772 100644 --- a/templates/include/prism/ast.h.erb +++ b/templates/include/prism/ast.h.erb @@ -22,7 +22,7 @@ */ typedef enum pm_token_type { <%- tokens.each do |token| -%> - /** <%= token.comment %> */ + /** <%= Prism::Template::Doxygen.verbatim(token.comment) %> */ PM_TOKEN_<%= token.name %><%= " = #{token.value}" if token.value %>, <%- end -%> diff --git a/templates/template.rb b/templates/template.rb index 6c3efd7e6c..aca626b5eb 100755 --- a/templates/template.rb +++ b/templates/template.rb @@ -49,6 +49,14 @@ def self.escape(value) end end + # This module contains methods for escaping characters in Doxygen comments. + module Doxygen + # Similar to /verbatim ... /endverbatim but doesn't wrap the result in a code block. + def self.verbatim(value) + value.gsub(/[\.*%!`#<>_+-]/, '\\\\\0') + end + end + # A comment attached to a field or node. class ConfigComment attr_reader :value