the parser may leave a remainder at the end of the string if it doesn't match any of the rules, mark them as unknowns
(self)
| 892 | return self.groups |
| 893 | |
| 894 | def _mark_unparsed_unknown(self): |
| 895 | """the parser may leave a remainder at the end of the string if it doesn't |
| 896 | match any of the rules, mark them as unknowns""" |
| 897 | parsed = [False] * len(self.s) |
| 898 | |
| 899 | # go over all existing matches to see if we've covered the |
| 900 | # current position |
| 901 | for mr in self.all_matches: |
| 902 | for i in range(mr.start, mr.end): |
| 903 | parsed[i] = True |
| 904 | |
| 905 | for i, parsed_i in enumerate(parsed): |
| 906 | c = self.s[i] |
| 907 | # whitespace is always 'unparsed' |
| 908 | if c.isspace(): |
| 909 | parsed[i] = True |
| 910 | |
| 911 | # the parser ignores comments but we can use a trick to see if this |
| 912 | # starts a comment and is beyond the ending index of the parsed |
| 913 | # portion of the input |
| 914 | if (not self.ast or i > self.ast.pos[1]) and c == "#": |
| 915 | comment = MatchResult( |
| 916 | i, len(parsed), help_constants.COMMENT, None, {"kind": "comment"} |
| 917 | ) |
| 918 | self.groups[0].results.append(comment) |
| 919 | break |
| 920 | |
| 921 | if not parsed[i]: |
| 922 | # add unparsed results to the 'shell' group |
| 923 | self.groups[0].results.append(self.unknown(c, i, i + 1)) |
| 924 | |
| 925 | # there are no overlaps, so sorting by the start is enough |
| 926 | self.groups[0].results.sort(key=lambda mr: mr.start) |
| 927 | |
| 928 | def _result_index(self): |
| 929 | """return a mapping of `MatchResult`s to their index among all |
no test coverage detected