The Shulchan Aruch · Orach Chayim
אורח חיים רפ״חOrach Chayim 288
Siman 288 of 697 in Orach Chayim — 10 se'ifim
הלכות שבתLaws of Shabbat· siman 288
Se’if 1א׳
אָסוּר לְהִתְעַנּוֹת בְּשַׁבָּת עַד ו' שָׁעוֹת. הַגָּה: וַאֲפִלּוּ לוֹמֵד וּמִתְפַּלֵּל, אָסוּר (מָרְדְּכַי פ"ק דְּשַׁבָּת).
Ruling of a fast and ruling of a fast for a dream on Shabbat; contains 10 subsections. It is forbidden to fast until six hours on Shabbat. Rema: and even for the purpose of learning or praying, it is forbidden [to fast] [Mordechai]
Se’if 2ב׳
יֵשׁ אוֹמְרִים שֶׁאָדָם שֶׁמַּזִּיק לוֹ הָאֲכִילָה, דְּאָז עֹנֶג הוּא שֶׁלֹּא לֶאֱכֹל, לֹא יֹאכַל. הַגָּה: וְכֵן מִי שֶׁיֵּשׁ לוֹ עֹנֶג אִם יִבְכֶּה, כְּדֵי שֶׁיֵּלֵךְ הַצַּעַר מִלִּבּוֹ, מֻתָּר לִבְכּוֹת בְּשַׁבָּת (אָגוּר בְּשֵׁם שִׁבּוֹלֵי הַלֶקֶט).
Some say that a person who is harmed by eating, such that it is their delight not to eat, should not eat. Rema: And so with one who finds delight in weeping, in order that their pain will leave their heart: such a person is permitted to weep on Shabbat. (Igur in the name of the Shibolei haLeket)
Se’if 3ג׳
אָדָם הַמִּתְעַנֶּה בְּכָל יוֹם וַאֲכִילָה בְּשַׁבָּת צַעַר הוּא לוֹ מִפְּנֵי שִׁנּוּי וֶסֶת (פי' דָּבָר קָבוּעַ), יֵשׁ אוֹמְרִים שֶׁרָאוּ כַּמָּה חֲסִידִים וְאַנְשֵׁי מַעֲשֶׂה שֶׁהִתְעַנּוּ בְּשַׁבָּת מִטַּעַם זֶה, וְכֵן אָמְרוּ שֶׁכָּךְ הָיָה עוֹשֶׂה הר"י הֶחָסִיד.
Regarding a person who fasts every day, and eating on Shabbat is painful for him because of the change in routine (explanation: a fixed thing), some say they have seen many pious and noble people who have fasted on Shabbat because of this reasoning, and they say that so acted Rabbi Yehuda heChasid.
Shulchan Aruch, Orach Chayim — Torat Emet 363 edition, via Sefaria — public domain
English: Sefaria Community Translation — CC0