Giter Club home page Giter Club logo

pylox's Introduction

Hi there, I'm sco1! ๐Ÿ‘‹

StackOverflow Slack HackerNews Mastodon

I'm a Boston-based Aerospace Engineer focused on test & evaluation.

Programming Interests

  • Data collection, postprocessing, and visualization
  • CLI and GUI tooling
  • Code quality
  • Software testing

I also find joy in making hilarious things like:

pylox's People

Contributors

pre-commit-ci[bot] avatar sco1 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

pylox's Issues

Chapter 6 Challenges (pg. 94)

  • Support comma expressions
  • Support ternary operator
  • Add syntax error for binary operation at the beginning of an expression

Chapter 7 Challenges (pg. 109)

  • Allow comparisons between types other than numbers
  • Concatenation of strings with other types
  • How should divison by zero be handled?

Chapter 8 Challenges (pg. 133)

  • Update REPL so it supports statements and expressions
  • Make it a runtime error to access a variable that has not been initialized with a value

Incorrect newline parsing

Newlines are being escaped when parsed for some reason:

$ pylox
>>> print len("\n");  // expect: 1
2

Which prevents comparisons between "\n" and newlines from files. e.g.

var sample = read_text("sample_input.txt");

fun split_on(in_str, delimiter) {
    // Split the input string on the specified delimiter & return a LoxArray of strings
    var out = array(0);
    var split_txt = string_array(in_str);
    var substr = "";
    for (var i = 0; i < len(in_str); i = i + 1) {
        if (split_txt.get(i) == delimiter) {
            out.append(substr);
            substr = "";
        }
        else {
            substr = substr + split_txt.get(i);
        }
    }

    out.append(substr);
    return out;
}

print split_on(sample, "\n");

Prints ['1\n2']

I suspect that this originates at the scanner, since we get the following token for "\n":

Token(
    token_type=<TokenType.STRING: 24>, 
    lexeme='"\\n"', 
    literal='\\n', 
    lineno=0, 
    end_lineno=0, 
    col_offset=10, 
    end_col_offset=14
)

Similar behavior exists for e.g. "\t" as well

Array sorting

Would be good to have built in array sorting, perhaps with both in-place and new array variants?

Fix typing

Once Mypy is updated to support pattern matching, need to go through and make sure our typing is correct.

Improve error reporting for imported source

Related to #4 and 9ad53de, error reporting can probably be improved a bit more than what we have for our baseline.

While a blanket subtraction of the number of lines inserted gives a helpful offset for issues with the on-disk code, if there's an issue with imported code then we have no idea which one, since the reported line number is going to be <=0 (lol). To clean this up a bit, let's keep track of a bit more metadata on what's been imported & where so we can point to the correct include if there ends up being an issue.

Include some regex builtins

To be ready for this year's Advent of Code, we'll likely need some basic regex capabilities. For the sake of time, add some basic passthrough to Pythons re module rather than implementing a regex engine from scratch.

Let's do a quick check through my existing AoC solutions to see what the most common use cases are; I suspect we won't need much more than re.findall and maybe re.sub.

Basic import mechanism

It would be nice to have a way to be able to write some external lox code and include it without needing to manually copy/paste.

As a quick & dirty start, let's try introducing an include keyword that allows us to specify a path to the file. Before the scanner runs, go through the include statements and (temporarily) replace them with the source from the referenced path.

For now let's make the following assumptions:

  • One path per include line
  • Source files contain valid code
  • Referenced source files do not themselves have any imports
  • Source files don't share any identifiers in the global scope

Things to think about for later:

  • Should we warn/error about duplicate imports?
  • How could we expand to recursive imports if we wanted to in the future?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.