Giter VIP home page Giter VIP logo

shakespearelang's People

Contributors

dependabot[bot] avatar stuart-thomas-zoopla avatar zmbc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

shakespearelang's Issues

Integers are read from (and written to) separate lines

I wrote the following program:

A rose by any other name.
Romeo, a speaker.
Juliet, his muse.
           Act I: Something.
           Scene I: A garden.
[Enter Romeo and Juliet]
Romeo: Open your mind! Speak your mind!
Romeo: Listen to your heart! Open your heart!
Romeo: Open your mind! Speak your mind!
[Exeunt]

Then ran:

% echo "a1b\n2 c\nd" | shakespeare run echo.spl

What I expect will be printed: a1b. What actually happens:

% echo "a1b\n2 c\nd" | shakespeare run echo.spl

aTraceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/bin/shakespeare", line 11, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/shakespearelang/cli.py", line 23, in run
    interpreter.run_play(play)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/shakespearelang/shakespeare_interpreter.py", line 212, in run_play
    done = self.step_forward(breakpoint_callback)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/shakespearelang/shakespeare_interpreter.py", line 196, in step_forward
    shouldnt_advance = self.run_event(event_to_run, breakpoint_callback)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/shakespearelang/shakespeare_interpreter.py", line 146, in run_event
    should_break = self.run_sentence(sentence, self._character_by_name(event.character))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/shakespearelang/shakespeare_interpreter.py", line 130, in run_sentence
    self._character_opposite(character).value = int(input())
ValueError: invalid literal for int() with base 10: '2 c'

(The "reference implementation" doesn't handle this correctly either.)

SyntaxError in `shakespeare_interpreter.py`

% shakespeare run echo.spl   
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/bin/shakespeare", line 7, in <module>
    from shakespearelang.cli import main
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/shakespearelang/cli.py", line 4, in <module>
    from .shakespeare_interpreter import Shakespeare
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/shakespearelang/shakespeare_interpreter.py", line 124
    print(chr(self._character_opposite(character).value), end="")
                                                             ^
SyntaxError: invalid syntax

I think this project assumes Python 3, but does not communicate that to pip. I was able to work around this by adding from __future__ import print_function to the top of shakespeare_interpreter.py.

Undeclared dependency on grako

% shakespeare run echo.spl
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/bin/shakespeare", line 7, in <module>
    from shakespearelang.cli import main
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/shakespearelang/cli.py", line 4, in <module>
    from .shakespeare_interpreter import Shakespeare
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/shakespearelang/shakespeare_interpreter.py", line 5, in <module>
    from .shakespeare_parser import shakespeareParser
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/shakespearelang/shakespeare_parser.py", line 16, in <module>
    from grako.buffering import Buffer
ImportError: No module named grako.buffering

I was able to work around this with pip install grako, but the package should probably declare this dependency.

Input Exception

I'm getting the 'No numeric input was given.' exception on line 376 as soon as a second number is requested. In the basic test below it reads the first number correctly, but immediately raises the exception on the second request.

I'll try to debug it and see if I can find what is causing it.

Test.
Macduff, test.
Horatio, test.
Act I: Test.
Scene I: Test.
[Enter Macduff and Horatio]
Macduff: Listen to your heart! Open your heart!
Horatio: Listen to your heart! Open your heart!
[Exeunt]

No module named 'readline'

Installed shakrespearelang and ran the example .spl and got the following error

Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "C:\Users\new\AppData\Local\Programs\Python\Python312\Scripts\shakespeare.exe\__main__.py", line 4, in <module> File "C:\Users\new\AppData\Local\Programs\Python\Python312\Lib\site-packages\shakespearelang\cli.py", line 7, in <module> from ._repl import start_console, debug_play File "C:\Users\new\AppData\Local\Programs\Python\Python312\Lib\site-packages\shakespearelang\_repl.py", line 6, in <module> import readline ModuleNotFoundError: No module named 'readline'

it seems that there is an import of an unused and missing module here

removing that import fixes it and the output is as expected

FailedParse exception when trying to use difference

The following example causes an unexpected FailedParse exception:

The adventures of Romeo.

Romeo, the noble hero of our story.
Hamlet, a cursing man.

        Act I: Love and Hate.

        Scene I: Curses.

[Enter Hamlet and Romeo]

Hamlet:
  You are as normal as the sum of a smelly vile disgusting curse and a cowardly foul misused snotty evil misused leech. You are as tiny as the difference of a toad and yourself. Speak your mind!

[Exeunt]

The traceback is:

Traceback (most recent call last):
  File "~/.local/lib/python3.7/site-packages/grako/contexts.py", line 200, in parse
    result = rule()
  File "~/.local/lib/python3.7/site-packages/grako/contexts.py", line 48, in wrapper
    return self._call(rule, name, params, kwparams)
  File "~/.local/lib/python3.7/site-packages/grako/contexts.py", line 456, in _call
    node, newpos, newstate = self._invoke_rule(rule, name, params, kwparams)
  File "~/.local/lib/python3.7/site-packages/grako/contexts.py", line 496, in _invoke_rule
    rule(self)
  File "~/.local/lib/python3.7/site-packages/shakespearelang/shakespeare_parser.py", line 1689, in _play_
    self._check_eof()
  File "~/.local/lib/python3.7/site-packages/grako/contexts.py", line 636, in _check_eof
    self._error('Expecting end of text.')
  File "~/.local/lib/python3.7/site-packages/grako/contexts.py", line 431, in _error
    item
grako.exceptions.FailedParse: (13:121) Expecting end of text. :
  You are as normal as the sum of a smelly vile disgusting curse and a cowardly foul misused snotty evil misused leech. You are as tiny as the difference of a toad and yourself. Speak your mind!
                                                                                                                        ^
play

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "~/.local/bin/shakespeare", line 10, in <module>
    sys.exit(main())
  File "~/.local/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "~/.local/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "~/.local/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "~/.local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "~/.local/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "~/.local/lib/python3.7/site-packages/shakespearelang/cli.py", line 26, in run
    interpreter.run_play(play)
  File "~/.local/lib/python3.7/site-packages/shakespearelang/shakespeare_interpreter.py", line 67, in run_play
    self.ast = self._parse_if_necessary(play, 'play')
  File "~/.local/lib/python3.7/site-packages/shakespearelang/shakespeare_interpreter.py", line 238, in _parse_if_necessary
    return self.parser.parse(item, rule_name=rule_name)
  File "~/.local/lib/python3.7/site-packages/grako/contexts.py", line 208, in parse
    raise self._furthest_exception
  File "~/.local/lib/python3.7/site-packages/grako/contexts.py", line 666, in _option
    yield
  File "~/.local/lib/python3.7/site-packages/shakespearelang/shakespeare_parser.py", line 1017, in block2
    self._negative_adjective_()
  File "~/.local/lib/python3.7/site-packages/grako/contexts.py", line 48, in wrapper
    return self._call(rule, name, params, kwparams)
  File "~/.local/lib/python3.7/site-packages/grako/contexts.py", line 456, in _call
    node, newpos, newstate = self._invoke_rule(rule, name, params, kwparams)
  File "~/.local/lib/python3.7/site-packages/grako/contexts.py", line 496, in _invoke_rule
    rule(self)
  File "~/.local/lib/python3.7/site-packages/shakespearelang/shakespeare_parser.py", line 305, in _negative_adjective_
    self._error('expecting one of: bad cowardly cursed damned dirty disgusting distasteful dusty evil fat fat-kidneyed fatherless foul hairy half-witted horrible horrid infected lying miserable misused oozing rotten smelly snotty sorry stinking stuffed stupid vile villainous worried')
  File "~/.local/lib/python3.7/site-packages/grako/contexts.py", line 431, in _error
    item
grako.exceptions.FailedParse: (13:144) expecting one of: bad cowardly cursed damned dirty disgusting distasteful dusty evil fat fat-kidneyed fatherless foul hairy half-witted horrible horrid infected lying miserable misused oozing rotten smelly snotty sorry stinking stuffed stupid vile villainous worried :
  You are as normal as the sum of a smelly vile disgusting curse and a cowardly foul misused snotty evil misused leech. You are as tiny as the difference of a toad and yourself. Speak your mind!
                                                                                                                                               ^
negative_adjective
negative_noun_phrase
noun_phrase
value
assignment
sentence
line
event
scene
act
play

When running this example with https://github.com/drsam94/Spl it gives the expected output G.

When I replace difference with sum I am not getting a FailedParse exception anymore (but a ValueError: chr() arg not in range(0x110000)).

When I replace what Romeo says with the following example from Wikipedia it outputs the expected "e":

 You are as brave as the sum of your fat little stuffed misused dusty
 old rotten codpiece and a beautiful fair warm peaceful sunny summer's
 day. You are as healthy as the difference between the sum of the
 sweetest reddest rose and my father and yourself! Speak your mind!

Both example have a sum in the first sentence and a difference in the second sentence. I do not understand why the Wikipedia example works but mine does not.

AI

since this language is Turing complete , can I use it to build machine learning models?

PyPI Version Incorrect?

Hello zmbc, would you mind to update the PyPI package of this repo? Its last release was in 2019 and has a lot of bugs. 1.0.0rc1 is much better and fixes a lot of the bugs.

Btw love this project, thank you! ❤️

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.