Skip to content

Commit d4aa952

Browse files
authored
Try to fix #255, #242 (#248)
* WIP * Make debugging easy for fix encoding bugs * Fix encoding problem that is #225 #242 * More simple implementation for bytes compatible * Make more simple * Remove debugging code * It is a classmethod, not instance method * Add a test case for suddn EOF * Rename to the correct name * Care multiple scriptencoding * Fix a problem about debug_hint overwriting * Care single line scriptencoding * decoding error is not a RuntimeError but Exception * More debug_hint * Fix a problem about missing last char * Change Chardet priority * Revert "WIP" This reverts commit 1fb7dfc. * Split files * Try to resolve module name conflict * Cosmetic changes * Compose strategies to decoding_strategy
1 parent 79b0f1a commit d4aa952

18 files changed

+302
-29
lines changed

dev_tool/show_ast.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
import sys
44
from argparse import ArgumentParser
55
from pathlib import Path
66
from pprint import pprint
77

88
vint_root = Path(__file__).resolve().parent.parent
9-
sys.path.append(str(vint_root))
9+
sys.path.insert(0, str(vint_root))
1010

1111
from vint.ast.node_type import NodeType
1212
from vint.ast.traversing import traverse

dev_tool/show_chardet_result.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
3+
import chardet
4+
import sys
5+
from pprint import pprint
6+
from pathlib import Path
7+
from argparse import ArgumentParser
8+
9+
10+
def main(file_path):
11+
# type: (Path) -> None
12+
with file_path.open(mode='rb') as f:
13+
bytes_seq = f.read()
14+
15+
coding_hint = chardet.detect(bytes_seq)
16+
pprint(coding_hint)
17+
18+
19+
if __name__ == '__main__':
20+
arg_parser = ArgumentParser(prog='show_ast', description='Show AST')
21+
arg_parser.add_argument('file', nargs=1, help='File to parse')
22+
namespace = vars(arg_parser.parse_args(sys.argv[1:]))
23+
24+
main(Path(namespace['file'][0]))

dev_tool/show_encoding.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
from argparse import ArgumentParser
5+
from pathlib import Path
6+
from pprint import pprint
7+
8+
vint_root = Path(__file__).resolve().parent.parent
9+
sys.path.insert(0, str(vint_root))
10+
11+
from vint.encodings.decoder import Decoder
12+
from vint.encodings.decoding_strategy import default_decoding_strategy
13+
14+
15+
if __name__ == '__main__':
16+
arg_parser = ArgumentParser(prog='show_ast', description='Show AST')
17+
arg_parser.add_argument('file', nargs=1, help='File to detect encoding')
18+
namespace = vars(arg_parser.parse_args(sys.argv[1:]))
19+
20+
file_path = Path(namespace['file'][0])
21+
decoder = Decoder(default_decoding_strategy)
22+
decoder.read(file_path)
23+
pprint(decoder.debug_hint)

test/fixture/encodings/__init__.py

Whitespace-only changes.

test/fixture/encodings/ascii.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo "Only ASCII"

test/fixture/encodings/cp932.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scriptencoding cp932 "���{��

test/fixture/encodings/empty.vim

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
scriptencoding utf-8
2+
" :purple_heart: 💜
3+
" set list listchars=tab:»·,trail:·,eol:¬,nbsp:_,extends:❯,precedes:❮
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
echo "before 1"
2+
scriptencoding utf8
3+
echo "before 2"
4+
scriptencoding utf8
5+
echo "after 2"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
echo "no scriptencofing 1"
2+
echo "no scriptencofing 2"
3+
echo "no scriptencofing 3"

0 commit comments

Comments
 (0)