Skip to content
This repository was archived by the owner on Sep 27, 2020. It is now read-only.

Tokenize function is not working #94

@fvictorio

Description

@fvictorio

Using version 0.4.11.

Reproduction steps: install the library and run:

const parser = require('solidity-parser-antlr')

const tokens = parser.tokenize('contract Foo {}')

Throws this error:

Error: ENOENT: no such file or directory, open <root>/node_modules/solidity-parser-antlr/lib/Solidity.tokens'

Possible fix

I cloned the repo and made two modifications:

  1. Change the build script to rm -rf dist && babel --out-dir=dist src --copy-files (adds --copy-files)
  2. In src/tokens.js, make this change:
diff --git a/src/tokens.js b/src/tokens.js
index 10836dd..f47b0ac 100644
--- a/src/tokens.js
+++ b/src/tokens.js
@@ -55,7 +55,7 @@ function getTokenType(value) {
 }
 
 function getTokenTypeMap() {
-  const filePath = path.join(__dirname, '../lib/Solidity.tokens')
+  const filePath = path.join(__dirname, './lib/Solidity.tokens')
 
   return fs
     .readFileSync(filePath)

This worked for me, but I'm not sure if it may have another implications. If you want, I can create a PR with this change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions