It works. It needs more refinement, that will come with time.
    
    
    import std/[streams]
    import npeg
    
    let stream = newStringStream("""
    0-0:96.13.0()
    1-3:0.2.8(50)
    0-0:1.0.0(221019115846S)
    1-0:32.32.0(00000)
    0-0:96.1.1(4530303737307730373236383936353232)
    1-0:1.8.1(000865.964*kWh)
    1-0:31.7.0(002*A)
    0-0:96.14.0(0002)
    1-0:99.97.0(1)(0-0:96.7.19)(220120193901W)(0000000000*s)
    0-1:24.2.1(221019115500S)(00112.177*m3)
    """
    )
    
    let p = peg("obis"):
      obis <- >obis_id * val
      val <- +('(' * *(>timestamp | >intunit  | >floatunit | >obis_id | 
>+Digit) * ')')
      obis_id <- (+Digit * "-" * +Digit * ':' * +Digit * '.' * +Digit * '.' * 
+Digit)
      timestamp <- {'0'..'9'}[12] * {'W','S'}
      intunit <- +Digit * '*' * +Alpha
      floatunit <- flt * '*' * +Alpha * *Digit
      flt <- +Digit * '.' * +Digit
      #alldata <- *{'A'..'Z','a'..'z','0'..'9','*',':','.','-'}
    
    var line: string
    while stream.readline(line):
      let m = p.match(line)
      if m.ok:
        echo m.captures
    
    
    Run

Reply via email to