Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub URLDecode(ByVal cb As uCalc.Callback)
      '// In a real application, this would be a full URL decoding implementation.
      '// For this example, we'll just handle spaces (%20) and plus signs (+).
      Dim s As uCalc.String = cb.ArgStr(1)
      s.Replace("%20", " ").Replace("+", " ")
      cb.ReturnStr(s.Text)
   End Sub
   
   Public Sub Main()
      Dim uc As New uCalc()
      '// 1. Define the custom URLDecode function in the uCalc engine
      uc.DefineFunction("URLDecode(s As String) As String", AddressOf URLDecode)
      
      '// 2. Create the transformer and configure its tokenizer
      Using t As New uCalc.Transformer(uc)
         '// Treat '&' as a statement separator to process each pair individually
         t.Tokens.Add("&", TokenType.StatementSep)
         
         '// 3. Define the rule to capture key-value pairs and decode the value
         t.FromTo("{@Alphanumeric:key}={value}", "- {key}: '{@Eval: URLDecode(value)}'")
         
         '// 4. Process a real-world query string
         Dim queryString = "name=John%20Doe&role=user+admin&id=123"
         
         '// Use Filter() to get a clean, newline-separated list of the results
         Console.WriteLine(t.Transform(queryString).Matches)
      End Using
   End Sub
End Module