Registry / testing / hm-parser

hm-parser

JSON →
library0.1.5jsnpmunverified

A parser for Hindley-Milner type signatures, designed as a drop-in replacement for hindley-milner-parser-js but without its babel-polyfill dependency and performance issues. Version 0.1.5 is the latest stable release, with infrequent updates. It supports Haskell-like syntax with JS-specific sugar for methods. Faster and more compatible with modern tooling than the original.

npm install hm-parser
INSTALL
IMPORT
SIG · HM-PARSER
H
hm-parser
testingjavascriptv0.1.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import { parse } from 'hm-parser'
import HMP from 'hm-parser'
The package exports a named object with a parse method; default import does not exist.
HMP
import * as HMP from 'hm-parser'
const HMP = require('hm-parser').parse
CommonJS usage: const HMP = require('hm-parser'). Default import is not available; use namespace import.
parse
const { parse } = require('hm-parser')
const parse = require('hm-parser')
CommonJS destructuring is required to get the parse function.

Parses a Hindley-Milner type signature and outputs the AST.

const { parse } = require('hm-parser'); const result = parse('hello :: a -> Maybe a'); console.log(JSON.stringify(result, null, 2)); // { // "name": "hello", // "constraints": [], // "type": { // "type": "function", // "text": "", // "children": [ // { "type": "typevar", "text": "a", "children": [] }, // { "type": "typeConstructor", "text": "Maybe", "children": [ // { "type": "typevar", "text": "a", "children": [] } // ]} // ] // } // }
Debug
Known issues
gotchaThe package does not export a default export; attempting to import it as default will result in undefined.
fix
Use named import or namespace import as shown in imports.
affects: >=0.0.0
gotchaThe parse function expects a string with a type signature; passing malformed input will throw an error.
fix
Ensure input follows Hindley-Milner syntax supported by the parser.
affects: >=0.0.0
gotchaThe package is a drop-in replacement for hindley-milner-parser-js but has a different API: it exports an object with a parse method, not the function directly.
fix
Use const { parse } = require('hm-parser') instead of const parse = require('hindley-milner-parser-js').
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: HMP.parse is not a function
Importing the default export instead of the named export.
fix
Use const { parse } = require('hm-parser') or import { parse } from 'hm-parser'.
Cannot find module 'hm-parser'
Package not installed.
fix
Run npm install hm-parser or yarn add hm-parser.
Unexpected token
Invalid type signature syntax.
fix
Check the input string for correct Hindley-Milner syntax (e.g., 'hello :: a -> Maybe a').
Upgrade
Version history
0.1.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
hm-parser — npm install hm-parser · libregistry