-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4-feat-build-srcplccscannermatcherpy #22
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought I'd give you a couple pointers.
@@ -0,0 +1,33 @@ | |||
from ...load_spec.parse_spec import parse_lexical_spec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't want to depend on parse_lexical_spec. The input we'll be given is pre-parsed and pre-validated, and is JSON. When JSON is loaded in Python using json.load
or json.loads
it will become a nested structure of dict, list, str, int, bool, etc. So from the perspective of the Matcher, a lexical spec looks like...
spec = [
{
"type": "Token",
"name": "MINUS",
"regex": "-"
}
]
spec[0]['name'] == 'MINUS'
There may be other fields, like Line, but I don't think you'll need them. If you do, great.
|
||
def test_empty_line(): | ||
test_matcher = make_matcher() | ||
assert "LexError" == test_matcher.match("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
match() should take a Line and an index and return one of three kinds of objects: LexError, Token, and Skip.
A test would then look something like...
def test_empty_line():
matcher = make_matcher()
line = Line(text="", file=None, number=1)
result = test_matcher.match(line=line, index=0)
assert result == LexError(line=line, column=1)
|
||
def test_not_empty_line(): | ||
test_matcher = make_matcher() | ||
assert "-" == test_matcher.match("+++-++") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_non_empty_line():
matcher = make_matcher()
line = Line(text="-", file=None, number=1)
result = test_matcher.match(line=line, index=0)
assert result == Token(name="MINUS", lexeme="-", line=line, column=1)
No description provided.