aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorache <ache@ache.one>2018-04-24 05:36:34 +0200
committerache <ache@ache.one>2018-04-24 06:03:09 +0200
commit85f2579ee2c240794294c15d61418f448054f71b (patch)
treea9b518c1625f554746323794da34f8f5a007fec4 /src
parentUse babel to distribut (diff)
Compatibility work
Diffstat (limited to 'src')
-rw-r--r--src/index.js40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/index.js b/src/index.js
index 9992704..3e123dc 100644
--- a/src/index.js
+++ b/src/index.js
@@ -2,7 +2,7 @@
// A valid output which mean nothing has been parsed.
// Used as error return / invalid output
-const nothingHappend = {
+var nothingHappend = {
prop: {
key: undefined,
class: undefined,
@@ -12,18 +12,22 @@ const nothingHappend = {
};
// Main function
-function parse(value, indexNext = 0) {
- let letsEat = '';
- let stopOnBrace = false;
- let errorDetected = false;
+function parse(value, indexNext) {
+ var letsEat = '';
+ var stopOnBrace = false;
+ var errorDetected = false;
- const prop = {key: undefined /* {} */, class: undefined /* [] */, id: undefined};
+ var prop = {key: undefined /* {} */, class: undefined /* [] */, id: undefined};
/* They is at leat one label and at best two */
/* ekqsdf <- one label
* qsdfqsfd=qsdfqsdf <- two */
- let labelFirst = '';
- let labelSecond;
+ var labelFirst = '';
+ var labelSecond;
+
+ if (indexNext === undefined) {
+ indexNext = 0;
+ }
/* 3 types :
* .azcv <- class
@@ -32,11 +36,11 @@ function parse(value, indexNext = 0) {
* jkj <- this is also a key but with a undefined value
* jkj= <- this is also a key but with a empty value
*/
- let type;
- const forbidenCharacters = '\n\r{}';
+ var type;
+ var forbidenCharacters = '\n\r{}';
// A function that detect if it's time to end the parsing
- const shouldStop = () => {
+ var shouldStop = function () {
if (indexNext >= value.length || forbidenCharacters.indexOf(value[indexNext]) > -1) {
if (stopOnBrace && value[indexNext] !== '}') {
errorDetected = true;
@@ -46,10 +50,10 @@ function parse(value, indexNext = 0) {
return value[indexNext] === '}' && stopOnBrace;
};
- let eaten = '';
+ var eaten = '';
// Couple of functions that parse same kinds of characters
// Used to parse spaces or identifiers
- const eat = chars => {
+ var eat = function (chars) {
eaten = '';
while (indexNext < value.length &&
@@ -62,7 +66,7 @@ function parse(value, indexNext = 0) {
return shouldStop();
};
- const eatUntil = chars => {
+ var eatUntil = function (chars) {
eaten = '';
while (indexNext < value.length &&
@@ -86,7 +90,7 @@ function parse(value, indexNext = 0) {
// In quote, every character is valid exept the unescaped quotes and CR or LF
// Same function for single and double quote
- const eatInQuote = quote => {
+ var eatInQuote = function (quote) {
eaten = '';
// First check so value[indexNext-1] will always be valid
if (value[indexNext] === quote) {
@@ -118,7 +122,7 @@ function parse(value, indexNext = 0) {
};
// It's realy commun to eat only one character so let's make it a function
- const eatOne = c => {
+ var eatOne = function (c) {
// Miam !
letsEat += c;
indexNext++;
@@ -126,7 +130,7 @@ function parse(value, indexNext = 0) {
return shouldStop();
};
- const addAttribute = () => {
+ var addAttribute = function () {
switch (type) {
case 'id': // ID
prop.id = prop.id || labelFirst;
@@ -249,7 +253,7 @@ function parse(value, indexNext = 0) {
return nothingHappend;
}
- return {prop, eaten: letsEat};
+ return {prop: prop, eaten: letsEat};
}
module.exports = parse;