Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Using validator As New uCalc.Transformer()
         '// 1. Configure the transformer
         validator.DefaultRuleSet.StatementSensitive = false
         validator.SkipOver(";{line}") '// Ignore comments
         
         '// 2. Define rules with validation constraints
         Dim serverRule = validator.Pattern("'['Server']' {body}").SetMinimum(1).SetMaximum(1)
         serverRule.Description = "Server Section"
         
         Dim local_t = serverRule.LocalTransformer
         Dim hostRule = local_t.Pattern("Host = {@Alpha}").SetMinimum(1).SetMaximum(1)
         hostRule.Description = "Host Key"
         
         Dim portRule = local_t.Pattern("Port = {@Number}").SetMinimum(1)
         portRule.Description = "Port Key"
         
         '// --- Test Data ---
         
         Dim validConfig = "[Server]" & vbNewLine & "Host = db1" & vbNewLine & "Port = 1433"
         Dim invalidConfig = "Host = web1" & vbNewLine & "Port = 80" '// Missing [Server] section
         
         '// --- Validate validConfig ---
         Console.WriteLine("--- Validating valid_config.ini ---")
         validator.SetText(validConfig).Find()
         Console.WriteLine($"  Server section check passed: {serverRule.Matches.Count() = 1}")
         Console.WriteLine($"  Host key check passed: {hostRule.Matches.Count() = 1}")
         Console.WriteLine($"  Port key check passed: {portRule.Matches.Count() >= 1}")
         Console.WriteLine("")
         
         '// --- Validate invalidConfig ---
         Console.WriteLine("--- Validating invalid_config.ini ---")
         validator.SetText(invalidConfig).Find()
         Console.WriteLine($"  Server section check passed: {serverRule.Matches.Count() = 1}")
         '// The host and port rules will have 0 matches because their parent rule (serverRule) failed.
         Console.WriteLine($"  Host key check passed: {hostRule.Matches.Count() = 1}")
         Console.WriteLine($"  Port key check passed: {portRule.Matches.Count() >= 1}")
      End Using
   End Sub
End Module