Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Split the ParseDict library into a source file as well.

  • Loading branch information...
commit 0ff8bfb9be7a28ce8f9a895af2b2036275d18f0b 1 parent 1a584ec
@jpedrosa authored
Showing with 153 additions and 151 deletions.
  1. +1 −151 parsedict/lib/parsedict.dart
  2. +152 −0 parsedict/lib/parsedict/parsedict.dart
View
152 parsedict/lib/parsedict.dart
@@ -1,153 +1,3 @@
#library("parsedict");
-// Copyright (c) 2012 Joao Pedrosa
-
-
-class ParseDict {
-
- static parse(s) {
- var dict = {}, i = -1, mirror = s.charCodes(), len = mirror.length, c, k,
- lookingFor = 0, tokenType = 50, token, lineCount = 1, lineMark = -1;
- invalidInput() {
- var j = lineMark + 1,
- line = j <= i ?
- new String.fromCharCodes(mirror.getRange(
- j, i - j + 1)) : '',
- llen = line.length,
- lastChars = llen > 5 ? line.substring(llen - 5, llen) : line;
- throw "Exception: Invalid input. Stopped at line# ${lineCount}, " +
- "column# ${llen}: => ${lastChars}";
- }
- while (true) {
- if (c === null) {
- i += 1;
- if (i < len) {
- c = mirror[i];
- } else if (tokenType == 100) {
- break; // done parsing.
- } else {
- invalidInput();
- }
- }
- switch (lookingFor) {
- case 0: // spaces
- switch (c) {
- case 32: // space
- case 9: // \t
- case 10: // \n
- case 13: // \r
- if (c == 10) {
- lineCount += 1;
- lineMark = i;
- }
- c = null;
- break;
- default:
- lookingFor = tokenType;
- }
- break;
- case 1: // not '
- switch (c) {
- case 39: // '
- lookingFor = tokenType;
- break;
- case 92: // \
- if (i + 1 < len) {
- token.add(mirror[i + 1]);
- i += 1;
- c = null;
- } else {
- invalidInput();
- }
- break;
- default:
- token.add(c);
- c = null;
- }
- break;
- case 50:
- if (c == 123) { // {
- tokenType = 51;
- lookingFor = 0;
- c = null;
- } else {
- invalidInput();
- }
- break;
- case 51:
- switch (c) {
- case 39: // '
- tokenType = 52;
- lookingFor = 1;
- c = null;
- token = [];
- break;
- case 125: // }
- lookingFor = 56;
- break;
- default:
- invalidInput();
- }
- break;
- case 52: // close string with a '
- k = token;
- tokenType = 53;
- lookingFor = 0;
- c = null;
- break;
- case 53:
- if (c == 58) { // :
- tokenType = 54;
- lookingFor = 0;
- c = null;
- } else {
- invalidInput();
- }
- break;
- case 54:
- if (c == 39) { // '
- token = [];
- tokenType = 55;
- lookingFor = 1;
- c = null;
- } else {
- invalidInput();
- }
- break;
- case 55: // close string with a '
- dict[new String.fromCharCodes(k)] = new String.fromCharCodes(token);
- tokenType = 56;
- lookingFor = 0;
- c = null;
- break;
- case 56:
- switch (c) {
- case 44: // ,
- tokenType = 51;
- lookingFor = 0;
- c = null;
- break;
- case 125: // }
- tokenType = 100;
- lookingFor = 0;
- c = null;
- break;
- default:
- invalidInput();
- }
- break;
- case 100:
- invalidInput();
- }
- }
- return dict;
- }
-
-}
-
-
-
-
-
-
-
+#source("parsedict/parsedict.dart");
View
152 parsedict/lib/parsedict/parsedict.dart
@@ -0,0 +1,152 @@
+// Copyright (c) 2012 Joao Pedrosa
+
+
+class ParseDict {
+
+ static parse(s) {
+ var dict = {}, i = -1, mirror = s.charCodes(), len = mirror.length, c, k,
+ lookingFor = 0, tokenType = 50, token, lineCount = 1, lineMark = -1;
+ invalidInput() {
+ var j = lineMark + 1,
+ line = j <= i ?
+ new String.fromCharCodes(mirror.getRange(
+ j, i - j + 1)) : '',
+ llen = line.length,
+ lastChars = llen > 5 ? line.substring(llen - 5, llen) : line;
+ throw "Exception: Invalid input. Stopped at line# ${lineCount}, " +
+ "column# ${llen}: => ${lastChars}";
+ }
+ while (true) {
+ if (c === null) {
+ i += 1;
+ if (i < len) {
+ c = mirror[i];
+ } else if (tokenType == 100) {
+ break; // done parsing.
+ } else {
+ invalidInput();
+ }
+ }
+ switch (lookingFor) {
+ case 0: // spaces
+ switch (c) {
+ case 32: // space
+ case 9: // \t
+ case 10: // \n
+ case 13: // \r
+ if (c == 10) {
+ lineCount += 1;
+ lineMark = i;
+ }
+ c = null;
+ break;
+ default:
+ lookingFor = tokenType;
+ }
+ break;
+ case 1: // not '
+ switch (c) {
+ case 39: // '
+ lookingFor = tokenType;
+ break;
+ case 92: // \
+ if (i + 1 < len) {
+ token.add(mirror[i + 1]);
+ i += 1;
+ c = null;
+ } else {
+ invalidInput();
+ }
+ break;
+ default:
+ token.add(c);
+ c = null;
+ }
+ break;
+ case 50:
+ if (c == 123) { // {
+ tokenType = 51;
+ lookingFor = 0;
+ c = null;
+ } else {
+ invalidInput();
+ }
+ break;
+ case 51:
+ switch (c) {
+ case 39: // '
+ tokenType = 52;
+ lookingFor = 1;
+ c = null;
+ token = [];
+ break;
+ case 125: // }
+ lookingFor = 56;
+ break;
+ default:
+ invalidInput();
+ }
+ break;
+ case 52: // close string with a '
+ k = token;
+ tokenType = 53;
+ lookingFor = 0;
+ c = null;
+ break;
+ case 53:
+ if (c == 58) { // :
+ tokenType = 54;
+ lookingFor = 0;
+ c = null;
+ } else {
+ invalidInput();
+ }
+ break;
+ case 54:
+ if (c == 39) { // '
+ token = [];
+ tokenType = 55;
+ lookingFor = 1;
+ c = null;
+ } else {
+ invalidInput();
+ }
+ break;
+ case 55: // close string with a '
+ dict[new String.fromCharCodes(k)] = new String.fromCharCodes(token);
+ tokenType = 56;
+ lookingFor = 0;
+ c = null;
+ break;
+ case 56:
+ switch (c) {
+ case 44: // ,
+ tokenType = 51;
+ lookingFor = 0;
+ c = null;
+ break;
+ case 125: // }
+ tokenType = 100;
+ lookingFor = 0;
+ c = null;
+ break;
+ default:
+ invalidInput();
+ }
+ break;
+ case 100:
+ invalidInput();
+ }
+ }
+ return dict;
+ }
+
+}
+
+
+
+
+
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.