pyscript-programming-language 1.2.1__tar.gz → 1.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pyscript-programming-language might be problematic. Click here for more details.

Files changed (57) hide show
  1. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/MANIFEST.in +1 -0
  2. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/PKG-INFO +4 -4
  3. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/README.md +3 -3
  4. pyscript_programming_language-1.2.3/changelog.md +28 -0
  5. pyscript_programming_language-1.2.3/pyscript/__init__.py +33 -0
  6. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/__init__.pyi +5 -2
  7. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/__main__.py +14 -12
  8. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/buffer.py +1 -7
  9. pyscript_programming_language-1.2.3/pyscript/core/cache.py +8 -0
  10. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/constants.py +5 -1
  11. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/context.py +3 -2
  12. pyscript_programming_language-1.2.3/pyscript/core/exceptions.py +79 -0
  13. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/handlers.py +20 -19
  14. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/highlight.py +12 -10
  15. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/interpreter.py +109 -72
  16. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/lexer.py +182 -188
  17. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/nodes.py +3 -3
  18. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/objects.py +64 -60
  19. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/parser.py +45 -52
  20. pyscript_programming_language-1.2.3/pyscript/core/position.py +85 -0
  21. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/pysbuiltins.py +66 -67
  22. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/results.py +14 -4
  23. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/runner.py +80 -62
  24. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/singletons.py +11 -4
  25. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/symtab.py +3 -15
  26. pyscript_programming_language-1.2.3/pyscript/core/token.py +25 -0
  27. pyscript_programming_language-1.2.3/pyscript/core/utils.py +196 -0
  28. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/validator.py +8 -8
  29. pyscript_programming_language-1.2.3/pyscript/core/version.py +9 -0
  30. pyscript_programming_language-1.2.1/pyscript/lib/hello.pys → pyscript_programming_language-1.2.3/pyscript/lib/__hello__.pys +2 -2
  31. pyscript_programming_language-1.2.3/pyscript/lib/brainfuck.pys +191 -0
  32. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/lib/parser.pys +27 -18
  33. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/lib/sys.pys +2 -2
  34. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript_programming_language.egg-info/PKG-INFO +4 -4
  35. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript_programming_language.egg-info/SOURCES.txt +3 -5
  36. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/setup.py +1 -1
  37. pyscript_programming_language-1.2.1/pyscript/__init__.py +0 -26
  38. pyscript_programming_language-1.2.1/pyscript/core/cache.py +0 -9
  39. pyscript_programming_language-1.2.1/pyscript/core/exceptions.py +0 -34
  40. pyscript_programming_language-1.2.1/pyscript/core/position.py +0 -11
  41. pyscript_programming_language-1.2.1/pyscript/core/token.py +0 -21
  42. pyscript_programming_language-1.2.1/pyscript/core/utils.py +0 -290
  43. pyscript_programming_language-1.2.1/pyscript/core/version.py +0 -9
  44. pyscript_programming_language-1.2.1/pyscript/lib/_tantee/__init__.pys +0 -50
  45. pyscript_programming_language-1.2.1/pyscript/lib/_tantee/animate.pys +0 -9
  46. pyscript_programming_language-1.2.1/pyscript/lib/_tantee/lyrics.pys +0 -12
  47. pyscript_programming_language-1.2.1/pyscript/lib/_tantee/tantee.mp3 +0 -0
  48. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/PyScript.png +0 -0
  49. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/__init__.py +0 -0
  50. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/core/bases.py +0 -0
  51. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/lib/clock.pys +0 -0
  52. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/lib/getch.pys +0 -0
  53. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/lib/this.pys +0 -0
  54. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript/this.py +0 -0
  55. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript_programming_language.egg-info/dependency_links.txt +0 -0
  56. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/pyscript_programming_language.egg-info/top_level.txt +0 -0
  57. {pyscript_programming_language-1.2.1 → pyscript_programming_language-1.2.3}/setup.cfg +0 -0
@@ -1,3 +1,4 @@
1
+ include changelog.md
1
2
  include MANIFEST.in
2
3
  include PyScript.png
3
4
  include setup.py
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyscript-programming-language
3
- Version: 1.2.1
3
+ Version: 1.2.3
4
4
  Summary: PyScript Programming Language
5
5
  Home-page: https://github.com/azzammuhyala/pyscript
6
6
  Author: azzammuhyala
@@ -29,10 +29,10 @@ Dynamic: project-url
29
29
  Dynamic: requires-python
30
30
  Dynamic: summary
31
31
 
32
- # PyScript Language📖
32
+ # PyScript
33
33
 
34
34
  <p align="center">
35
- <img src="PyScript.png" alt="PyScript Logo" width="200">
35
+ <img src="https://github.com/azzammuhyala/pyscript/blob/main/PyScript.png?raw=true" alt="PyScript Logo" width="200">
36
36
  </p>
37
37
 
38
38
  PyScript adalah bahasa pemprograman sederhana yang dibuat di atas bahasa Python. Bahasa ini mengabungkan beberapa sintaks dari Python dan JavaScript, jadi bagi Anda yang sudah familiar dengan sintaks Python atau JavaScript atau keduanya pasti seharusnya cukup mudah mempelajari bahasa ini.
@@ -269,7 +269,7 @@ Anda sudah sampai akhir, harusnya Anda sudah cukup bisa menulis dan memahami syn
269
269
  2. Buat program untuk mencari nilai faktorial.
270
270
  3. Buat program untuk mencari nilai fibonaci.
271
271
  4. Buat program gim sederhana yakni tebak angka.
272
- 5. Buat program gim ular menggunakan _egine_ atau modul Python [PyGame](https://pygame.org).
272
+ 5. Buat program gim ular menggunakan _egine_ [PyGame](https://pygame.org).
273
273
 
274
274
  _Good Luck :)_
275
275
 
@@ -1,7 +1,7 @@
1
- # PyScript Language📖
1
+ # PyScript
2
2
 
3
3
  <p align="center">
4
- <img src="PyScript.png" alt="PyScript Logo" width="200">
4
+ <img src="https://github.com/azzammuhyala/pyscript/blob/main/PyScript.png?raw=true" alt="PyScript Logo" width="200">
5
5
  </p>
6
6
 
7
7
  PyScript adalah bahasa pemprograman sederhana yang dibuat di atas bahasa Python. Bahasa ini mengabungkan beberapa sintaks dari Python dan JavaScript, jadi bagi Anda yang sudah familiar dengan sintaks Python atau JavaScript atau keduanya pasti seharusnya cukup mudah mempelajari bahasa ini.
@@ -238,7 +238,7 @@ Anda sudah sampai akhir, harusnya Anda sudah cukup bisa menulis dan memahami syn
238
238
  2. Buat program untuk mencari nilai faktorial.
239
239
  3. Buat program untuk mencari nilai fibonaci.
240
240
  4. Buat program gim sederhana yakni tebak angka.
241
- 5. Buat program gim ular menggunakan _egine_ atau modul Python [PyGame](https://pygame.org).
241
+ 5. Buat program gim ular menggunakan _egine_ [PyGame](https://pygame.org).
242
242
 
243
243
  _Good Luck :)_
244
244
 
@@ -0,0 +1,28 @@
1
+ # Change Log
2
+
3
+ ## [1.2.3] - 12-10-2025
4
+
5
+ ### Added
6
+ - `qualname` on `pyscript.core.context.PysContext`.
7
+ - Flag `COMMENT` (replace `allowed_comment_token` on `pyscript.core.lexer.PysLexer`).
8
+
9
+ ### Fixed
10
+ - `pyscript.__main__` improvements.
11
+ - `pyscript.core.exceptions` improvements.
12
+ - `pyscript.core.handlers` improvements.
13
+ - `pyscript.core.objects` improvements.
14
+ - `pyscript.core.buffer.PysCode` object are moved to `pyscript.core.objects`
15
+ - `pyscript.core.interpreter.PysInterpreter` improvements.
16
+ - `pyscript.core.lexer.PysLexer` improvements.
17
+ - `pyscript.core.parser.PysParser` improvements.
18
+ - `pyscript.core.position.PysPosition` improvements.
19
+ - `pyscript.core.results.PysExecuteResult` improvements.
20
+ - `pyscript.core.utils.format_highlighted_text_with_arrow` function are moved to `pyscript.core.position.PysPosition`
21
+ A.K.A function method with name `format_arrow`.
22
+ - `pyscript.core.utils.generate_string_traceback` function are moved to `pyscript.core.exceptions.PysException`
23
+ A.K.A function method with name `string_traceback`.
24
+ - Name changes on all objects in `pyscript.core.singletons`.
25
+
26
+ ### Removed
27
+ - Function `pyscript.core.utils.get_line_column_by_index`
28
+ - Function `pyscript.code.utils.sanitize_newline`.
@@ -0,0 +1,33 @@
1
+ """
2
+ PyScript is a programming language written in Python. \
3
+ This language is not isolated and is directly integrated with the Python's library and namespace levels.
4
+ """
5
+
6
+ import sys
7
+
8
+ if sys.version_info < (3, 5):
9
+ raise ImportError("Python version 3.5 and above is required to run PyScript")
10
+
11
+ from . import core
12
+
13
+ from .core.constants import DEFAULT, OPTIMIZE, SILENT, RETRES, COMMENT, REVERSE_POW_XOR
14
+ from .core.highlight import HLFMT_HTML, HLFMT_ANSI, pys_highlight
15
+ from .core.runner import pys_exec, pys_eval
16
+ from .core.version import __version__, __date__
17
+
18
+ __all__ = [
19
+ 'core',
20
+ 'DEFAULT',
21
+ 'OPTIMIZE',
22
+ 'SILENT',
23
+ 'RETRES',
24
+ 'COMMENT',
25
+ 'REVERSE_POW_XOR',
26
+ 'HLFMT_HTML',
27
+ 'HLFMT_ANSI',
28
+ 'pys_highlight',
29
+ 'pys_exec',
30
+ 'pys_eval'
31
+ ]
32
+
33
+ del sys
@@ -4,6 +4,7 @@ if TYPE_CHECKING:
4
4
  from .core.buffer import PysFileBuffer
5
5
  from .core.highlight import _HighlightFormatter
6
6
  from .core.position import PysPosition
7
+ from .core.results import PysExecuteResult
7
8
  from .core.symtab import PysSymbolTable
8
9
 
9
10
  from io import IOBase
@@ -14,6 +15,8 @@ DEFAULT: int
14
15
  OPTIMIZE: int
15
16
  SILENT: int
16
17
  RETRES: int
18
+ COMMENT: int
19
+ REVERSE_POW_XOR: int
17
20
 
18
21
  HLFMT_HTML: _HighlightFormatter
19
22
  HLFMT_ANSI: _HighlightFormatter
@@ -38,13 +41,13 @@ def pys_exec(
38
41
  source: Union[str, bytes, bytearray, IOBase, PysFileBuffer],
39
42
  globals: Optional[Union[Dict[str, Any], PysSymbolTable]] = None,
40
43
  flags: int = DEFAULT
41
- ) -> None: ...
44
+ ) -> Union[None, PysExecuteResult]: ...
42
45
 
43
46
  def pys_eval(
44
47
  source: Union[str, bytes, bytearray, IOBase, PysFileBuffer],
45
48
  globals: Optional[Union[Dict[str, Any], PysSymbolTable]] = None,
46
49
  flags: int = DEFAULT
47
- ) -> Any: ...
50
+ ) -> Union[Any, PysExecuteResult]: ...
48
51
 
49
52
  __version__: str
50
53
  __date__: str
@@ -60,6 +60,7 @@ args = parser.parse_args()
60
60
  if args.highlight and args.file is None:
61
61
  parser.error("file path require")
62
62
 
63
+ code = 0
63
64
  flags = DEFAULT
64
65
 
65
66
  if args.optimize:
@@ -113,9 +114,10 @@ if args.file is not None:
113
114
  code = handle_execute(result)
114
115
 
115
116
  if args.inspect:
116
- pys_shell(flags=flags, future=result.future, symbol_table=result.context.symbol_table)
117
- else:
118
- exit(code)
117
+ code = pys_shell(
118
+ symbol_table=result.context.symbol_table,
119
+ flags=result.flags
120
+ )
119
121
 
120
122
  elif args.command is not None:
121
123
  file = PysFileBuffer(args.command)
@@ -123,16 +125,16 @@ elif args.command is not None:
123
125
  symtab = build_symbol_table(file)
124
126
  symtab.set('__name__', '__main__')
125
127
 
126
- exit(
127
- handle_execute(
128
- pys_runner(
129
- file=file,
130
- mode='exec',
131
- symbol_table=symtab,
132
- flags=flags
133
- )
128
+ code = handle_execute(
129
+ pys_runner(
130
+ file=file,
131
+ mode='exec',
132
+ symbol_table=symtab,
133
+ flags=flags
134
134
  )
135
135
  )
136
136
 
137
137
  else:
138
- pys_shell(flags=flags)
138
+ code = pys_shell(flags=flags)
139
+
140
+ sys.exit(code)
@@ -22,10 +22,4 @@ class PysFileBuffer(PysBuffer):
22
22
  self.name = '<string>' if name is None else to_str(name)
23
23
 
24
24
  def __repr__(self):
25
- return '<FileBuffer from {!r}>'.format(self.name)
26
-
27
- class PysCode(PysBuffer):
28
-
29
- def __init__(self, **kwargs):
30
- for key, value in kwargs.items():
31
- setattr(self, key, value)
25
+ return '<FileBuffer from {!r}>'.format(self.name)
@@ -0,0 +1,8 @@
1
+ from .singletons import PysHook
2
+
3
+ loading_modules = set()
4
+ library = set()
5
+ modules = {}
6
+ hook = PysHook()
7
+
8
+ del PysHook
@@ -128,9 +128,13 @@ HIGHLIGHT = {
128
128
  'comment': '#549952'
129
129
  }
130
130
 
131
+ # python extensions file
132
+ PYTHON_EXTENSIONS = {'.ipy', '.py', '.pyc', '.pyi', '.pyo', '.pyp', '.pyw', '.pyz', '.pyproj', '.rpy', '.xpy'}
133
+
131
134
  # flags
132
135
  DEFAULT = 0
133
136
  OPTIMIZE = 1 << 1
134
137
  SILENT = 1 << 2
135
138
  RETRES = 1 << 3
136
- REVERSE_POW_XOR = 1 << 25
139
+ COMMENT = 1 << 4
140
+ REVERSE_POW_XOR = 1 << 20
@@ -2,9 +2,10 @@ from .bases import Pys
2
2
 
3
3
  class PysContext(Pys):
4
4
 
5
- def __init__(self, name, file, symbol_table=None, parent=None, parent_entry_position=None):
6
- self.name = name
5
+ def __init__(self, file, name=None, qualname=None, symbol_table=None, parent=None, parent_entry_position=None):
7
6
  self.file = file
7
+ self.name = name
8
+ self.qualname = qualname
8
9
  self.symbol_table = symbol_table
9
10
  self.parent = parent
10
11
  self.parent_entry_position = parent_entry_position
@@ -0,0 +1,79 @@
1
+ from .bases import Pys
2
+ from .utils import space_indent
3
+
4
+ class PysException(Pys):
5
+
6
+ def __init__(self, exception, context, position):
7
+ self.exception = exception
8
+ self.context = context
9
+ self.position = position
10
+
11
+ def __str__(self):
12
+ return str(self.exception)
13
+
14
+ def __repr__(self):
15
+ return '<Exception of {!r}>'.format(self.exception)
16
+
17
+ def string_traceback(self):
18
+ frames = []
19
+
20
+ context = self.context
21
+ position = self.position
22
+
23
+ while context:
24
+ frames.append(
25
+ ' File "{}", line {}{}\n{}'.format(
26
+ position.file.name,
27
+ position.start_line,
28
+ '' if context.name is None else ', in {}'.format(context.name),
29
+ space_indent(position.format_arrow(), 4)
30
+ )
31
+ )
32
+
33
+ position = context.parent_entry_position
34
+ context = context.parent
35
+
36
+ found_duplicated_frame = 0
37
+ strings_traceback = ''
38
+ last_frame = ''
39
+
40
+ for frame in reversed(frames):
41
+ if frame == last_frame:
42
+ found_duplicated_frame += 1
43
+
44
+ else:
45
+ if found_duplicated_frame > 0:
46
+ strings_traceback += ' [Previous line repeated {} more times]\n'.format(found_duplicated_frame)
47
+ found_duplicated_frame = 0
48
+
49
+ strings_traceback += frame + '\n'
50
+ last_frame = frame
51
+
52
+ if found_duplicated_frame > 0:
53
+ strings_traceback += ' [Previous line repeated {} more times]\n'.format(found_duplicated_frame)
54
+
55
+ result = 'Traceback (most recent call last):\n' + strings_traceback
56
+
57
+ if isinstance(self.exception, type):
58
+ return result + self.exception.__name__
59
+ else:
60
+ message = str(self.exception)
61
+ return '{}{}{}'.format(result, type(self.exception).__name__, ': ' + message if message else '')
62
+
63
+ class PysShouldReturn(Pys, BaseException):
64
+
65
+ def __init__(self, result):
66
+ super().__init__()
67
+ self.result = result
68
+
69
+ def __str__(self):
70
+ if self.result.error is None:
71
+ return '<signal>'
72
+
73
+ exception = self.result.error.exception
74
+
75
+ if isinstance(exception, type):
76
+ return exception.__name__
77
+ else:
78
+ message = str(exception)
79
+ return type(exception).__name__ + (': ' + message if message else '')
@@ -1,7 +1,9 @@
1
1
  from .cache import hook
2
2
  from .exceptions import PysException, PysShouldReturn
3
- from .objects import PysChainFunction, PysFunction
4
- from .utils import is_object_of
3
+ from .objects import PysPythonFunction, PysFunction
4
+ from .position import PysPosition
5
+ from .results import PysRunTimeResult
6
+ from .utils import is_object_of, print_traceback
5
7
 
6
8
  from contextlib import contextmanager
7
9
  from types import MethodType
@@ -21,28 +23,22 @@ def handle_call(object, context, position, flags):
21
23
  object.__code__.position = position
22
24
  object.__code__.flags = flags
23
25
 
24
- elif isinstance(object, PysChainFunction):
26
+ elif isinstance(object, PysPythonFunction):
25
27
  object.__code__.context = context
26
28
  object.__code__.position = position
27
29
  object.__code__.flags = flags
28
30
 
29
- elif isinstance(object, MethodType) and isinstance(object.__func__, PysFunction):
30
- object.__func__.__code__.call_context = context
31
- object.__func__.__code__.position = position
32
- object.__func__.__code__.flags = flags
33
-
34
31
  elif isinstance(object, type):
32
+ for call in ('__new__', '__init__'):
33
+ handle_call(getattr(object, call, None), context, position, flags)
35
34
 
36
- for call in ('__init__', '__new__'):
37
- fn = getattr(object, call, None)
38
-
39
- if isinstance(fn, PysFunction):
40
- fn.__code__.call_context = context
41
- fn.__code__.position = position
42
- fn.__code__.flags = flags
35
+ elif isinstance(object, MethodType):
36
+ handle_call(object.__func__, context, position, flags)
43
37
 
44
38
  def handle_execute(result):
45
- try:
39
+ result_runtime = PysRunTimeResult()
40
+
41
+ with handle_exception(result_runtime, result.context, PysPosition(result.context.file, 0, 0)):
46
42
 
47
43
  if result.error:
48
44
  if is_object_of(result.error.exception, SystemExit):
@@ -51,10 +47,15 @@ def handle_execute(result):
51
47
  hook.exception(result.error)
52
48
  return 1
53
49
 
54
- elif len(result.result) == 1 and hook.display is not None:
55
- hook.display(result.result[0])
50
+ elif hook.display is not None:
51
+ if result.mode == 'exec' and len(result.value) == 1:
52
+ hook.display(result.value[0])
53
+ elif result.mode == 'eval':
54
+ hook.display(result.value)
56
55
 
57
- except:
56
+ if result_runtime.should_return():
57
+ if result_runtime.error:
58
+ print_traceback(result_runtime.error)
58
59
  return 1
59
60
 
60
61
  return 0
@@ -1,10 +1,10 @@
1
1
  from .bases import Pys
2
2
  from .buffer import PysFileBuffer
3
- from .constants import TOKENS, KEYWORDS, HIGHLIGHT, DEFAULT, SILENT
3
+ from .constants import TOKENS, KEYWORDS, HIGHLIGHT, SILENT, COMMENT
4
4
  from .lexer import PysLexer
5
5
  from .position import PysPosition
6
6
  from .pysbuiltins import pys_builtins
7
- from .utils import parenthesises_map, sanitize_newline
7
+ from .utils import parenthesises_map
8
8
 
9
9
  from html import escape as html_escape
10
10
 
@@ -19,10 +19,7 @@ class _HighlightFormatter(Pys):
19
19
  self._type = 'start'
20
20
  self._open = False
21
21
 
22
- def __call__(self, *args, **kwargs):
23
- return self.formater(*args, **kwargs)
24
-
25
- def formater(self, type, position, content):
22
+ def __call__(self, type, position, content):
26
23
  contented = self.content_block(position, content)
27
24
  result = ''
28
25
 
@@ -38,6 +35,8 @@ class _HighlightFormatter(Pys):
38
35
  result += self.close_block(position, self._type)
39
36
  self._open = False
40
37
 
38
+ type = 'start'
39
+
41
40
  elif type == self._type and self._open:
42
41
  result += contented
43
42
 
@@ -63,20 +62,20 @@ def _ansi_open_block(position, type):
63
62
  )
64
63
 
65
64
  HLFMT_HTML = _HighlightFormatter(
66
- lambda position, content: sanitize_newline('<br>', html_escape(content)),
65
+ lambda position, content: '<br>'.join(html_escape(content).splitlines()),
67
66
  lambda position, type: '<span style="color:{}">'.format(HIGHLIGHT.get(type, 'default')),
68
67
  lambda position, type: '</span>',
69
68
  lambda position: '<br>'
70
69
  )
71
70
 
72
71
  HLFMT_ANSI = _HighlightFormatter(
73
- lambda position, content: sanitize_newline('\n', content),
72
+ lambda position, content: content,
74
73
  _ansi_open_block,
75
74
  lambda position, type: '\x1b[0m',
76
75
  lambda position: '\n'
77
76
  )
78
77
 
79
- def pys_highlight(source, format=None, max_parenthesis_level=3, flags=DEFAULT):
78
+ def pys_highlight(source, format=None, max_parenthesis_level=3, flags=COMMENT):
80
79
  """
81
80
  Highlight a PyScript code from source given.
82
81
 
@@ -103,7 +102,10 @@ def pys_highlight(source, format=None, max_parenthesis_level=3, flags=DEFAULT):
103
102
  elif max_parenthesis_level < 0:
104
103
  raise ValueError("pys_highlight(): max_parenthesis_level must be grather than 0")
105
104
 
106
- lexer = PysLexer(file, allowed_comment_token=True)
105
+ if not isinstance(flags, int):
106
+ raise TypeError("pys_highlight(): flags must be integer")
107
+
108
+ lexer = PysLexer(file=file, flags=flags)
107
109
  tokens, error = lexer.make_tokens()
108
110
 
109
111
  if error and not (flags & SILENT):