Skip to content

Commit 7867b19

Browse files
committed
Initial Commit
0 parents  commit 7867b19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+835
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/_build
2+
/deps
3+
erl_crash.dump
4+
*.ez
5+
/doc
6+
/docs

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# v1.0.0-dev
2+
3+
* Enhancements
4+
* Should implement all non-E4X nodes from the Parser API

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SpiderMonkey
2+
============
3+
4+
A Full (or near full) implementation of the SpiderMonkey Parser API in Elixir

config/config.exs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This file is responsible for configuring your application
2+
# and its dependencies with the aid of the Mix.Config module.
3+
use Mix.Config
4+
5+
# This configuration is loaded before any dependency and is restricted
6+
# to this project. If another project depends on this project, this
7+
# file won't be loaded nor affect the parent project. For this reason,
8+
# if you want to provide default values for your application for third-
9+
# party users, it should be done in your mix.exs file.
10+
11+
# Sample configuration:
12+
#
13+
# config :logger, :console,
14+
# level: :info,
15+
# format: "$date $time [$level] $metadata$message\n",
16+
# metadata: [:user_id]
17+
18+
# It is also possible to import configuration files, relative to this
19+
# directory. For example, you can emulate configuration per environment
20+
# by uncommenting the line below and defining dev.exs, test.exs and such.
21+
# Configuration from the imported file will override the ones defined
22+
# here (which is why it is important to import them last).
23+
#
24+
# import_config "#{Mix.env}.exs"

lib/spider_monkey.ex

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
defmodule SpiderMonkey do
2+
@moduledoc """
3+
A Full (or near full) implementation of the SpiderMonkey Parser API in Elixir
4+
5+
[Parser API docs](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Parser_API)
6+
"""
7+
8+
@type unary_operator :: :- | :+ | :! | :"~" | :typeof | :void | :delete
9+
10+
@type binary_operator :: :== | :!= | :=== | :!== | :< | :<= | :> | :>= |
11+
:"<<" | :">>" | :>>> | :+ | :- | :* | :/ | :% | :| |
12+
:^ | :& | :in | :instanceof | :..
13+
14+
@type logical_operator :: :|| | :&&
15+
16+
@type assignment_operator :: := | :"+=" | :"-=" | :"*=" | :"/=" | :"%=" |
17+
:"<<=" | :">>=" | :">>>=" |
18+
:"|=" | :"^=" | :"&="
19+
20+
@type update_operator :: :++ | :--
21+
end

lib/spider_monkey/array_expression.ex

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defmodule SpiderMonkey.ArrayExpression do
2+
@type t :: %SpiderMonkey.ArrayExpression{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
elements: [SpiderMonkey.Expression.t | nil]
6+
}
7+
defstruct type: "ArrayExpression",
8+
loc: nil,
9+
elements: []
10+
end

lib/spider_monkey/array_pattern.ex

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
defmodule SpiderMonkey.ArrayPattern do
2+
@type t :: %SpiderMonkey.ArrayPattern{
3+
type: binary,
4+
elements: [SpiderMonkey.Pattern.t | nil]
5+
}
6+
defstruct type: "ArrayPattern",
7+
elements: []
8+
end

lib/spider_monkey/arrow_expression.ex

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
defmodule SpiderMonkey.ArrowExpression do
2+
@type t :: %SpiderMonkey.ArrowExpression{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
params: [SpiderMonkey.Pattern.t],
6+
defaults: [ SpiderMonkey.Expression.t ],
7+
rest: SpiderMonkey.Identifier.t | nil,
8+
body: SpiderMonkey.BlockStatement.t | SpiderMonkey.Expression.t,
9+
generator: boolean,
10+
expression: boolean
11+
}
12+
defstruct type: "ArrowExpression",
13+
loc: nil,
14+
params: [],
15+
defaults: [],
16+
rest: nil,
17+
body: %SpiderMonkey.BlockStatement{},
18+
generator: false,
19+
expression: false
20+
end
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmodule SpiderMonkey.AssignmentExpression do
2+
@type t :: %SpiderMonkey.AssignmentExpression{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
operator: SpiderMonkey.assignment_expression,
6+
left: SpiderMonkey.Pattern.t,
7+
right: SpiderMonkey.Expression.t
8+
}
9+
defstruct type: "AssignmentExpression",
10+
loc: nil,
11+
operator: nil,
12+
left: %SpiderMonkey.EmptyExpression{},
13+
right: %SpiderMonkey.EmptyExpression{}
14+
end
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmodule SpiderMonkey.BinaryExpression do
2+
@type t :: %SpiderMonkey.BinaryExpression{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
operator: SpiderMonkey.binary_expression,
6+
left: SpiderMonkey.Expression.t,
7+
right: SpiderMonkey.Expression.t
8+
}
9+
defstruct type: "BinaryExpression",
10+
loc: nil,
11+
operator: nil,
12+
left: %SpiderMonkey.EmptyExpression{},
13+
right: %SpiderMonkey.EmptyExpression{}
14+
end

lib/spider_monkey/block_statement.ex

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
defmodule SpiderMonkey.BlockStatement do
2+
@type t :: %SpiderMonkey.BlockStatement{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
body: [SpiderMonkey.Statement.t]
6+
}
7+
defstruct type: "BlockStatement", loc: nil, body: []
8+
end

lib/spider_monkey/break_statement.ex

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defmodule SpiderMonkey.BreakStatement do
2+
@type t :: %SpiderMonkey.BreakStatement{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
label: SpiderMonkey.Identifier.t | nil
6+
}
7+
defstruct type: "BreakStatement",
8+
loc: nil,
9+
label: nil
10+
end

lib/spider_monkey/call_expression.ex

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defmodule SpiderMonkey.CallExpression do
2+
@type t :: %SpiderMonkey.CallExpression{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
callee: SpiderMonkey.Expression.t,
6+
arguments: [SpiderMonkey.Expression.t]
7+
}
8+
defstruct type: "CallExpression",
9+
loc: nil,
10+
operator: nil,
11+
callee: %SpiderMonkey.EmptyExpression{},
12+
arguments: []
13+
end

lib/spider_monkey/catch_case.ex

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmodule SpiderMonkey.CatchCase do
2+
@type t :: %SpiderMonkey.CatchCase{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
param: SpiderMonkey.Pattern.t,
6+
guard: SpiderMonkey.Expression.t | nil,
7+
body: SpiderMonkey.BlockStatement
8+
}
9+
defstruct type: "CatchCase",
10+
loc: nil,
11+
param: %SpiderMonkey.EmptyExpression{},
12+
guard: nil,
13+
body: %SpiderMonkey.BlockStatement{}
14+
end
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmodule SpiderMonkey.ComprehensionBlock do
2+
@type t :: %SpiderMonkey.ComprehensionBlock{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
left: SpiderMonkey.Pattern.t,
6+
right: SpiderMonkey.Expression.t,
7+
each: boolean
8+
}
9+
defstruct type: "ComprehensionBlock",
10+
loc: nil,
11+
left: %SpiderMonkey.EmptyExpression{},
12+
right: %SpiderMonkey.EmptyExpression{},
13+
each: false
14+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmodule SpiderMonkey.ComprehensionExpression do
2+
@type t :: %SpiderMonkey.ComprehensionExpression{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
body: SpiderMonkey.Expression.t,
6+
blocks: [SpiderMonkey.ComprehensionBlock.t],
7+
filter: SpiderMonkey.Expression.t | nil,
8+
}
9+
defstruct type: "ComprehensionExpression",
10+
loc: nil,
11+
body: %SpiderMonkey.EmptyExpression{} ,
12+
blocks: [],
13+
filter: nil
14+
end
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmodule SpiderMonkey.ConditionalStatement do
2+
@type t :: %SpiderMonkey.ConditionalStatement{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
test: SpiderMonkey.Expression.t,
6+
alternate: SpiderMonkey.Expression.t,
7+
consequent: SpiderMonkey.Expression.t
8+
}
9+
defstruct type: "ConditionalStatement",
10+
loc: nil,
11+
test: %SpiderMonkey.EmptyExpression{},
12+
alternate: %SpiderMonkey.EmptyExpression{},
13+
consequent: %SpiderMonkey.EmptyExpression{}
14+
end
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defmodule SpiderMonkey.ContinueStatement do
2+
@type t :: %SpiderMonkey.ContinueStatement{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
label: SpiderMonkey.Identifier.t | nil
6+
}
7+
defstruct type: "ContinueStatement",
8+
loc: nil,
9+
label: nil
10+
end
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defmodule SpiderMonkey.DebuggerStatement do
2+
@type t :: %SpiderMonkey.DebuggerStatement{ type: binary, loc: SpiderMonkey.SourceLocation.t | nil }
3+
defstruct type: "DebuggerStatement", loc: nil
4+
end

lib/spider_monkey/declaration.ex

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
defmodule SpiderMonkey.Declaration do
2+
@type t :: SpiderMonkey.FunctionDeclaration.t |
3+
SpiderMonkey.VariableDeclaration.t |
4+
SpiderMonkey.ExpressionStatement.t |
5+
SpiderMonkey.IfStatement.t |
6+
SpiderMonkey.LabeledStatement.t |
7+
SpiderMonkey.BreakStatement.t |
8+
SpiderMonkey.ContinueStatement.t |
9+
SpiderMonkey.WithStatement.t |
10+
SpiderMonkey.SwitchStatement.t |
11+
SpiderMonkey.ReturnStatement.t |
12+
SpiderMonkey.ThrowStatement.t |
13+
SpiderMonkey.TryStatement.t |
14+
SpiderMonkey.WhileStatement.t |
15+
SpiderMonkey.DoWhileStatement.t |
16+
SpiderMonkey.ForStatement.t |
17+
SpiderMonkey.ForInStatement.t |
18+
SpiderMonkey.ForOfStatement.t |
19+
SpiderMonkey.LetStatement.t |
20+
SpiderMonkey.DebuggerStatement.t |
21+
SpiderMonkey.Declaration.t
22+
end
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
defmodule SpiderMonkey.DoWhileStatement do
2+
@type t :: %SpiderMonkey.DoWhileStatement{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
body: SpiderMonkey.Statement.t,
6+
test: SpiderMonkey.Expression.t
7+
}
8+
defstruct type: "DoWhileStatement",
9+
loc: nil,
10+
body: %SpiderMonkey.EmptyStatement{},
11+
test: %SpiderMonkey.EmptyExpression{}
12+
end

lib/spider_monkey/empty_expression.ex

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defmodule SpiderMonkey.EmptyExpression do
2+
@type t :: %SpiderMonkey.EmptyExpression{ type: binary, loc: SpiderMonkey.SourceLocation.t | nil }
3+
defstruct type: "EmptyExpression", loc: nil
4+
end

lib/spider_monkey/empty_statement.ex

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defmodule SpiderMonkey.EmptyStatement do
2+
@type t :: %SpiderMonkey.EmptyStatement{ type: binary, loc: SpiderMonkey.SourceLocation.t | nil }
3+
defstruct type: "EmptyStatement", loc: nil
4+
end

lib/spider_monkey/expression.ex

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
defmodule SpiderMonkey.Expression do
2+
@type t :: SpiderMonkey.ThisExpression.t |
3+
SpiderMonkey.ArrayExpression.t |
4+
SpiderMonkey.ObjectExpression.t |
5+
SpiderMonkey.FunctionExpression.t |
6+
SpiderMonkey.ArrowExpression.t |
7+
SpiderMonkey.SequenceExpression.t |
8+
SpiderMonkey.UnaryExpression.t |
9+
SpiderMonkey.BinaryExpression.t |
10+
SpiderMonkey.AssignmentExpression.t |
11+
SpiderMonkey.UpdateExpression.t |
12+
SpiderMonkey.LogicalExpression.t |
13+
SpiderMonkey.ConditionalExpression.t |
14+
SpiderMonkey.NewExpression.t |
15+
SpiderMonkey.CallExpression.t |
16+
SpiderMonkey.MemberExpression.t |
17+
SpiderMonkey.YieldExpression.t |
18+
SpiderMonkey.ComprehensionExpression.t |
19+
SpiderMonkey.GeneratorExpression.t |
20+
SpiderMonkey.GraphExpression.t |
21+
SpiderMonkey.GraphIndexExpression.t |
22+
SpiderMonkey.LetExpression.t |
23+
SpiderMonkey.Identifier.t |
24+
SpiderMonkey.Literal.t
25+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
defmodule SpiderMonkey.ExpressionStatement do
2+
@type t :: %SpiderMonkey.ExpressionStatement{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
expression: SpiderMonkey.Expression.t
6+
}
7+
defstruct type: "ExpressionStatement", loc: nil, expression: %SpiderMonkey.EmptyExpression{}
8+
end

lib/spider_monkey/for_in_statement.ex

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
defmodule SpiderMonkey.ForInStatement do
2+
@type t :: %SpiderMonkey.ForInStatement{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
left: SpiderMonkey.VariableDeclaration.t | SpiderMonkey.Expression.t ,
6+
right: SpiderMonkey.Expression.t ,
7+
body: SpiderMonkey.Statement.t ,
8+
each: boolean
9+
}
10+
defstruct type: "ForInStatement",
11+
loc: nil,
12+
left: %SpiderMonkey.EmptyExpression{},
13+
right: %SpiderMonkey.EmptyExpression{},
14+
body: %SpiderMonkey.EmptyStatement{},
15+
each: false
16+
end

lib/spider_monkey/for_of_statement.ex

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmodule SpiderMonkey.ForOfStatement do
2+
@type t :: %SpiderMonkey.ForOfStatement{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
left: SpiderMonkey.VariableDeclaration.t | SpiderMonkey.Expression.t ,
6+
right: SpiderMonkey.Expression.t ,
7+
body: SpiderMonkey.Statement.t
8+
}
9+
defstruct type: "ForOfStatement",
10+
loc: nil,
11+
left: %SpiderMonkey.EmptyExpression{},
12+
right: %SpiderMonkey.EmptyExpression{},
13+
body: %SpiderMonkey.EmptyStatement{}
14+
end

lib/spider_monkey/for_statement.ex

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
defmodule SpiderMonkey.ForStatement do
2+
@type t :: %SpiderMonkey.ForStatement{
3+
type: binary,
4+
loc: SpiderMonkey.SourceLocation.t | nil,
5+
init: SpiderMonkey.VariableDeclaration.t | SpiderMonkey.Expression.t | nil,
6+
test: SpiderMonkey.Expression.t | nil,
7+
update: SpiderMonkey.Expression.t | nil,
8+
body: SpiderMonkey.Statement.t
9+
}
10+
defstruct type: "ForStatement",
11+
loc: nil,
12+
init: nil,
13+
test: nil,
14+
update: nil,
15+
body: %SpiderMonkey.EmptyStatement{}
16+
end

0 commit comments

Comments
 (0)