parse-js manual

parse-js is a Common Lisp package for parsing JavaScript ... ECMAScript 3, to be more precise. It is released under a zlib-style licence. For any feedback, contact me: Marijn Haverbeke.

The library can be downloaded, checked out from the Darcs repository, or installed with asdf-install.

Reference

function parse-js (stream &optional strict-semicolons)
→ syntax-tree

Reads a program from a stream, and produces an abstract syntax tree, which is a nested structure consisting of lists starting with keywords. The exact format of this structure is, I am afraid, not currently documented, but can be rather easily figured out by trying things out or looking at the source code of the parser.

When strict-semicolons is true, the parser will complain about missing semicolons, even when they would have been inserted by 'automatic semicolon insertion' rules.

function parse-js-string (string &optional strict-semicolons)
→ syntax-tree

Like parse-js, but takes a string as input instead of a stream.

class js-parse-error

The type of errors raised when invalid input is encountered. Inherits from simple-error, and has js-parse-error-line and js-parse-error-character accessors that can be used to read the location at which the error occurred.

function lex-js (stream)
→ function

A JavaScript tokeniser. The function returned can be called repeatedly to read the next token object. See below for a description of these objects. When the end of the stream is reached, tokens with type :eof are returned.

function token-type (token)
→ keyword

Reader for the type of token objects. Types are keywords (one of :num :punc :string :operator :name :atom :keyword :eof).

function token-value (token)
→ value

Reader for the content of token objects. The type of this value depends on the type of the token ― it holds strings for names, for example, and numbers for number tokens.

function token-line (token)
→ number

The line on which a token was read.

function token-char (token)
→ number

The character at which a token starts.