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

Fixed issue with multiple levels of json objects #104

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"dependencies": {
"angular": "~1.x",
"jquery": "2.x",
"jquery-ui": "latest"
"jquery-ui": "latest",
"jison":"git://github.com/zaach/jison.git"
},
"devDependencies": {
"angular-mocks": "~1.x"
Expand Down
10 changes: 10 additions & 0 deletions lexersrc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
These files generate the Parser.js found in the main source of this repo. The parser was generated using a tool called jison which can be found <a href="https://github.com/zaach/jison">here<a>. Currently the primary purpose of the parser is to add the ability to parse json arguments to the drag and drop callbacks.

##Changing the parser.

If you need to make changes to the parser you can update the parser.lex and the parser.y files then use jison to generate the Parser.js file.The command should look like this:

node_modules/.bin/jison lexersrc/parser.y lexersrc/parser.lex --outfile src/Parser.js

This will generate a javascript parsing engine in the src/Parser.js file, based on your two grammar files.

69 changes: 69 additions & 0 deletions lexersrc/parser.lex
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
%{
/* Note for future hackers */
/* Jison by default gets the first matched item, working top down
* This is NOT the same as lex, which matches longest
* Adding the %option flex to the file will make jison work like lex
* but, this is not heavily tested
*
* The safest thing to do is have more important rules before less
* important rules, which is why . is last
*/
%}
int "-"?([0-9]|[1-9][0-9]+)
exp [eE][-+]?[0-9]+
frac "."[0-9]+

%x json singleQuoteString dblQuoteString
%flex
%%

[^{,][^,]+ return 'LITERAL';
"{" {
saver.currText = "{";
this.begin('json');
}
"," {
// do nothing we don't want commas
}
<<EOF>> return 'EOF';

<json>"}" {
saver.currText = saver.currText + yytext;
if (saver.braceCount == 0) {
yytext = saver.currText;
saver.currText = "";
this.popState();
return 'JSON';
}
else {
saver.braceCount -= 1;
}
}
<json>"{" {
saver.currText = saver.currText + yytext;
saver.braceCount += 1;
}
<json><<EOF>> {
yytext = saver.currText;
saver.currText = "";
this.popState();
return 'EOF';
}
<json>\s+ { saver.currText = saver.currText + yytext; }
<json>"'" { saver.currText = saver.currText + yytext; this.begin('singleQuoteString'); }
<json>\" { saver.currText = saver.currText + yytext; this.begin('dblQuoteString'); }
<json>"//" { this.begin('singleLineComment'); }
<json>"/*" { this.begin('multiLineComment'); }
<json>. { saver.currText = saver.currText + yytext; }

<singleQuoteString>"\'" { saver.currText = saver.currText + yytext; }
<singleQuoteString>"'" { saver.currText = saver.currText + yytext; this.popState(); }
<singleQuoteString>. { saver.currText = saver.currText + yytext; }

<dblQuoteString>"\\\"" { saver.currText = saver.currText + yytext; }
<dblQuoteString>\" { saver.currText = saver.currText + yytext; this.popState(); }
<dblQuoteString>. { saver.currText = saver.currText + yytext; }

%%

var saver = { currText: "", braceCount:0 }
53 changes: 53 additions & 0 deletions lexersrc/parser.y
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
%start parsedargs

%{

%}

%%

parsedargs
: EOF
{
$$ = [undefined];
return $$
}
| arguments EOF
{
$$ = $1;
return $$;
}
;
arguments
: stringarg
{
$$ = [$1];
}
| JSON
{
$$ = [$1];
}
| arguments stringarg
{
$1.push($2);
$$ = $1;
}
| arguments JSON
{
$1.push($2)
$$ = $1;
}
;

stringarg
: LITERAL
{
$$ = $1;
}
| LITERAL stringarg
{
$$ = $1 + $2;
}
;

%%
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
"license": "MIT",
"homepage": "http://codef0rmer.github.io/angular-dragdrop",
"main": "src/angular-dragdrop.js",
"dependencies": {},
"dependencies": {
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-karma": "~0.4.4"
"grunt-karma": "~0.4.4",
"jison":"*"
},
"scripts": {},
"repository": {
Expand Down
Loading