-
Notifications
You must be signed in to change notification settings - Fork 95
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
Edits #78
base: master
Are you sure you want to change the base?
Edits #78
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a pass and it generally looks good to me. Granted I haven't touched the parser in years so we're learning together. :-)
Left a few small comments, let's fix those and add some tests? Thanks for the contribution!
bashlex/parser.py
Outdated
|
||
def p_pattern_list(p): | ||
'''pattern_list : newline_list pattern RIGHT_PAREN compound_list | ||
| newline_list pattern RIGHT_PAREN newline_list | ||
| newline_list LEFT_PAREN pattern RIGHT_PAREN compound_list | ||
| newline_list LEFT_PAREN pattern RIGHT_PAREN newline_list''' | ||
handleNotImplemented(p, 'pattern list') | ||
|
||
parserobj = p.context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taken care of
bashlex/parser.py
Outdated
rparen = ast.node(kind='reservedword', word=p[4], pos=p.lexspan(4)) | ||
parts.extend([lparen, patterns, rparen]) | ||
if p.slice[-1].type == "compound_list": | ||
# for some reason, p[-1] does not give the "true" last element, do not know why |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I've pushed my updated code which I believe to be correct (although resulting in a somewhat unintuitive AST, in my opinion, but it seems right). Locally, "make tests" doesn't work, it gives an error in the "malformed if" case, which is odd since I didn't touch that, to my knowledge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good overall!
- can you please look at the test failures
- please squash the commits, i think you want to end up with one?
bashlex/parser.py
Outdated
redirects = [], | ||
list=[ast.node(kind='case', parts=parts, pos=_partsspan(parts))], | ||
pos=_partsspan(parts)) | ||
#handleNotImplemented(p, 'case command') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left over
@@ -377,14 +382,36 @@ def p_elif_clause(p): | |||
def p_case_clause(p): | |||
'''case_clause : pattern_list | |||
| case_clause_sequence pattern_list''' | |||
handleNotImplemented(p, 'case clause') | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary new line here
|
||
def p_pattern_list(p): | ||
'''pattern_list : newline_list pattern RIGHT_PAREN compound_list | ||
| newline_list pattern RIGHT_PAREN newline_list | ||
| newline_list LEFT_PAREN pattern RIGHT_PAREN compound_list | ||
| newline_list LEFT_PAREN pattern RIGHT_PAREN newline_list''' | ||
handleNotImplemented(p, 'pattern list') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
patterns = p[3] | ||
rparen = ast.node(kind='reservedword', word=p[4], pos=p.lexspan(4)) | ||
parts.extend([lparen, patterns, rparen]) | ||
if p.slice[-1].type == "compound_list": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a comment that explains this part
|
||
def p_pattern(p): | ||
'''pattern : WORD | ||
| pattern BAR WORD''' | ||
handleNotImplemented(p, 'pattern') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newline
;; | ||
esac | ||
""" | ||
self.assertASTEquals(s, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see what you mean about the resulting ast :) is there a more condensed way to represent it, that is still in line with how everything else is parsed?
I'm not sure what is going on with the test failures, I'm still looking into it, but the failures are in parts of the code that I hadn't knowingly touched (malformed if statements). I'll make sure to squash the commits on the next one (I'm pretty sure there are going to be more changes). |
Made some changes to parser and ast to support case_clauses and patterns. Submitting as a draft PR because I'm not sure if it is correct (it looks correct to me on the example I tested on, but I don't know how to compare it to the "canonical" ast).