Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring #28

Merged
merged 1 commit into from
May 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
568 changes: 247 additions & 321 deletions build/scscript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scscript",
"version": "0.0.19",
"version": "0.0.20",
"author": "Nao Yonamine <mohayonao@gmail.com>",
"homepage": "http://mohayonao.github.io/SCScript/",
"bugs": "https://github.com/mohayonao/SCScript/issues",
Expand Down
4 changes: 2 additions & 2 deletions src/sc/lang/compiler/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
yield: true
};

var Scope = sc.lang.compiler.Scope({
var Scope = sc.lang.compiler.scope({
add_delegate: function(stmt, id, indent, peek, scope) {
if (stmt.vars.length === 0) {
this._addNewVariableStatement(stmt, id, indent);
Expand Down Expand Up @@ -807,6 +807,6 @@
return new CodeGen(opts).generate(ast);
};

sc.lang.codegen = codegen;
sc.lang.compiler.codegen = codegen;

})(sc);
6 changes: 3 additions & 3 deletions src/sc/lang/compiler/codegen_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"use strict";

require("./codegen");
require("./compiler_test");
require("./test-cases");

var codegen = sc.lang.codegen;
var codegen = sc.lang.compiler.codegen;
var Syntax = sc.lang.compiler.Syntax;
var Token = sc.lang.compiler.Message;

describe("sc.lang.codegen", function() {
describe("sc.lang.compiler.codegen", function() {
function s(str) {
str = JSON.stringify(str);
return '"' + str.substr(1, str.length - 2) + '"';
Expand Down
127 changes: 59 additions & 68 deletions src/sc/lang/compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,87 +3,78 @@

require("./sc");

var compiler = {};

compiler.Token = {
CharLiteral: "Char",
EOF: "<EOF>",
FalseLiteral: "False",
FloatLiteral: "Float",
Identifier: "Identifier",
IntegerLiteral: "Integer",
Keyword: "Keyword",
Label: "Label",
NilLiteral: "Nil",
Punctuator: "Punctuator",
StringLiteral: "String",
SymbolLiteral: "Symbol",
TrueLiteral: "True"
};

compiler.Syntax = {
AssignmentExpression: "AssignmentExpression",
BinaryExpression: "BinaryExpression",
BlockExpression: "BlockExpression",
CallExpression: "CallExpression",
FunctionExpression: "FunctionExpression",
GlobalExpression: "GlobalExpression",
Identifier: "Identifier",
ListExpression: "ListExpression",
Label: "Label",
Literal: "Literal",
ObjectExpression: "ObjectExpression",
Program: "Program",
ThisExpression: "ThisExpression",
UnaryExpression: "UnaryExpression",
VariableDeclaration: "VariableDeclaration",
VariableDeclarator: "VariableDeclarator"
};

compiler.Message = {
ArgumentAlreadyDeclared: "argument '%0' already declared",
InvalidLHSInAssignment: "invalid left-hand side in assignment",
NotImplemented: "not implemented %0",
UnexpectedEOS: "unexpected end of input",
UnexpectedIdentifier: "unexpected identifier",
UnexpectedChar: "unexpected char",
UnexpectedLabel: "unexpected label",
UnexpectedNumber: "unexpected number",
UnexpectedString: "unexpected string",
UnexpectedSymbol: "unexpected symbol",
UnexpectedToken: "unexpected token %0",
VariableAlreadyDeclared: "variable '%0' already declared",
VariableNotDefined: "variable '%0' not defined"
};

compiler.Keywords = {
var: "keyword",
arg: "keyword",
const: "keyword",
this: "function",
thisThread: "function",
thisProcess: "function",
thisFunction: "function",
thisFunctionDef: "function",
var compiler = {
Token: {
CharLiteral: "Char",
EOF: "<EOF>",
FalseLiteral: "False",
FloatLiteral: "Float",
Identifier: "Identifier",
IntegerLiteral: "Integer",
Keyword: "Keyword",
Label: "Label",
NilLiteral: "Nil",
Punctuator: "Punctuator",
StringLiteral: "String",
SymbolLiteral: "Symbol",
TrueLiteral: "True"
},
Syntax: {
AssignmentExpression: "AssignmentExpression",
BinaryExpression: "BinaryExpression",
BlockExpression: "BlockExpression",
CallExpression: "CallExpression",
FunctionExpression: "FunctionExpression",
GlobalExpression: "GlobalExpression",
Identifier: "Identifier",
ListExpression: "ListExpression",
Label: "Label",
Literal: "Literal",
ObjectExpression: "ObjectExpression",
Program: "Program",
ThisExpression: "ThisExpression",
UnaryExpression: "UnaryExpression",
VariableDeclaration: "VariableDeclaration",
VariableDeclarator: "VariableDeclarator"
},
Message: {
ArgumentAlreadyDeclared: "argument '%0' already declared",
InvalidLHSInAssignment: "invalid left-hand side in assignment",
NotImplemented: "not implemented %0",
UnexpectedEOS: "unexpected end of input",
UnexpectedIdentifier: "unexpected identifier",
UnexpectedNumber: "unexpected number",
UnexpectedLiteral: "unexpected %0",
UnexpectedToken: "unexpected token %0",
VariableAlreadyDeclared: "variable '%0' already declared",
VariableNotDefined: "variable '%0' not defined"
},
Keywords: {
var: "keyword",
arg: "keyword",
const: "keyword",
this: "function",
thisThread: "function",
thisProcess: "function",
thisFunction: "function",
thisFunctionDef: "function",
}
};

sc.lang.compiler = compiler;

var SCScript = sc.SCScript;

SCScript.tokenize = function(source, opts) {
opts = opts || /* istanbul ignore next */ {};
opts.tokens = true;
return sc.lang.parser.parse(source, opts).tokens || /* istanbul ignore next */ [];
return new compiler.lexer(source, opts).tokenize();
};

SCScript.parse = function(source, opts) {
return sc.lang.parser.parse(source, opts);
return compiler.parser.parse(source, opts);
};

SCScript.compile = function(source, opts) {
var ast = SCScript.parse(source, opts);
return sc.lang.codegen.compile(ast, opts);
return compiler.codegen.compile(SCScript.parse(source, opts), opts);
};

})(sc);
Loading