-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use jison and not hand rolled parsing
- Loading branch information
1 parent
833015e
commit 4c7ece2
Showing
14 changed files
with
417 additions
and
1,188 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/ | ||
coverage/ | ||
lib/jomini.js |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
var jomini = require('./'); | ||
var JS = require('json3'); | ||
var header = new jomini.Header({header: 'EU4txt'}); | ||
var parser = new jomini.Parser(); | ||
process.stdin.pipe(header).pipe(parser); | ||
parser.on('finish', function() { | ||
process.stdout.write(JS.stringify(parser.obj), 'utf8', function() {}); | ||
}); | ||
var concat = require('concat-stream'); | ||
var concatStream = concat(function(buf) { | ||
var str = buf.toString('utf8'); | ||
var obj = jomini.parse(str); | ||
process.stdout.write(JS.stringify(obj)); | ||
}); | ||
|
||
process.stdin.pipe(concatStream) |
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
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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
exports = module.exports; | ||
exports.Parser = require('./lib/parser'); | ||
exports.Header = require('./lib/header'); | ||
exports.parse = require('./lib/parse'); | ||
exports.parse = require('./lib/jomini').parser.parse; | ||
exports.toArray = require('./lib/toArray'); | ||
exports.toDate = require('./lib/toDate'); | ||
exports.toBool = require('./lib/toBool'); |
This file was deleted.
Oops, something went wrong.
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,86 @@ | ||
%{ | ||
var toDate = require('./toDate'); | ||
var setProp = require('./setProp'); | ||
%} | ||
|
||
/* lexical grammar */ | ||
%lex | ||
%% | ||
|
||
\s+ /* skip whitespace */ | ||
"yes"\b return 'BOOL' | ||
"no"\b return 'BOOL' | ||
[0-9]+"."[0-9]+"."[0-9]+\b return 'DATE' | ||
'"'[0-9]+"."[0-9]+"."[0-9]+'"' yytext = yytext.substr(1,yyleng-2); return 'QDATE' | ||
"-"?[0-9]+("."[0-9]+)?\b return 'NUMBER' | ||
"{" return '{' | ||
"}" return '}' | ||
"=" return '=' | ||
\"[^\"]*\" yytext = yytext.substr(1,yyleng-2); return 'QIDENTIFIER' | ||
[a-zA-Z0-9_]+ return 'IDENTIFIER' | ||
"#"[^\r\n]*((\r\n)|<<EOF>>) /* skip comments */ | ||
. return 'INVALID' | ||
<<EOF>> return 'EOF' | ||
|
||
|
||
/lex | ||
|
||
%start expressions | ||
|
||
%% /* language grammar */ | ||
|
||
expressions | ||
: PMemberList EOF | ||
{ return obj; } | ||
| IDENTIFIER PMemberList EOF | ||
{ return obj; } | ||
; | ||
|
||
PMemberList | ||
: PMember | ||
{if(key) {nest.push(obj); obj = {}; setProp(obj, key, value);}} | ||
| PMemberList PMember | ||
{if (key) {setProp(obj, key, value);}} | ||
; | ||
|
||
PMember | ||
: IDENTIFIER '=' PValue | ||
{key = $1; value = $3;} | ||
| DATE '=' PValue | ||
{key = $1; value = $3;} | ||
| IDENTIFIER '=' '{' '}' | ||
{key = $1; value = {};} | ||
| '{' '}' | ||
{key = undefined;} | ||
; | ||
|
||
PList | ||
: PValue | ||
{nest.push(obj); obj = [$1];} | ||
| PList PValue | ||
{obj.push($2);} | ||
; | ||
|
||
PValue | ||
: NUMBER | ||
{$$ = +yytext;} | ||
| BOOL | ||
{$$ = yytext === 'yes';} | ||
| QIDENTIFIER | ||
{$$ = yytext;} | ||
| IDENTIFIER | ||
{$$ = yytext;} | ||
| DATE | ||
{$$ = toDate(yytext);} | ||
| QDATE | ||
{$$ = toDate(yytext);} | ||
| '{' PMemberList '}' | ||
{$$ = obj; obj = nest.pop();} | ||
| '{' PList '}' | ||
{$$ = obj; obj = nest.pop();} | ||
; | ||
|
||
%% | ||
nest = []; | ||
obj = {}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.