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

Parser does not work when compiling to JavaScript #84

Open
xigoi opened this issue Jun 9, 2021 · 2 comments
Open

Parser does not work when compiling to JavaScript #84

xigoi opened this issue Jun 9, 2021 · 2 comments
Labels

Comments

@xigoi
Copy link

xigoi commented Jun 9, 2021

Minimal example:

# A parser that only parses the string "0"

import nimly
import patty

variant ZeroToken:
  zero

niml ZeroLexer[ZeroToken]:
  r"0":
    zero()

nimy ZeroParser[ZeroToken]:
  top[int]:
    zero:
      0

var lexer = ZeroLexer.newWithString("0")
var parser = ZeroParser.newParser
echo parser.parse lexer

When the code is compiled to C, it successfully outputs 0. However, if compiled to JavaScript (with -d:release), it outputs:

/home/xigoi/sandbox/nimlytest.js:878
    throw new Error(cbuf_1420201);
    ^

Error: Error: unhandled exception: Unexpected token(kind: TermS, term: zero)is passed.
token: (kind: zero) [NimyActionError]

    at unhandledException (/home/xigoi/sandbox/nimlytest.js:878:11)
    at raiseException (/home/xigoi/sandbox/nimlytest.js:478:5)
    at parseImpl_14412133 (/home/xigoi/sandbox/nimlytest.js:2596:11)
    at parse_14412000 (/home/xigoi/sandbox/nimlytest.js:2962:25)
    at Object.<anonymous> (/home/xigoi/sandbox/nimlytest.js:2972:23)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)

Note that this happens both in Node and in the browser. The error happens on the first token passed to the parser, no matter what the parser looks like.

@loloicci
Copy link
Owner

Sorry, nimly does not support compiling to JS now.

nimly targets to use as a part of compilers, so it only targets C/C++ compiling. In what situation do you want to use nimly in JS? If it looks like a common situation, I will try to support JS.

Or, you are very welcome to make PRs for supporting JS!

@xigoi
Copy link
Author

xigoi commented Jun 10, 2021

I'm making a library that my team wants to use both in JavaScript and in Python. But I found out that I can use NPeg instead (which seems to work fine with JavaScript), so it's not a problem in the end. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants