npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lexiparse

v1.0.2

Published

Combined Lexical Analyzer and Parser for making programming language interpreters or compilers -- but from JavaScript. (Note: the Lexiparse class is all you need. The rest is for the example.)

Downloads

6

Readme

The Lexiparse class may be used to instantiate a combined lexical analyzer / parser generator for making programming language interpreters and/or compilters.

First you must: * Code your language's grammar definition (notation described later herein) * Include and instantiate an instance of the Lexiparse class, passing your grammar definition and any non-default options into the constructor.

The sample file "burp.js" illustrates with implementation of the "burp" language.


Grammar Definition

The grammar definition is a JavaScript object, such as the following illustrative example:

grammar = {
	'stmt':[
		['input',':var', getInput],
		['output',':expr', doOutput],
		['var','=',':expr', doAssignment]
	],
	'expr':[
		':numlit',
		':var',
		[':expr','+',':expr', doAddition],
		[':expr','+',':expr', doSubtraction],
		['(',':expr',')']
	],
	'var':[/^[A-Za-z][A-Za-z0-9]+/,getValue],
	'numlit':[/^[+-]?\d+(\.\d+)?/],
}

The 'stmt', 'expr', 'var', and 'numlit' elements are named grammar

segments. Each holds an array of options, any of which will evaluate to it. These options may be strings, regular expressions, or sub-arrays (representing sequences). Each works like this:

String
	A string not starting with a colon is interpreted as a literal to match

in the program source code. However, if the string begins with a colon (and not a double-colon than the rest of the string is interpreted as the name of a grammar segment. For example, ':expr' means as defined under segment 'expr'. However, '::expr' would mean the text literal '::expr'.

Regular Expression
	Regular expressions must always begin with a karat character ('^') but

are otherwise normal regular expressions to match against program source code. It will extract exactly what the JavaScript Rexexp.exec() produces, so you may make use of parenthesis, etc., as desired.

Sequence
	If a segment option is an array itself, the elements of that array are

interpreted as required items in sequence. Furthermore, the last element may optionally be a function to preprocess the option's returned values. For example, the 'stmt' segment has 3 sequences under it. The 'expr' segment has 5 options, the last 3 of which are sequences.


Constructor Options

caseful
	This may be true (default) for case sensitivity or false for case 
	insensitivity.

ignore
	This should hold an array of characters to ignore.  Usually, this will
	be the whitespace characters of your language.
	NOTE: In the future, I might want to add a way to specify ignored 
	characters for each named segment, individually.

sequenceBlind (TODO: not yet implemeneted)
	If true, sequences will match if all elements exist in place, in order,
	but will ignore any extraneous elements before, after, or between.

literalBlind (TODO: not yet implemented)
	If true, tolerate keyword mispellings where still recognizable.