Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug code left in regex example #26

Open
doug719 opened this issue Jun 18, 2023 · 2 comments
Open

Debug code left in regex example #26

doug719 opened this issue Jun 18, 2023 · 2 comments

Comments

@doug719
Copy link

doug719 commented Jun 18, 2023

In part VI, process execution, parsing data files(in parallel), using regular expressions:

the code has
if match(l,r,m):
when true: #debug
discard

Maybe this was intended to bypass the large amount of output. Maybe writing it to a file would be better.

@StefanSalewski
Copy link
Owner

Thanks for reporting. I think you are referring to the example

import regex
from std/strutils import repeat
const
  FileName = "csvdata.txt"
  P = """([^,]+)"""
  r = re(repeat(P & ',', 5) & P)

proc main =
  var m: RegexMatch
  for l in Filename.lines:
    if l[0] != '#': # skip first two and all other comment lines
      if match(l, r, m):
        when true: # debug
          discard
        else:
          for i in 0 .. 5:
            stdout.write(m.group(i, l))
            stdout.write(' ')
          echo ""
      else:
        assert false

main()

Yes, the statement "when true: discard" was intended to avoid all the output, because we try to compare the performance of various parsing strategies. With actual output, that would be dominated by the relatively slow output operation. Maybe I should better have defined a const named Debug, and used that const to suppress output. I think some of the other examples do that. I may adapt this example next time when I apply again some tiny grammar fixes. I think GPT-4 may find some more.

And congratulations that you have managed to read the book so far. Have you been able to follow the explanations and understand them?

Best regards,

Stefan Salewski

@doug719
Copy link
Author

doug719 commented Jun 19, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants