# liblouis: common rules for Classical/Biblical Hebrew
#
#-license: lgpl-2.1

# This file is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this file; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
# liblouis  comes with ABSOLUTELY NO WARRANTY.

# This table contains rules that are shared by all three Classical/
# Biblical Hebrew systems: the International Hebrew Braille Code
# (hbo-ihbc.uti and hbo.utb), the fully cantillated IHBC-McAllister
# system (hbo-cantillated.uti and hbo-cantillated.utb), and the
# Katz system with no shewas or dageshes (hbo-slim.uti and
# hbo-slim.utb).

# Developed by Eric J. Harvey with support from the national
# Endowment for the Humanities (USA) and Stanford University.
# Many thanks to Leonard de Ruijter, Sarah Blake LaRose, Matthew
# Yeater, and Paul Geoghegan for their help developing and testing the
# tables, and to Abbie Howell for suggesting the inclusion of Yiddish
# characters and reviewing code.

# Copyright (C) 2025 Eric J. Harvey

#-copyright: 2025, Eric J. Harvey

#-maintainer: Eric J. Harvey <eric@blindscholar.com>

#-author: Eric J. Harvey <eric@blindscholar.com>

# Include common characters
include he-common-consonants.uti
include he-common-vowels-ihbc.uti
include spaces.uti

# Eliminate direction-switching characters
noback correct "‎" ?  # Left-to-right mark
noback correct "‏" ?  # Right-to-left mark
noback correct "‭" ?  # left-to-right override
noback correct "‮" ?  # Right-to-left override

# In rules below, attribute $x is %vowel, defined in he-common-vowels-ihbc.uti
# Attribute $y is %extcant, defined in he-common-vowels-ihbc.uti

# character reordering
## Move dagesh before nearest preceding consonant
noback correct [$l]"ּ" "ּ"*
noback correct [$l$xy.]"ּ" "ּ"*

## Move shin and sin dot next to sin/shin consonant
## Prerequisite for “always” rule in he-common-consonants.uti
## to work with vocalized texts.
noback correct [$xy.]"ׂ" "ׂ"*
noback correct [$xy.]"ׁ" "ׁ"*

# Contracting dagesh for bet, kaf, pe, and tav
noback context "ּב" @12
noback context "ּכ" @13
noback context "ּך" @13
noback context "ּפ" @1234
noback context "ּף" @1234
noback context "ּת" @1256

# Contracting ultralong vowels (vowel+mater lectionis)
attribute majCant \x05bc\x05bd

## Holam-waw and consonantal waw
noback pass3 !$xyz[@2456-135a] @246
noback pass3 [@2456-135a]$sp @246
noback pass3 [@2456-135a]~ @246
noback pass3 [@135a-2456]%hebLetter @246

## Shuruq and consonantal waw
noback context `["ּו"] @346
noback context ["ּו"]~ @346
noback pass3 [@5-2456]!$xy @346
noback pass2 @156-5-2456 @156-346
noback pass2 @146-5-2456 @146-346

## Hiriq Yod
noback pass3 @24a-245 @35 Hiriq-yod

## Contract tsere-yod
noback pass3 @34a-245 @3456

## Shin and sin with dagesh
noback correct ["ש"$xy.]"\x05bc\x05c2" "\x05bc\x05c2"*
noback correct ["ש"$xy.]"\x05bc\x05c1" "\x05bc\x05c1"*
noback always \x05c1\x05e9 146
noback always \x05c2\x05e9 156
noback pass3 @146-5 @5-146
noback pass3 @156-5 @5-156

## Changing dagesh-he to mappiq
noback pass4 @5-125 @45-125

# Back-translation rules
## dagesh
nofor pass2 @5[$l] *@5

## Reverse mappiq
nofor pass3 @45-125 @5-125

## Uncontract hiriq-yod
nofor pass4 @35 @24-245 Hiriq-yod

## Uncontract tsere-yod
nofor pass4 $lxy[@3456] @34-245

## Final letters
nofor correct "כ"~ "ך"
nofor correct "כ"[$sp] "ך"*
nofor correct "כ"[$S.$sp] "ך"*
nofor correct "כ"[$S.]~ "ך"*
nofor correct "מ"~ "ם"
nofor correct "מ"[$sp] "ם"*
nofor correct "מ"[$S.$sp] "ם"*
nofor correct "מ"[$S.]~ "ם"*
nofor correct "נ"~ "ן"
nofor correct "נ"[$sp] "ן"*
nofor correct "נ"[$S.$sp] "ן"*
nofor correct "נ"[$S.]~ "ן"*
nofor correct "פ"~ "ף"
nofor correct "פ"[$sp] "ף"*
nofor correct "פ"[$S.$sp] "ף"*
nofor correct "פ"[$S.]~ "ף"*
nofor correct "צ"~ "ץ"
nofor correct "צ"[$sp] "ץ"*
nofor correct "צ"[$S.$sp] "ץ"*
nofor correct "צ"[$S.]~ "ץ"*

## Holam-waw and shuruq
nofor always וּ 346
nofor always וֹ 246
