textmate-grammar-python 0.1.1__tar.gz → 0.1.2__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.
Files changed (19) hide show
  1. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/PKG-INFO +5 -13
  2. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/README.md +4 -12
  3. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/pyproject.toml +2 -1
  4. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/textmate_grammar/grammars/matlab/grammar.yaml +31 -30
  5. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/textmate_grammar/handler.py +3 -2
  6. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/textmate_grammar/parser.py +16 -4
  7. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/LICENSE +0 -0
  8. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/textmate_grammar/__init__.py +0 -0
  9. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/textmate_grammar/captures.py +0 -0
  10. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/textmate_grammar/elements.py +0 -0
  11. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/textmate_grammar/exceptions.py +0 -0
  12. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/textmate_grammar/grammars/__init__.py +0 -0
  13. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/textmate_grammar/grammars/markdown/LICENSE.txt +0 -0
  14. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/textmate_grammar/grammars/markdown/__init__.py +0 -0
  15. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/textmate_grammar/grammars/markdown/grammar.yaml +0 -0
  16. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/textmate_grammar/grammars/matlab/__init__.py +0 -0
  17. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/textmate_grammar/grammars/matlab/license.txt +0 -0
  18. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/textmate_grammar/language.py +0 -0
  19. {textmate_grammar_python-0.1.1 → textmate_grammar_python-0.1.2}/textmate_grammar/logging.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: textmate-grammar-python
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: An interpreter for grammar files as defined by TextMate and used in VSCode, implemented in Python. TextMate grammars use the oniguruma dialect (https://github.com/kkos/oniguruma). Supports loading grammar files from JSON, PLIST, or YAML format.
5
5
  Home-page: https://github.com/watermarkhu/textmate-grammar-python
6
6
  License: MIT
@@ -92,22 +92,14 @@ Install the repository after cloning with [poetry](https://python-poetry.org/)
92
92
  > poetry install
93
93
  ```
94
94
 
95
- Setup nodejs dependencies in the regression testing folder.
95
+ Run unit tests
96
96
  ```bash
97
- > cd test/regression
98
- > bash install.js
97
+ > tox run
99
98
  ```
100
99
 
101
- Run all tests in main test directory
100
+ Run regression testing against vscode-textmate (will install npm and required packages)
102
101
  ```bash
103
- > cd ..
104
- > pytest
105
-
106
- ====================== test session starts =====================
107
- platform linux -- Python 3.11.4, pytest-7.4.0, pluggy-1.2.0
108
- rootdir: /home/watermarkhu/repositories/sphinx-matlab/test
109
- plugins: icdiff-0.8
110
- ...
102
+ > tox run -e regression
111
103
  ```
112
104
 
113
105
 
@@ -73,21 +73,13 @@ Install the repository after cloning with [poetry](https://python-poetry.org/)
73
73
  > poetry install
74
74
  ```
75
75
 
76
- Setup nodejs dependencies in the regression testing folder.
76
+ Run unit tests
77
77
  ```bash
78
- > cd test/regression
79
- > bash install.js
78
+ > tox run
80
79
  ```
81
80
 
82
- Run all tests in main test directory
81
+ Run regression testing against vscode-textmate (will install npm and required packages)
83
82
  ```bash
84
- > cd ..
85
- > pytest
86
-
87
- ====================== test session starts =====================
88
- platform linux -- Python 3.11.4, pytest-7.4.0, pluggy-1.2.0
89
- rootdir: /home/watermarkhu/repositories/sphinx-matlab/test
90
- plugins: icdiff-0.8
91
- ...
83
+ > tox run -e regression
92
84
  ```
93
85
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "textmate-grammar-python"
3
- version = "0.1.1"
3
+ version = "0.1.2"
4
4
  description = "An interpreter for grammar files as defined by TextMate and used in VSCode, implemented in Python. TextMate grammars use the oniguruma dialect (https://github.com/kkos/oniguruma). Supports loading grammar files from JSON, PLIST, or YAML format."
5
5
  authors = ["Mark Shui Hu <watermarkhu@gmail.com>"]
6
6
  license = "MIT"
@@ -17,6 +17,7 @@ PyYAML = "^6.0.1"
17
17
  [tool.poetry.group.test.dependencies]
18
18
  pytest = "^7.3.1"
19
19
  pytest-icdiff = "^0.8"
20
+ tox = "^4.11.4"
20
21
 
21
22
  [build-system]
22
23
  requires = ["poetry-core"]
@@ -18,7 +18,7 @@ repository:
18
18
  beginCaptures:
19
19
  '1':
20
20
  name: punctuation.definition.function.anonymous.matlab
21
- end: (?=;|(?<!(?:\.\.\..*))\n|%)
21
+ end: (?=;|(?<!(?:\.{3}.*))\n|%)
22
22
  name: meta.function.anonymous.matlab
23
23
  patterns:
24
24
  - begin: \G(\()
@@ -40,7 +40,7 @@ repository:
40
40
  beginCaptures:
41
41
  '1':
42
42
  name: punctuation.section.group.begin.matlab
43
- end: (\))?[^\S\n]*(?=;|(?<!(?:\.\.\..*))\n|%)
43
+ end: (\))?[^\S\n]*(?=;|(?<!(?:\.{3}.*))\n|%)
44
44
  endCaptures:
45
45
  '1':
46
46
  name: punctuation.section.group.end.matlab
@@ -62,7 +62,7 @@ repository:
62
62
  name: meta.for.matlab
63
63
  patterns:
64
64
  - begin: \G(?!$)
65
- end: (?<!\.\.\.)(?:(?=([,;])(?![^(]*\)))|$)
65
+ end: (?<!\.{3})(?:(?=([,;])(?![^(]*\)))|$)
66
66
  name: meta.for.declaration.matlab
67
67
  patterns:
68
68
  - include: $self
@@ -81,7 +81,7 @@ repository:
81
81
  name: meta.if.matlab
82
82
  patterns:
83
83
  - begin: \G(?!$)
84
- end: (?<!\.\.\.)(?:(?=([,;])(?![^(]*\)))|$)
84
+ end: (?<!\.{3})(?:(?=([,;])(?![^(]*\)))|$)
85
85
  name: meta.if.declaration.matlab
86
86
  patterns:
87
87
  - include: $self
@@ -92,7 +92,7 @@ repository:
92
92
  name: meta.elseif.matlab
93
93
  patterns:
94
94
  - begin: \G(?!$)
95
- end: (?<!\.\.\.)(?:(?=([,;])(?![^(]*\)))|$)
95
+ end: (?<!\.{3})(?:(?=([,;])(?![^(]*\)))|$)
96
96
  name: meta.elseif.declaration.matlab
97
97
  patterns:
98
98
  - include: $self
@@ -114,7 +114,7 @@ repository:
114
114
  name: meta.for.parallel.matlab
115
115
  patterns:
116
116
  - begin: \G(?!$)
117
- end: (?<!\.\.\.)(?:(?=([,;])(?![^(]*\)))|$)
117
+ end: (?<!\.{3})(?:(?=([,;])(?![^(]*\)))|$)
118
118
  name: meta.for.parallel.declaration.matlab
119
119
  patterns:
120
120
  - include: $self
@@ -130,7 +130,7 @@ repository:
130
130
  name: meta.repeat.parallel.matlab
131
131
  patterns:
132
132
  - begin: \G(?!$)
133
- end: (?<!\.\.\.)(?:(?=([,;])(?![^(]*\)))|$)
133
+ end: (?<!\.{3})(?:(?=([,;])(?![^(]*\)))|$)
134
134
  name: meta.repeat.parallel.declaration.matlab
135
135
  patterns:
136
136
  - include: $self
@@ -152,11 +152,11 @@ repository:
152
152
  name: keyword.control.switch.case.matlab
153
153
  '3':
154
154
  begin: \G(?!$)
155
- end: (?<!\.\.\.)(?:(?=([,;])(?![^(]*\)))|$)
155
+ end: (?<!\.{3})(?:(?=([,;])(?![^(]*\)))|$)
156
156
  name: meta.case.declaration.matlab
157
157
  patterns:
158
158
  - include: $self
159
- match: (\s*)(?<=^|[\s,;])(case)\b(.*?)(?<!\.\.\.)(?:(?=([,;])(?![^(]*\)))|$)
159
+ match: (\s*)(?<=^|[\s,;])(case)\b(.*?)(?<!\.{3})(?:(?=([,;])(?![^(]*\)))|$)
160
160
  name: meta.case.matlab
161
161
  - captures:
162
162
  '2':
@@ -196,7 +196,7 @@ repository:
196
196
  name: meta.while.matlab
197
197
  patterns:
198
198
  - begin: \G
199
- end: (?<!\.\.\.)(?:(?=([,;])(?![^(]*\)))|$)
199
+ end: (?<!\.{3})(?:(?=([,;])(?![^(]*\)))|$)
200
200
  endCaptures:
201
201
  '1':
202
202
  include: $self
@@ -235,7 +235,7 @@ repository:
235
235
  name: meta.class.matlab
236
236
  patterns:
237
237
  - begin: \G
238
- end: (?<!\.\.\.)(?=\n)
238
+ end: (?<!\.{3})(?=\n)
239
239
  name: meta.class.declaration.matlab
240
240
  patterns:
241
241
  - begin: \G(\([^)]*\))?\s*
@@ -262,14 +262,14 @@ repository:
262
262
  - include: '#string'
263
263
  - include: '#comments'
264
264
  - include: '#line_continuation'
265
- end: (?<!\.\.\.)(?=\s*%|\n)
265
+ end: (?<!\.{3})(?=\s*%|\n)
266
266
  patterns:
267
267
  - begin: \G\s*([a-zA-Z][a-zA-Z0-9_]*)
268
268
  beginCaptures:
269
269
  '1':
270
270
  comment: Class name
271
271
  name: entity.name.type.class.matlab
272
- end: (?<!\.\.\.)(?=\n)
272
+ end: (?<!\.{3})(?=\n)
273
273
  patterns:
274
274
  - comment: Optional inheritance operator
275
275
  match: <
@@ -414,7 +414,7 @@ repository:
414
414
  - include: '#string_quoted_single'
415
415
  comment: "\t\t\t\t\t 1 \t\t\t\t 2\t\t3 \t\t\t\t 4\t\t\t\t\t\t\t\t\t\t\t\t\
416
416
  \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t "
417
- match: (?<=^|[^.]\n|;|,|=)([^\S\n]*)(?# A> )(\b\w+\b)([^\S\n]+)(?# B> )((?!(\+|-|\*|\.\*|\/|\.\/|\\|\.\\|\^|\.\^|==|~=|&|&&|\||\|\||=|:|>|>=|<|<=|\.\.\.)[^\S\n]?)[^\s({=;%][^\n;%]*)
417
+ match: (?<=^|[^.]\n|;|,|=)([^\S\n]*)(?# A> )(\b\w+\b)([^\S\n]+)(?# B> )((?!(\+|-|\*|\.\*|\/|\.\/|\\|\.\\|\^|\.\^|==|~=|&|&&|\||\|\||=|:|>|>=|<|<=|\.{3})[^\S\n]?)[^\s({=;%][^\n;%]*)
418
418
  name: meta.function-call.command.matlab
419
419
  comment_block:
420
420
  begin: (^[\s]*)(%\{)[^\S\n]*+\n
@@ -525,10 +525,10 @@ repository:
525
525
  name: meta.function.matlab
526
526
  patterns:
527
527
  - begin: \G
528
- end: (?<=[\)\n])
528
+ end: (?<=\))|(?>(?<!\.{3}.*)\n)
529
529
  name: meta.function.declaration.matlab
530
530
  patterns:
531
- - begin: \G(?=.*?=)
531
+ - begin: \G(?=[^\(]*?(?:=|\[|\.{3}))
532
532
  comment: Function output
533
533
  contentName: meta.assignment.variable.output.matlab
534
534
  end: \s*(=)\s*
@@ -541,21 +541,21 @@ repository:
541
541
  - captures:
542
542
  '1':
543
543
  name: punctuation.section.assignment.group.end.matlab
544
- match: (\])\s*\z
544
+ match: (\])\s*
545
545
  - match: '[a-zA-Z][a-zA-Z0-9_]*'
546
546
  name: variable.parameter.output.matlab
547
547
  - match: ','
548
548
  name: punctuation.separator.parameter.comma.matlab
549
- - include: '#comments'
550
549
  - include: '#line_continuation'
550
+ - include: '#comments'
551
551
  - comment: Function name
552
- match: '[a-zA-Z][a-zA-Z0-9_.]*(?=[^a-zA-Z0-9_.])'
552
+ match: '[a-zA-Z][a-zA-Z0-9_]*(?>\.[a-zA-Z0-9_]+)*'
553
553
  name: entity.name.function.matlab
554
554
  patterns:
555
555
  - match: \.
556
556
  name: punctuation.accessor.dot.matlab
557
557
  - include: '#line_continuation'
558
- - begin: (?<=[a-zA-Z0-9_])\s*\(
558
+ - begin: \s*\(
559
559
  beginCaptures:
560
560
  '0':
561
561
  name: punctuation.definition.parameters.begin.matlab
@@ -574,6 +574,7 @@ repository:
574
574
  name: punctuation.separator.parameter.comma.matlab
575
575
  - include: '#comments'
576
576
  - include: '#line_continuation'
577
+ - include: '#line_continuation'
577
578
  - include: '#comments'
578
579
  - begin: "(?x)\n\t\t\t\t\t\t\t\t\t(^\\s*)\t\t\t\t\t\t\t\t# Leading whitespace\n\
579
580
  \t\t\t\t\t\t\t\t\t(arguments)\\b([^%]*)\n\t\t\t\t\t\t\t\t\t\\s*\n\t\t\t\t\
@@ -617,7 +618,7 @@ repository:
617
618
  comment: "\n\t\t\t\tFunction call; matrix or array index (subscript)\n\t\t\t\t\
618
619
  We don't include $self here to avoid matching command syntax inside (), [],\
619
620
  \ {}\n\t\t\t"
620
- end: (\)|(?<!\.\.\..*)\n)
621
+ end: (\)|(?<!\.{3}.*)\n)
621
622
  endCaptures:
622
623
  '0':
623
624
  name: punctuation.section.parens.end.matlab
@@ -658,7 +659,7 @@ repository:
658
659
  name: punctuation.section.parens.begin.matlab
659
660
  comment: Index array with expression evaluated to variable name or number
660
661
  contentName: meta.parens.matlab
661
- end: (\)|(?<!\.\.\..*)\n)
662
+ end: (\)|(?<!\.{3}.*)\n)
662
663
  endCaptures:
663
664
  '0':
664
665
  name: punctuation.section.parens.end.matlab
@@ -673,7 +674,7 @@ repository:
673
674
  - include: '#variables'
674
675
  comment: We don't include $self here to avoid matching command syntax inside (),
675
676
  [], {}
676
- end: (\}|(?<!\.\.\..*)\n)
677
+ end: (\}|(?<!\.{3}.*)\n)
677
678
  patterns:
678
679
  - include: '#end_in_parentheses'
679
680
  - include: '#rules_before_command_dual'
@@ -685,7 +686,7 @@ repository:
685
686
  '2':
686
687
  name: comment.continuation.line.matlab
687
688
  comment: Line continuations
688
- match: (\.\.\.)(.*)$
689
+ match: (\.{3})(.*)$
689
690
  name: meta.continuation.line.matlab
690
691
  multiple_assignment:
691
692
  begin: \[(?=[^\]]+\]\s*=[a-zA-Z0-9_\s(])
@@ -740,19 +741,19 @@ repository:
740
741
  match: (?<!\w)\?(?=\w)
741
742
  name: keyword.operator.other.question.matlab
742
743
  - comment: Arithmetic operator symbols
743
- match: (?<=[a-zA-Z0-9\s])(\+|-|\*|\.\*|/|\./|\\|\.\\|\^|\.\^)(?=[a-zA-Z0-9\s]|(?:\.\.\.))
744
+ match: (?<=[a-zA-Z0-9\s])(\+|-|\*|\.\*|/|\./|\\|\.\\|\^|\.\^)(?=[a-zA-Z0-9\s]|(?:\.{3}))
744
745
  name: keyword.operator.arithmetic.matlab
745
746
  - comment: Operator symbols
746
- match: (?<=[a-zA-Z0-9\s])(==|~=|&|&&|\||\|\|)(?=[a-zA-Z0-9\s]|(?:\.\.\.))
747
+ match: (?<=[a-zA-Z0-9\s])(==|~=|&|&&|\||\|\|)(?=[a-zA-Z0-9\s]|(?:\.{3}))
747
748
  name: keyword.operator.logical.matlab
748
749
  - comment: Assignment operator
749
750
  match: (?<=[a-zA-Z0-9\s])(=)(?!=)
750
751
  name: keyword.operator.assignment.matlab
751
752
  - comment: Colon operator for vector creation/indexing
752
- match: (?<=[a-zA-Z0-9_\s(){,]|^):(?=[a-zA-Z0-9_\s()},]|$||(?:\.\.\.))
753
+ match: (?<=[a-zA-Z0-9_\s(){,]|^):(?=[a-zA-Z0-9_\s()},]|$||(?:\.{3}))
753
754
  name: keyword.operator.vector.colon.matlab
754
755
  - comment: Comparative operators
755
- match: (?<=[a-zA-Z0-9\s])(>|>=|<|<=)(?=[a-zA-Z0-9\s]|(?:\.\.\.))
756
+ match: (?<=[a-zA-Z0-9\s])(>|>=|<|<=)(?=[a-zA-Z0-9\s]|(?:\.{3}))
756
757
  name: keyword.operator.relational.matlab
757
758
  parentheses:
758
759
  begin: \(
@@ -762,7 +763,7 @@ repository:
762
763
  comment: "\n\t\t\t\tOperator precedence in expressions\n\t\t\t\tWe don't include\
763
764
  \ $self here to avoid matching command syntax inside (), [], {}\n\t\t\t"
764
765
  contentName: meta.parens.matlab
765
- end: (\)|(?<!\.\.\..*)\n)
766
+ end: (\)|(?<!\.{3}.*)\n)
766
767
  endCaptures:
767
768
  '0':
768
769
  name: punctuation.section.parens.end.matlab
@@ -935,7 +936,7 @@ repository:
935
936
  comment: "\n\t\t\t\tSuperclass method call; matrix or array index (subscript)\n\
936
937
  \t\t\t\tWe don't include $self here to avoid matching command syntax inside\
937
938
  \ (), [], {}\n\t\t\t"
938
- end: (\)|(?<!\.\.\..*)\n)
939
+ end: (\)|(?<!\.{3}.*)\n)
939
940
  endCaptures:
940
941
  '0':
941
942
  name: punctuation.section.parens.end.matlab
@@ -1,4 +1,4 @@
1
- from onigurumacffi import _Pattern as Pattern, _Match as Match
1
+ from onigurumacffi import _Pattern as Pattern, _Match as Match, compile
2
2
 
3
3
  from .logging import LOGGER
4
4
  from .exceptions import FileNotFound, ImpossibleSpan
@@ -16,6 +16,7 @@ class ContentHandler(object):
16
16
  are index by a tuple (line_number, line_position). Additionally, the handler contains the
17
17
  search method to match a search span against a input oniguruma regex pattern.
18
18
  """
19
+ notLookForwardEOL = compile("(?<!\(\?=[^\(]*)\$")
19
20
 
20
21
  def __init__(self, source: str) -> None:
21
22
  self.source = source
@@ -201,7 +202,7 @@ class ContentHandler(object):
201
202
  LOGGER.warning(f"skipping < {leading_string} >", position=start_pos, depth=kwargs.get("depth", 0))
202
203
 
203
204
  # Include \n in match span if pattern matches on end of line $
204
- if "$" in pattern._pattern and matching.end() + 1 == self.line_lengths[starting[0]]:
205
+ if self.notLookForwardEOL.search(pattern._pattern) and matching.end() + 1 == self.line_lengths[starting[0]]:
205
206
  newline_matching = pattern.search(line[:-1])
206
207
  if newline_matching and newline_matching.span() == matching.span():
207
208
  close_pos = (starting[0], matching.end() + 1)
@@ -349,8 +349,21 @@ class PatternsParser(ParserHasPatterns):
349
349
  LOGGER.info(
350
350
  f"{self.__class__.__name__} chosen pattern of {parser}", self, current, kwargs.get("depth", 0)
351
351
  )
352
- else:
352
+ elif self != self.language:
353
353
  break
354
+ else:
355
+ remainder = handler.read_line(current)
356
+ if not remainder.isspace():
357
+ LOGGER.warning(
358
+ f"{self.__class__.__name__} remainder of line not parsed: {remainder}", self, current, kwargs.get("depth", 0)
359
+ )
360
+ if current[0] + 1 <= len(handler.lines):
361
+ current = (current[0] + 1, 0)
362
+ else:
363
+ LOGGER.debug(
364
+ f"{self.__class__.__name__} EOF encountered", self, current, kwargs.get("depth", 0)
365
+ )
366
+ break
354
367
 
355
368
  if current == starting:
356
369
  LOGGER.warning(
@@ -370,13 +383,12 @@ class PatternsParser(ParserHasPatterns):
370
383
  break
371
384
 
372
385
  if self.token:
373
- closing = boundary if starting == current else current
374
386
  elements = [
375
387
  ContentElement(
376
388
  token=self.token,
377
389
  grammar=self.grammar,
378
- content=handler.read_pos(starting, closing),
379
- characters=handler.chars(starting, closing),
390
+ content=handler.read_pos(starting, boundary),
391
+ characters=handler.chars(starting, boundary),
380
392
  children=elements,
381
393
  )
382
394
  ]