neon
neon

Reputation: 31

order of words in python

I have a code like:

class <name>
{
public:
...
private:
...
};

I want to ensure that the public section is declared before the private section and not after that.One way of doing this in Python is by comparing the line numbers where these words occur.However,am not sure if this would work when I have several such sections(such declarations) in my code.Any other suggestions?

Upvotes: 0

Views: 115

Answers (1)

David Heffernan
David Heffernan

Reputation: 612894

This problem is, in general, much harder than you think. Not all classes are laid out like that.

  1. Some won't have private sections and rely on the default visibility.
  2. Some might not have public sections.
  3. Some might have multiple private and/or public sections.
  4. How will you know when the class declaration has finished? You don't want to move code around from another class!
  5. Some classes might use macros which will throw you.

And so on. To do this properly and reliably you need a proper C++ parser which is notoriously hard to get right. Don't try to implement one of those yourself using simple text search.

Upvotes: 4

Related Questions