Hacker News new | past | comments | ask | show | jobs | submit login

While Ruby and Perl cannot be parsed, Python can be parsed correctly.



Technically correct. Practically there is a tiny subset of Perl that the parser cannot decide correctly, which is used by virtually nobody. Almost all of the code on CPAN can be parsed just fine by this module: https://metacpan.org/module/PPI


I don't understand what you mean by parsing if not what the interpreter does. Can you give an example?


Perl (and I assume Ruby from the comment) requires the running context of the interpreter to make decisions about how to interpret some code constructs. Because you need the running state, it is not parseable.


Parsing as in determining what constructs different lines represent, without running them. Imagine e.g. a documentation generator that needs to figure out what all your methods and parameters are, but not actually execute them (obviously there are many other use cases).

A friend at an old job had a piece of perl code where one of the lines would be a comment or not when you ran it, depending on user input. He would bring it out whenever someone suggested writing something in perl.


Uh, ruby can be parsed, it's just hard. It's waaaay saner than perl.


If you emulate the way the MRI parses it, sure.

For example:

  # Is this some_method with an empty block, or an empty hash?
  some_method {}

  # Is this a regex or a comment?
  #
  # It depends how many arguments "whatever" takes, and you
  # don't know that until you run the code that defines it.
  #
  # Interpretation is implementation-defined. It just so
  # happens that the MRI determines that the below ISN'T a
  # regex because it has a SPACE character just after the "/".
  whatever  / 25 ; # / ; raise SystemExit.new;




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: