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?
struct
(struct identifier syntax-element (symbol))
symbol : symbol?
struct
(struct function syntax-element (name parameters body))
name : (or/c identifier? #f) parameters : (listof identifier?) body : (listof (or/c function? statement?))
struct
(struct variable-declaration syntax-element (name initializer))
name : identifier? initializer : (or/c expression? #f)
7.1.1 Expressions
struct
struct
(struct expression:literal expression (value))
value : literal?
struct
struct
(struct expression:reference expression (identifier))
identifier : identifier?
struct
(struct expression:member-reference expression (base property))
base : expression? property : (or/c identifier? expression?)
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?
struct
(struct expression:conditional expression (test true false))
test : expression? true : expression? false : expression?
struct
(struct expression:call expression (function arguments))
function : expression? arguments : (listof expression?)
struct
(struct expression:new expression (constructor arguments))
constructor : expression? arguments : (listof expression?)
struct
(struct expression:function expression (definition))
definition : function?
struct
(struct expression:comma expression (left right))
left : expression? right : expression?
7.1.2 Literals
struct
(struct literal syntax-element ())
struct
(struct literal:null literal ())
struct
(struct literal:boolean literal (value))
value : boolean?
struct
(struct literal:number literal (value))
value : number?
struct
(struct literal:string literal (value))
value : string?
struct
(struct literal:regexp literal (pattern flags))
pattern : string? flags : string?
struct
(struct literal:array literal (elements))
elements : (listof (or/c expression? #f))
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?
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
struct
struct
(struct statement:block statement (body))
body : (listof statement?)
struct
(struct statement:break statement (label))
label : (or/c identifier? #f)
struct
(struct statement:continue statement (label))
label : (or/c identifier? #f)
struct
struct
(struct statement:do statement (body test))
body : statement? test : expression?
struct
struct
(struct statement:expression statement (expression))
expression : expression?
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?
struct
(struct statement:for-in stmt (index expression body))
index : (or/c expression? variable-declaration?) expression : expression? body : statement?
struct
(struct statement:if statement (test true false))
test : expression? true : statement? false : (or/c statement? #f)
struct
(struct statement:label statement (label statement))
label : identifier? statement : statement?
struct
(struct statement:return statement (expression))
expression : (or/c expression? #f)
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?)
struct
(struct statement:throw statement (expression))
expression : expression?
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)
struct
(struct statement:var statement (declarations))
declarations : (listof variable-declaration?)
struct
(struct statement:while statement (test body))
test : expression? body : statement?
struct
(struct statement:with statement (expression body))
expression : expression? body : statement?