title: Parse subset of Python grammar
body: <p>We are working on a tool to validate user configurations. Invalid configurations will be described in some text file or json file in following form:</p>
  <pre><code>case1: if something &gt; 5 and something.else != 10
  case2: (if a &lt;= 3 or a &gt;= 5) and b == 10
  </code></pre>
  <p>In case the if statement evaluates to true, the configuration is invalid. We used SLY module to create a lexer and parser to parse this sentence and check, whether it's valid or not. After thinking a bit more, we realized, that instead of writing our own grammar, it would be interesting to use a subset of the Python grammar - let's say expressions, bool operators and few others, but not the complete set, as we don't want and need to incorporate support for functions, classes and many more. The reason for such approach was, that we are writing our tool in Python, so it could cooperate nicely.</p>
  <p>I've checked the ast module, however, I've a feeling, that the grammar is tightly coupled with it. If I understand it correctly, the Python parser is not generated automatically using some existing parser generator based on a grammar, right? The parser is &quot;hard coded&quot;. Or em I wrong?</p>
  <p>Is there &quot;simple&quot; way of doing this?</p>
  <p>In general, we are looking for a parser generator, which generates the parser for a subset of Python grammar, but I'm afraid to cover part of the Python grammar, we would need to write the grammar by ourselves and based on it generate a parser. Is my assumption right?</p>