Skip to content

Parser does not work when compiling to JavaScript #84

@xigoi

Description

@xigoi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions