I wanted to improve the rule Tiago created years ago that detects spaces before punctuation so that it can remove false positives when we are referring to file extensions.
The problem is that his rule has no “pattern” so the “antipattern” triggers an error:
RULE:
<rulegroup id="SPACE_BEFORE_PUNCTUATION" name="Espaços antes da pontuação">
<!-- Based on German grammar.xml, by Tiago F. Santos, 2017-07-08 -->
<rule>
<regexp>\b([\p{L}\d]+) ([!?»”’,….])</regexp>
<message>Remova o espaço antes deste sinal de pontuação.</message>
<suggestion>\1\2</suggestion>
<example correction="escapou!">Como é que isto me <marker>escapou !</marker></example>
<!--example correction="escapou!">Como é que isto me <marker>escapou !</marker></example-->
<example correction="roda.">Existem duas estratégias possíveis: aproveitar o que existe ou reinventar a <marker>roda .</marker></example>
</rule>
<rule>
<regexp>\b([\p{L}\d]+) ([:;])(?![\-o]?(?:[()/]|[DSP]\b))</regexp>
<message>Remova o espaço antes deste sinal de pontuação.</message>
<suggestion>\1\2</suggestion>
<example correction="possíveis:">Existem duas estratégias <marker>possíveis :</marker> aproveitar o que existe ou reinventar a roda.</example>
<example>Um sorriso :-)</example>
<example>Um sorriso :)</example>
<example>Um sorriso :(</example>
<example>Um sorriso :-/</example>
<example>Um sorriso :/</example>
<example>Um sorriso :D</example>
<example correction="Brasil;">Site de Instituto Ludwig von Mises <marker>Brasil ;</marker>Principais portais web</example>
</rule>
</rulegroup>
I checked the diff before and after your suggestions and the results are very different:
<rulegroup id="SPACE_BEFORE_PUNCTUATION" name="Espaços antes da pontuação">
<!-- Based on German grammar.xml, by Tiago F. Santos, 2017-07-08 -->
<!-- Converted <regexp> to <pattern> thanks to Ruud and Udomai - 2021-09-02 -->
<rule>
<pattern>
<token regexp="yes">[\p{L}\d]+</token>
<token spacebefore="yes" regexp="yes">[!?»”’,….]</token>
<!-- <regexp>\b([\p{L}\d]+) ([!?»”’,….])</regexp> *** TIAGO VERSION 2017-07-08 *** -->
</pattern>
<message>Remova o espaço antes deste sinal de pontuação.</message>
<suggestion>\1\2</suggestion>
<example correction="escapou!">Como é que isto me <marker>escapou !</marker></example>
<!--example correction="escapou!">Como é que isto me <marker>escapou !</marker></example-->
<example correction="roda.">Existem duas estratégias possíveis: aproveitar o que existe ou reinventar a <marker>roda .</marker></example>
</rule>
<rule>
<regexp>\b([\p{L}\d]+) ([:;])(?![\-o]?(?:[()/]|[DSP]\b))</regexp>
<message>Remova o espaço antes deste sinal de pontuação.</message>
<suggestion>\1\2</suggestion>
<example correction="possíveis:">Existem duas estratégias <marker>possíveis :</marker> aproveitar o que existe ou reinventar a roda.</example>
<example>Um sorriso :-)</example>
<example>Um sorriso :)</example>
<example>Um sorriso :(</example>
<example>Um sorriso :-/</example>
<example>Um sorriso :/</example>
<example>Um sorriso :D</example>
<example correction="Brasil;">Site de Instituto Ludwig von Mises <marker>Brasil ;</marker>Principais portais web</example>
</rule>
</rulegroup>