Git Product home page Git Product logo

scrapscript's Introduction

Scrapscript Interpreter

See scrapscript.org for some more information. Keep in mind that the syntax on the website will change a little bit in the coming weeks to match this repository.

Take a look inside scrapscript.py and all of its tests to get an idea for how the language works.

Usage

We support python3.8+.

# With a file
python3 scrapscript.py eval examples/0_home/factorial.scrap

# With a string literal
python3 scrapscript.py apply "1 + 2"

# With a REPL
python3 scrapscript.py repl

or with Cosmopolitan:

./build-com

# With a file
./scrapscript.com eval examples/0_home/factorial.scrap

# With a string literal
./scrapscript.com apply "1 + 2"

# With a REPL
./scrapscript.com repl

(if you have an exec format error and use Zsh, either upgrade Zsh or prefix with sh)

or with Docker:

# With a file (mount your local directory)
docker run --mount type=bind,source="$(pwd)",target=/mnt -i -t ghcr.io/tekknolagi/scrapscript:trunk eval /mnt/examples/0_home/factorial.scrap

# With a string literal
docker run -i -t ghcr.io/tekknolagi/scrapscript:trunk apply "1 + 2"

# With a REPL
docker run -i -t ghcr.io/tekknolagi/scrapscript:trunk repl

Running Tests

python3 scrapscript.py test

scrapscript's People

Contributors

tekknolagi avatar gregorybchris avatar

Stargazers

3xcpy avatar Jeff Carpenter avatar Philip Zucker avatar Chaz Straney avatar  avatar Cameron Kelley avatar  avatar tripleo avatar Jody Frankowski avatar nuin avatar Jack Webb-Heller avatar  avatar  avatar  avatar David Enochs avatar  avatar Satyam Mishra avatar Drew Olson avatar Beto Dealmeida avatar  avatar Michael Rodler avatar Robin Siep avatar  avatar  avatar Khushmeet Singh avatar Yoshihiro Tanaka avatar Radosław Szamszur avatar Aleksander Gondek avatar Will Maier avatar Thassilo Schulze avatar Lei Lei avatar HIRAKI Satoru avatar Brian Hammond avatar yuiseki avatar Eugen Pavličević avatar KOBAYASHI Yū avatar  avatar Josef Pospíšil avatar Alex Cameron avatar Aman Bansal avatar Vinh Tran avatar Cristián Romo avatar Sebastian Tunberg avatar Nikolaus Schlemm avatar  avatar  avatar Ivan Ermakov avatar Hayden Jones avatar Patrick avatar Josh Karpel avatar Bhavit Sharma avatar Tom Kenny avatar Rhea Myers avatar Victor Song avatar  avatar latrokles avatar Troy Hinckley avatar  avatar Grant Williams avatar Avneesh Sarwate avatar Ben avatar  avatar Lulzx avatar anjan bacchu avatar Ricardo avatar Joel Walker avatar jacobi petrucciani avatar  avatar Daniel Nakov avatar Andreas Prell avatar Javier Vizoso avatar fwcd avatar Robert Whitaker avatar Mtv Europe avatar Christopher Carvalho avatar Bryan Helmig avatar Olaf Tomalka avatar Joel Burget avatar Andrejs Agejevs avatar  avatar Andrew Lamzed-Short avatar  avatar Mark Friedgan avatar  avatar Hunter Madison avatar Yvan Sraka avatar Joshua Munn avatar Raphael LANG avatar coderock avatar Carl Bordum Hansen avatar  avatar Jag Chadha avatar David Wu avatar Costa Bushnaq avatar  avatar Shaurya Agarwal avatar  avatar Hector Peeters avatar Krispin Schulz avatar Samuele avatar

Watchers

 avatar  avatar Olaf Tomalka avatar David Enochs avatar  avatar yeti avatar  avatar

scrapscript's Issues

Boolean NOT operator

We have NOT_EQUAL (\=) and pattern matching on #true/#false, so implementing boolean NOT is technically possible, but would be easier with a dedicated NOT operator. ! is already taken by RIGHT_EVAL.

Float literals

We currently support int literals, but we should also support float literals

Maintain line and character number after parsing

Evaluation has many failure cases, many of which have pretty reasonable error messages. However we do not maintain the line and character numbers associated with nodes in the AST. The interpreter can't point to the part of the code associated with a failure that occurs during evaluation.

This feature request is to make code index information available in the evaluation stage.

Recursive serialization

For example,

fac =
| 0 -> 1
| n -> n * fac (n - 1)

won't serialize because it results in a closure that references itself.

Implement alternates

 ()
  . _ = scoop :: chocolate ( )
  . scoop : # vanilla ( ) # chocolate ( ) # strawberry ( )
  . _ : p = p :: point { x = 3 , y = 4 }
  . p : # point { x : int , y : int }
  . tuple : x => y => z => # pair { x : x , y : y } # triplet { x : x , y : y , z : z }

scrapscript shebang

Can you please allow # as comment char in the 1st line in a script?

That would make using #!/path/to/scrapscript.py there possible and so probably would allow directly executable scripts.

Current reaction:

$ ls -l test.ss 
-rwxr-xr-x 1 yeti yeti 104 Dec  8 16:08 test.ss
$ ./test.ss 
Traceback (most recent call last):
  File "/tmp/mc-yeti/scrapscript.py", line 2800, in <module>
    main()
  File "/tmp/mc-yeti/scrapscript.py", line 2796, in main
    args.func(args)
  File "/tmp/mc-yeti/scrapscript.py", line 2611, in eval_command
    tokens = tokenize(program)
  File "/tmp/mc-yeti/scrapscript.py", line 239, in tokenize
    while (token := lexer.read_one()) and not isinstance(token, EOF):
  File "/tmp/mc-yeti/scrapscript.py", line 180, in read_one
    raise ParseError(f"unexpected token {c!r}", ("<input>", self.lineno, self.colno, self.line))
  File "<input>", line 1
    #
     ^
__main__.ParseError: unexpected token '#'

Or is that a case of PEBCAK?

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.