Return a list of Token objects with pos and line number collected from the file at `location` or the `query_string` string. `dictionary` is the index mapping a token string to a token id. NOTE: the _cache={} arg IS A GLOBAL mutable by design.
(
location,
query_string,
dictionary,
start_line=1,
_cache={},
)
| 2916 | |
| 2917 | |
| 2918 | def tokenize_matched_text( |
| 2919 | location, |
| 2920 | query_string, |
| 2921 | dictionary, |
| 2922 | start_line=1, |
| 2923 | _cache={}, |
| 2924 | ): |
| 2925 | """ |
| 2926 | Return a list of Token objects with pos and line number collected from the |
| 2927 | file at `location` or the `query_string` string. `dictionary` is the index |
| 2928 | mapping a token string to a token id. |
| 2929 | |
| 2930 | NOTE: the _cache={} arg IS A GLOBAL mutable by design. |
| 2931 | """ |
| 2932 | key = location, query_string, start_line |
| 2933 | cached = _cache.get(key) |
| 2934 | if cached: |
| 2935 | return cached |
| 2936 | # we only cache the last call |
| 2937 | _cache.clear() |
| 2938 | _cache[key] = result = list( |
| 2939 | _tokenize_matched_text( |
| 2940 | location=location, |
| 2941 | query_string=query_string, |
| 2942 | dictionary=dictionary, |
| 2943 | start_line=start_line, |
| 2944 | ) |
| 2945 | ) |
| 2946 | return result |
| 2947 | |
| 2948 | |
| 2949 | def _tokenize_matched_text( |