Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Lib/test/test_peg_generator/test_c_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,13 @@ def test_headers_and_trailer(self) -> None:
self.assertTrue("SOME SUBHEADER" in parser_source)
self.assertTrue("SOME TRAILER" in parser_source)

def test_multiple_lookahead(self) -> None:
grammar_source = 'start: !"(" NEWLINE+ !")"'
grammar = parse_string(grammar_source, GrammarParser)
parser_source = generate_c_parser_source(grammar)

self.assertNotIn("int None_1", parser_source)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hummmm. I don't like this test because is checking the implementation. What goes wrong exactly now when there are two negative lookaheads?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What goes wrong exactly now when there are two negative lookaheads?

gcc -pthread -c -Wno-unused-result -Wsign-compare -g -Og -Wall    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE -o Parser/pegen/parse.o Parser/pegen/parse.c
Parser/pegen/parse.c: In function ‘invalid_import_from_targets_rule’:
Parser/pegen/parse.c:12249:13: warning: unused variable ‘None_1’ [-Wunused-variable]
12249 |         int None_1;
      |             ^~~~~~

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hummmm. I don't like this test because is checking the implementation.

I agree with you but this is an implementation problem so I dont know exactly how to write a better test for this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you but this is an implementation problem so I dont know exactly how to write a better test for this

Yeah, let's remove the test and let's focus on why mypy has not found this.

@isidentical isidentical May 21, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because of CCallMakerVisitor's return value is Any, mypy kind a ignores it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦

Ok, will prepare a PR to fix mypy, I found a couple of other stuff.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #20297 to fix mypy issues


def test_error_in_rules(self) -> None:
grammar_source = """
start: expr+ NEWLINE? ENDMARKER
Expand Down
5 changes: 4 additions & 1 deletion Tools/peg_generator/pegen/c_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,4 +722,7 @@ def collect_vars(self, node: Alt) -> Dict[Optional[str], Optional[str]]:

def add_var(self, node: NamedItem) -> Tuple[Optional[str], Optional[str]]:
call = self.callmakervisitor.visit(node.item)
return self.dedupe(node.name if node.name else call.assigned_variable), call.return_type
name = node.name if node.name else call.assigned_variable
if name is not None:
name = self.dedupe(name)
return name, call.return_type