-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
631 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
node_modules | ||
refs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(function(global){ | ||
|
||
var parser = fastparser; | ||
var JSONFast = { | ||
parse: function(str){ | ||
if(parser.parse(str)){ | ||
return parser.$$; | ||
}else{ | ||
return {}; | ||
} | ||
}, | ||
stringify: function(){ | ||
} | ||
}; | ||
|
||
global.JSONFast = JSONFast; | ||
|
||
|
||
})(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
var fs = require('fs'); | ||
|
||
var Generator = require('jsbison'); | ||
|
||
Generator.lexParser.parse(fs.readFileSync('./json.l').toString()); | ||
|
||
|
||
Generator.bnfParser.parse(fs.readFileSync('./json.y').toString()); | ||
|
||
var bnfcfg = Generator.bnfParser.$$; | ||
bnfcfg.lex = Generator.lexParser.$$; | ||
bnfcfg.type = 'LR(1)'; | ||
|
||
|
||
debugger | ||
var generator = new Generator(bnfcfg); | ||
|
||
var code = generator.generate(); | ||
|
||
|
||
fs.writeFileSync('./parser.js', code); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
%% | ||
|
||
\/\/[^\n]* /* skip singleline comment */ | ||
\/\*(.|\n|\r)*?\*\/ /* skip multiline comment */ | ||
"(?:\\[bfnrt\/"]|\\u[a-fA-F0-9]{4}|[^"\\])*" this.yytext=this.yytext.slice(1, this.yyleng-1);return "STRING"; | ||
\s+ | ||
\r\n | ||
((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([eE][+-]?[0-9]+)?|[0][xX][0-9a-fA-F]+ return "NUMBER" | ||
null return "NULL"; | ||
true return "TRUE"; | ||
false return "FALSE"; | ||
: return ":"; | ||
, return ","; | ||
\[ return "["; | ||
\] return "]"; | ||
\{ return "{"; | ||
\} return "}"; | ||
\s+ /* skip whitespace */ | ||
\n /* skip lineterminal */ | ||
. return "INVALID"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
%start Json | ||
%% | ||
|
||
Json : | ||
JsonValue $end | ||
{ | ||
this.$$ = $1; | ||
} | ||
; | ||
|
||
JsonValue : | ||
NULL | ||
{ | ||
this.$$ = null; | ||
} | ||
| BooleanLiteral | ||
{ | ||
this.$$ = $1; | ||
} | ||
| STRING | ||
{ | ||
this.$$ = $1; | ||
} | ||
| NUMBER | ||
{ | ||
this.$$ = parseFloat($1); | ||
} | ||
| JSONObject | ||
{ | ||
this.$$ = $1; | ||
} | ||
| JSONArray | ||
{ | ||
this.$$ = $1; | ||
} | ||
; | ||
|
||
BooleanLiteral : | ||
TRUE | ||
{ | ||
this.$$ = true; | ||
} | ||
| FALSE | ||
{ | ||
this.$$ = false; | ||
} | ||
; | ||
|
||
JSONObject : | ||
{ } | ||
{ | ||
this.$$ = {}; | ||
} | ||
| { JSONMemberList } | ||
{ | ||
this.$$ = $2; | ||
} | ||
; | ||
|
||
JSONMemberList : | ||
JSONMemberList , JSONMember | ||
{ | ||
this.$$ = $1; | ||
this.$$ = _.merge(this.$$, $3); | ||
} | ||
| JSONMember | ||
{ | ||
this.$$ = $1; | ||
} | ||
; | ||
JSONMember : | ||
STRING : JsonValue | ||
{ | ||
this.$$ = {}; | ||
this.$$[$1] = $3; | ||
} | ||
; | ||
|
||
JSONArray : | ||
[ ] | ||
{ | ||
this.$$ = []; | ||
} | ||
| [ JSONElementList ] | ||
{ | ||
this.$$ = $2; | ||
} | ||
; | ||
JSONElementList: | ||
JSONElementList , JsonValue | ||
{ | ||
this.$$ = $1; | ||
this.$$.push($3); | ||
} | ||
| JsonValue | ||
{ | ||
this.$$ = [$1]; | ||
} | ||
; | ||
|
||
|
||
|
||
%% | ||
|
||
global.fastparser = parser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "JSONFast", | ||
"description": "基于jsbison生成的JSON的快速解析器。", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/takumi4ichi/JSONFast", | ||
"author": { | ||
"name": "takumi4ichi", | ||
"email": "[email protected]" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:takumi4ichi/jsonfast.git" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "/blob/master/LICENSE" | ||
} | ||
], | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
"devDependencies": { | ||
"grunt": "~0.4.1", | ||
"grunt-contrib-clean": "~0.5.0", | ||
"grunt-contrib-copy": "~0.4.1", | ||
"grunt-contrib-uglify": "~0.2.0", | ||
"grunt-contrib-watch": "~0.4.0", | ||
"grunt-contrib-jshint": "~0.10.0", | ||
"jsbison": "~0.1.8" | ||
}, | ||
"dependencies": { | ||
"lodash": "^2.4.1" | ||
}, | ||
"keywords": [ | ||
"lib", | ||
"parser", | ||
"javascript", | ||
"json" | ||
] | ||
} |
Oops, something went wrong.