Commit graph

226 commits

Author SHA1 Message Date
Jennifer Taylor
f9ff50047e Bump hypothesis/hypothesmith version now that https://github.com/Zac-HD/hypothesmith/issues/3 is resolved. 2019-09-10 16:57:16 -07:00
Jennifer Taylor
036cfbc765 Pin Hypothesis to work around https://github.com/Zac-HD/hypothesmith/issues/3 2019-09-09 16:02:24 -07:00
Gareth T
41af9de31d [docs] Small update and corrections to documentation. (#55) 2019-09-03 10:30:08 -07:00
jimmylai
b232547826
[typing] refactor TypeVar CSTNodeT for consistency and reusability (#54) 2019-08-29 21:30:34 -07:00
Jennifer Taylor
38d220d224 Bump version number to 0.1.2. 2019-08-29 14:25:37 -07:00
Jennifer Taylor
0d2b66a1e7 Add more documentation around attribute visitors.
Adds a bit more documentation to various pieces of attribute visitors.
Adds a section around traversal order of visitors given a tree.
2019-08-29 14:16:51 -07:00
Jennifer Taylor
ce47f864a2 Create a config_for_parsing property on Module.
This is useful when you are using `parse_expression` or `parse_statement`
to generate a tree from a source string that is meant to be later added
to an existing module. It allows you to more easily configure both of these
parser functions to output a tree which has the same defaults as the `Module`
that you previously parsed out.
2019-08-29 14:16:25 -07:00
Jennifer Taylor
9a90fda8c3 Document additional caveats with parse_statement and parse_expression. 2019-08-29 11:33:57 -07:00
Jennifer Taylor
687f47c5aa Update hypothesis tests to reflect new reality.
`parse_statement` and `parse_expresssion` aren't guaranteed to round-trip
exactly due to the fact that they don't have a wrapping Module to encapsulate
miscelaneous spacing. So, update the tests to verify that the rendered code
is identical to the original code based on the AST. Also, while I'm at it,
bump up Hypothesis's maximums in order to stress LibCST more.
2019-08-29 11:33:57 -07:00
Jennifer Taylor
ed73b0456f Allow more esoteric spacing in Import statement. 2019-08-29 11:33:57 -07:00
Jennifer Taylor
6dca3c914e Fix inability to parse certain expressions that ast.parse parses. 2019-08-29 11:33:57 -07:00
Jennifer Taylor
95f649af79 Fix incorrect round-tripping of newlines when parsing statements.
Hypothesis found that when we have a statement like `pass\r`, we detect that
`\r` is the default and parse the trailing newline as `Newline(None)`. However, when
we render the statement back out again, since we don't have a module, we construct
a default module which treats `Newline(None)` as a `\n` not a '\r'. So, when we are
parsing statements or expressions, disable auto-inferring the default newline and always
infer the default rendered newline (`\n`) so that rendering a statement/expression back
out behaves as expected.
2019-08-29 11:33:57 -07:00
jimmylai
70d6ca6513
[doc] improve metadata docs. (#50) 2019-08-28 13:41:31 -07:00
Jennifer Taylor
956460617e Codegen attribute visitors. 2019-08-28 13:28:29 -07:00
Jennifer Taylor
53fae25b7d Visit and leave attributes. 2019-08-28 13:28:29 -07:00
Jennifer Taylor
7287190e21 Pass parent down to visitor helper methods in preparation for attribute visitors. 2019-08-28 13:28:29 -07:00
Jennifer Taylor
0da658d183 Calculate necessity of MaybeSentinel/RemovalSentinel based on usage.
There are a lot of nodes that cannot be removed or converted to maybes, such as
most of the Op tokens. It would be a bit of a lie to codegen leave_* methods
that allow these nodes to be converted, only to throw a runtime error later. So,
upgrade the codegen to allow us to see whether certain nodes are used in conjunction
with a MaybeSentinel/None, or inside a Sequence, to inform ourselves as to when to
allow MaybeSentinel or RemovalSentinel.
2019-08-28 13:28:29 -07:00
Jennifer Taylor
f1e97748f2 Add a BaseStatement type.
Adds a BaseStatement type which can be used to specify in types that you can
accept either a compound statement or a simple statement line.
2019-08-28 13:28:29 -07:00
Jennifer Taylor
90e39ca4fa Add a tox environment for running codegen. 2019-08-28 13:28:29 -07:00
Jennifer Taylor
f9437f42b4 Add unit test to verify that codegen is clean.
We want to make sure that the generated function stubs stay in sync with
the node definitions. So, make a unit test that fails if codegen generates
a different file than the existing file, so that somebody modifying code
knows they need to re-run codegen.
2019-08-28 13:28:29 -07:00
Jennifer Taylor
f14b4fa37c Add codegen for visit_* and leave_* methods on CSTTransform and CSTVisitor.
This allows Pyre to typecheck returns inside visitors for us.
2019-08-28 13:28:29 -07:00
jimmylai
b19732938c
[metadata] add ExpressionContextProvider (#49)
* [metadata] add ExpressionContextProvider

* address comments
2019-08-27 19:07:28 -07:00
jimmylai
f818773652
[CI] move test coverage job as a separate job (#48) 2019-08-27 08:46:35 -07:00
Jennifer Taylor
9ab56f4d36 Add hypothesis tests to its own env for now until we can fix all the bugs in LibCST. 2019-08-22 16:05:10 -07:00
Jennifer Taylor
00aeb6817a Fix incorrect space validation with Unary operators.
This was found by Hypothesis, so lets fix it! Turns out we aren't recursively
evaluating whether an expression can be used without spaces against a word
operator. That means that complex expressions such as `not...^A` fail to parse
when we really should allow such expressions.
2019-08-22 16:05:10 -07:00
Benjamin Woodruff
4c50974606 Document where CodeRange is inclusive/exclusive (#47)
Fixes #42.
2019-08-22 15:35:29 -07:00
Benjamin Woodruff
aac5103592 Add PartialParserSyntaxError, simplify ParserSyntaxError
Because the parser conversion functions may not understand their current
position in the code, we instead need to construct a `ParserSyntaxError`
without the current line and column information, filling it in later.

Originally I did this by allowing ParserSyntaxError to be partially
initialized, but this wasn't very type-safe, and required some ugly
assertions.

Instead, I now construct and raise a PartialParserSyntaxError. The
BaseParser class is responsible for catching that partial error object
and constructing a full ParserSyntaxError.
2019-08-22 13:35:11 -07:00
Benjamin Woodruff
283a736173 Make conversion functions use ParserSyntaxError
For anything that's not an internal logic error, conversion functions
should raise a ParserSyntaxError.

Internal logic errors should probably use an AssertionError or an assert
statement, but that's not as important and is out of scope for this PR.
2019-08-22 13:35:11 -07:00
Benjamin Woodruff
e9567a08c0 Add tests to the parser for syntax errors
This tries to test all the ways a ParserSyntaxError can be thrown.
2019-08-22 13:35:11 -07:00
Benjamin Woodruff
7fe92e84df Improve the quality of syntax error messages
- Make INDENT/DEDENT dummy tokens more readable instead of outputting an
  empty string for them.

- Sort the "expected" list to make testing easier.

- Don't show the list of expected values if there are > 10
  possibilities. The output becomes impossible to read at that point.

- Try to avoid using an empty line for the displayed contextual line of
  source code. Instead, point at the line above it, or just don't output
  any context.
2019-08-22 13:35:11 -07:00
Benjamin Woodruff
f34d6a80fe Include ParserSyntaxError in parser documentation 2019-08-22 13:35:11 -07:00
Benjamin Woodruff
636cad6e6c Raise a ParserSyntaxError on mismatched braces
If we had more close braces than open braces, we used to raise an
IndexError due to an empty stack. This fixes that bug.
2019-08-22 13:35:11 -07:00
Benjamin Woodruff
2459ba0aa0 Make ParserSyntaxError more generic (#24)
This removes the hard-coded logic about encountered/expected, and moves
it into a separate helper method.

Line and column can now be initialized lazily. We'll use this later to
raise `ParserSyntaxError`s inside of conversion functions, backfilling
the positions inside `_base_parser`, since conversion functions don't
always have access to position information.
2019-08-22 13:35:11 -07:00
Benjamin Woodruff
2d1d2f7aa1 Add a pickle test for ParserSyntaxError
This ensures that ParserSyntaxError can safely be used with pickle, and
(by extension) multiprocessing.
2019-08-22 13:35:11 -07:00
Zac Hatfield-Dodds
2c27c0862c Fuzz with Hypothesmith 2019-08-21 17:55:28 -07:00
jimmylai
750b18c5fe
add PYPI version badge to readme (#41) 2019-08-21 11:52:57 -07:00
Jennifer Taylor
b3d5f462a5 Update changelog with new release information. 2019-08-20 16:09:15 -07:00
Jennifer Taylor
941dee9977 Bump revision number to release 0.1.1 which corrects dependencies. 2019-08-20 15:53:16 -07:00
Benjamin Woodruff
53a7c782d4 Improve PartialParserConfig's documentation
Adds details about how various configuration options can be used, and
updates some details to reflect reality (e.g. we don't currently infer
the python version from your execution environment).
2019-08-19 17:09:55 -07:00
Benjamin Woodruff
821a613c46 Raise an exception on unsupported python_version
We only support parsing code as 3.7 right now.

This raises a descriptive error message if we receive an unsupported
version number, instead of silently trying to use it with the tokenizer
and failing in potentially strange ways.
2019-08-19 17:09:55 -07:00
jimmylai
2f33bdd912
Add CodeCov badge in README 2019-08-19 13:44:52 -07:00
jimmylai
71ba5cc51d
update dependent package version in setup.py 2019-08-19 13:39:02 -07:00
jimmylai
d4dca1db5e
[CI] add test coverage run and codecov integration 2019-08-19 11:31:55 -07:00
Ray Zeng
68699e21d7 Add more examples and improve docstrings 2019-08-16 10:34:30 -07:00
Ray Zeng
e2f2eafc59 Add extended example for metadata and fix some docstrings 2019-08-16 10:34:30 -07:00
Ray Zeng
fa6bb4942c Moved metadata usage example into usage.ipynb 2019-08-16 10:34:30 -07:00
Ray Zeng
b2e26db708 resort imports 2019-08-16 10:34:30 -07:00
Ray Zeng
d91a79220b Fix some typing and improve some docstrings for metadata 2019-08-16 10:34:30 -07:00
Ray Zeng
f0b6e6c37d Re-organize metadata documentation and add a usage example 2019-08-16 10:34:30 -07:00
Ray Zeng
2e8c3b6756 Convert CodeRange.create to a constructor to clean up docs 2019-08-16 10:34:30 -07:00