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

Split apart grammar.py and segments_*.py. Introduce Parser class. #510

Merged
merged 4 commits into from Oct 28, 2020

Conversation

alanmcruickshank
Copy link
Member

This is another meaty re-org. Reason for this change is twofold:

  1. We had a couple of really big source files. Especially grammar.py, which were very difficult to navigate. This PR splits up some of those larger source files into their own modules, namely sqlfluff.core.parser.segments and sqlfluff.core.parser.grammar.
  2. Dependency was really unclear between some segments and some grammars. In particular the FileSegment was a bit of an anomaly in that it depended on grammars, and also that it was instantiated directly to initiate parsing.

This PR does four things:

  • Refactors grammar.py into a module of seperate source files in sqlfluff.core.parser.grammar.
  • Refactors segments_base.py, segments_common.py & segment_generator.py into a module of smaller seperate source files in sqlfluff.core.parser.segments.
  • Moves the main content of segments_file.py into dialect_ansi.py, with the logic in the .from_raw() method (which used to be called as the standard way of parsing a lexed file) moved into a Parser class which can be called directly, much like the way that Lexer already exists. This also has the upshot of removing the need for modules outside the parser to deal with RootParseContext and so this has been removed from the public interface of this module.

@codecov
Copy link

codecov bot commented Oct 28, 2020

Codecov Report

Merging #510 into master will decrease coverage by 0.02%.
The diff coverage is 92.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #510      +/-   ##
==========================================
- Coverage   93.14%   93.12%   -0.03%     
==========================================
  Files          32       42      +10     
  Lines        4812     4855      +43     
==========================================
+ Hits         4482     4521      +39     
- Misses        330      334       +4     
Flag Coverage Δ
#py36 93.00% <92.09%> (-0.03%) ⬇️
#py37 93.00% <92.09%> (-0.03%) ⬇️
#py38 92.95% <91.94%> (-0.03%) ⬇️
#py39 92.95% <91.94%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/sqlfluff/core/parser/segments/generator.py 100.00% <ø> (ø)
src/sqlfluff/core/linter.py 88.42% <72.72%> (+0.02%) ⬆️
src/sqlfluff/core/parser/grammar/greedy.py 86.58% <86.58%> (ø)
src/sqlfluff/core/parser/grammar/delimited.py 89.15% <89.15%> (ø)
src/sqlfluff/core/parser/grammar/base.py 90.73% <90.73%> (ø)
src/sqlfluff/core/parser/grammar/sequence.py 90.81% <90.81%> (ø)
src/sqlfluff/core/parser/segments/indent.py 94.59% <94.59%> (ø)
src/sqlfluff/core/parser/helpers.py 96.66% <96.66%> (ø)
src/sqlfluff/core/parser/segments/raw.py 97.14% <97.14%> (ø)
src/sqlfluff/core/parser/grammar/anyof.py 97.19% <97.19%> (ø)
... and 24 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c58a3f4...cd8fe68. Read the comment docs.

@alanmcruickshank alanmcruickshank merged commit 969c11e into master Oct 28, 2020
@alanmcruickshank alanmcruickshank deleted the ac/clearup branch October 28, 2020 23:00
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

Successfully merging this pull request may close these issues.

None yet

1 participant