Skip to content

Commit

Permalink
Update tokens to use mistletoe.Position rather than old style tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Mar 15, 2020
1 parent e37dd00 commit 8b0d16e
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 29 deletions.
2 changes: 1 addition & 1 deletion myst_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.6.0"
__version__ = "0.7.0"


def text_to_tokens(text: str):
Expand Down
7 changes: 4 additions & 3 deletions myst_parser/block_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import attr

from mistletoe import block_tokens
from mistletoe.base_elements import Position
from mistletoe.block_tokens import Heading, ThematicBreak, CodeFence
from mistletoe.attr_doc import autodoc

Expand Down Expand Up @@ -62,7 +63,7 @@ def read(cls, lines):
return cls(
raw=line.splitlines()[0],
content=cls.content,
position=(lines.lineno, lines.lineno),
position=Position.from_source_lines(lines),
)


Expand Down Expand Up @@ -106,7 +107,7 @@ def read(cls, lines):
return cls(
raw=line.splitlines()[0],
content=cls.content,
position=(lines.lineno, lines.lineno),
position=Position.from_source_lines(lines),
)


Expand Down Expand Up @@ -198,7 +199,7 @@ def read(cls, lines):
children=children,
loose=loose,
start_at=start,
position=(start_line, lines.lineno),
position=Position.from_source_lines(lines, start_line=start_line),
)


Expand Down
7 changes: 4 additions & 3 deletions myst_parser/span_tokens.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import re
from typing import Pattern, Tuple
from typing import Pattern

import attr

from mistletoe import span_tokens
from mistletoe.attr_doc import autodoc
from mistletoe.base_elements import Position

__all__ = ("Role", "Target")

Expand All @@ -24,7 +25,7 @@ class Role(span_tokens.SpanToken):

role_name: str = attr.ib(metadata={"doc": "The name of the extension point"})
children = attr.ib(metadata={"doc": "a single RawText node for alternative text."})
position: Tuple[int, int] = attr.ib(
position: Position = attr.ib(
default=None,
repr=False,
metadata={"doc": "Line position in source text (start, end)"},
Expand Down Expand Up @@ -53,7 +54,7 @@ class Target(span_tokens.SpanToken):
children = attr.ib(
factory=list, metadata={"doc": "a single RawText node for alternative text."}
)
position: Tuple[int, int] = attr.ib(
position: Position = attr.ib(
default=None,
repr=False,
metadata={"doc": "Line position in source text (start, end)"},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
children:
- content: ''
position:
- 1
- 1
data: {}
line_end: null
line_start: 1
uri: null
raw: +++
type: BlockBreak
footnotes: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
children:
- content: a
position:
- 1
- 1
data: {}
line_end: null
line_start: 1
uri: null
raw: +++a
type: BlockBreak
footnotes: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
children:
- content: a
position:
- 1
- 1
data: {}
line_end: null
line_start: 1
uri: null
raw: +++ a
type: BlockBreak
footnotes: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
children:
- content: ''
position:
- 1
- 1
data: {}
line_end: null
line_start: 1
uri: null
raw: '+++ '
type: BlockBreak
footnotes: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ children:
type: ListItem
loose: false
position:
- 0
- 1
data: {}
line_end: 1
line_start: 0
uri: null
start_at: null
type: List
- content: ''
position:
- 2
- 2
data: {}
line_end: null
line_start: 2
uri: null
raw: +++
type: BlockBreak
footnotes: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
children:
- content: ''
position:
- 1
- 1
data: {}
line_end: null
line_start: 1
uri: null
raw: ' +++'
type: BlockBreak
footnotes: {}
Expand Down
6 changes: 4 additions & 2 deletions tests/test_syntax/test_ast/test_comment_basic_strings0_.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
children:
- content: comment
position:
- 1
- 1
data: {}
line_end: null
line_start: 1
uri: null
raw: '% comment'
type: LineComment
footnotes: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ children:
type: ListItem
loose: false
position:
- 0
- 1
data: {}
line_end: 1
line_start: 0
uri: null
start_at: null
type: List
- content: comment
position:
- 2
- 2
data: {}
line_end: null
line_start: 2
uri: null
raw: '% comment'
type: LineComment
footnotes: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
children:
- content: comment
position:
- 1
- 1
data: {}
line_end: null
line_start: 1
uri: null
raw: ' % comment'
type: LineComment
footnotes: {}
Expand Down

0 comments on commit 8b0d16e

Please sign in to comment.