Skip to content
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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

TheDragonApple
Copy link

No description provided.

@TheDragonApple TheDragonApple linked an issue Feb 7, 2025 that may be closed by this pull request
7 tasks
@TheDragonApple TheDragonApple marked this pull request as draft February 7, 2025 03:34
@TheDragonApple TheDragonApple changed the title Create matcher files and begin matcher algo 4-feat-build-srcplccscannermatcherpy Feb 7, 2025
Copy link
Member

@StoneyJackson StoneyJackson left a 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
Copy link
Member

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.

src/plccng/Scanner/matcher/matcher_test.py Outdated Show resolved Hide resolved
src/plccng/Scanner/matcher/matcher_test.py Outdated Show resolved Hide resolved
src/plccng/Scanner/matcher/matcher_test.py Outdated Show resolved Hide resolved

def test_empty_line():
test_matcher = make_matcher()
assert "LexError" == test_matcher.match("")
Copy link
Member

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("+++-++")
Copy link
Member

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)

src/plccng/Scanner/matcher/matcher.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Revising
Development

Successfully merging this pull request may close these issues.

feat: build src/plcc/scanner/matcher.py
2 participants