On this page:
read-program
7.1 Abstract Syntax
syntax-element
identifier
function
variable-declaration
7.1.1 Expressions
expression
expression:  literal
expression:  this
expression:  reference
expression:  member-reference
operator
expression:  postfix
expression:  unary
expression:  binary
expression:  conditional
expression:  call
expression:  new
expression:  function
expression:  comma
7.1.2 Literals
literal
literal:  null
literal:  boolean
literal:  number
literal:  string
literal:  regexp
literal:  array
literal:  object
property-initializer
property-initializer:  data
property-initializer:  get
property-initializer:  set
7.1.3 Statements
statement
statement:  block
statement:  break
statement:  continue
statement:  debugger
statement:  do
statement:  empty
statement:  expression
statement:  for
statement:  for-in
statement:  if
statement:  label
statement:  return
statement:  switch
case-clause
default-clause
statement:  throw
statement:  try
statement:  var
statement:  while
statement:  with
8.12

7 Parsing ECMAScript🔗ℹ

 (require ecmascript/parse) package: ecmascript

procedure

(read-program [source-name in])

  (or/c (listof (or/c function? statement?)) eof-object?)
  source-name : any/c = (object-name in)
  in : input-port? = (current-input-port)

7.1 Abstract Syntax🔗ℹ

 (require ecmascript/ast) package: ecmascript

struct

(struct syntax-element (location))

  location : source-location?
The base type for all ECMAScript syntax elements.

struct

(struct identifier syntax-element (symbol))

  symbol : symbol?
An identifier.

struct

(struct function syntax-element (name parameters body))

  name : (or/c identifier? #f)
  parameters : (listof identifier?)
  body : (listof (or/c function? statement?))
A function definition, which may appear as part of an expression (in which case name may be #f) or program body, or nested within another function.

struct

(struct variable-declaration syntax-element (name initializer))

  name : identifier?
  initializer : (or/c expression? #f)
A variable declaration with optional initializer.

7.1.1 Expressions🔗ℹ

The base type for all ECMAScript expressions.

struct

(struct expression:literal expression (value))

  value : literal?
A literal value expression.

The this keyword.

struct

(struct expression:reference expression (identifier))

  identifier : identifier?
An identifier reference.

struct

(struct expression:member-reference expression (base property))

  base : expression?
  property : (or/c identifier? expression?)
A member reference. This struct represents expressions of the form object.property and object[property], depending on the type of property.

struct

(struct operator syntax-element (symbol))

  symbol : symbol?

struct

(struct expression:postfix expression (operand operator))

  operand : expression?
  operator : operator?

struct

(struct expression:unary expression (operator operand))

  operator : operator?
  operand : expression?

struct

(struct expression:binary expression (left operator right))

  left : expression?
  operator : operator?
  right : expression?
Operator expressions.

struct

(struct expression:conditional expression (test true false))

  test : expression?
  true : expression?
  false : expression?
The conditional (ternary) operator ?:.

struct

(struct expression:call expression (function arguments))

  function : expression?
  arguments : (listof expression?)
A function call.

struct

(struct expression:new expression (constructor arguments))

  constructor : expression?
  arguments : (listof expression?)
A new expression.

struct

(struct expression:function expression (definition))

  definition : function?
A function expression.

struct

(struct expression:comma expression (left right))

  left : expression?
  right : expression?
The comma operator.

7.1.2 Literals🔗ℹ

The base type for all literals.

The null keyword.

struct

(struct literal:boolean literal (value))

  value : boolean?

struct

(struct literal:number literal (value))

  value : number?

struct

(struct literal:string literal (value))

  value : string?
A boolean, numeric or string literal.

struct

(struct literal:regexp literal (pattern flags))

  pattern : string?
  flags : string?
A regular expression literal. The flags field should be a (possibly empty) string consisting of a combination of the characters g, i and m.

struct

(struct literal:array literal (elements))

  elements : (listof (or/c expression? #f))
An array literal. A #f value for any element indicates an elision.

struct

(struct literal:object literal (properties))

  properties : (listof property-initializer?)

struct

(struct property-initializer syntax-element (name))

  name : (or/c identifier? literal:string? literal:number?)

struct

(struct property-initializer:data property-initializer (value))

  value : expression?

struct

(struct property-initializer:get property-initializer (function))

  function : function?

struct

(struct property-initializer:set property-initializer (function))

  function : function?
An object literal.

A property-initializer:get initializer must be an anonymous function of no arguments. A property-initializer:set initializer must be an anonymous function of one argument.

7.1.3 Statements🔗ℹ

The base type for all statements.

struct

(struct statement:block statement (body))

  body : (listof statement?)
A block.

struct

(struct statement:break statement (label))

  label : (or/c identifier? #f)
A break statement.

struct

(struct statement:continue statement (label))

  label : (or/c identifier? #f)
A continue statement.

A debugger statement.

struct

(struct statement:do statement (body test))

  body : statement?
  test : expression?
A do statement.

An empty statement. See empty-statement.

struct

(struct statement:expression statement (expression))

  expression : expression?
An expression statement.

struct

(struct statement:for statement (initializer test update body))

  initializer : (or/c expression? (listof variable-declaration?) #f)
  test : (or/c expression? #f)
  update : (or/c expression? #f)
  body : statement?
A for statement.

struct

(struct statement:for-in stmt (index expression body))

  index : (or/c expression? variable-declaration?)
  expression : expression?
  body : statement?
See for-in.

struct

(struct statement:if statement (test true false))

  test : expression?
  true : statement?
  false : (or/c statement? #f)
An if statement.

struct

(struct statement:label statement (label statement))

  label : identifier?
  statement : statement?
A labelled statement. See label.

struct

(struct statement:return statement (expression))

  expression : (or/c expression? #f)
A return statement.

struct

(struct statement:switch statement (expression body))

  expression : expression?
  body : (listof (or/c case-clause? default-clause?))

struct

(struct case-clause syntax-element (expression body))

  expression : expression?
  body : (listof statement?)

struct

(struct default-clause syntax-element (body))

  body : (listof statement?)
A switch statement.

struct

(struct statement:throw statement (expression))

  expression : expression?
A throw statement.

struct

(struct statement:try statement (body
    catch-id
    catch-body
    finally-body))
  body : statement:block?
  catch-id : (or/c identifier? #f)
  catch-body : (or/c statement:block? #f)
  finally-body : (or/c statement:block? #f)
A try statement.

struct

(struct statement:var statement (declarations))

  declarations : (listof variable-declaration?)
A variable declaration statement.

struct

(struct statement:while statement (test body))

  test : expression?
  body : statement?
A while statement.

struct

(struct statement:with statement (expression body))

  expression : expression?
  body : statement?
A with statement.