Skip to content

Commit

Permalink
v0.1.0: add all core functionalities
Browse files Browse the repository at this point in the history
  • Loading branch information
vipranarayan14 committed Aug 9, 2022
1 parent 64bad9e commit 0999c12
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 49 deletions.
48 changes: 25 additions & 23 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ class $3aefcdddac337967$export$50792b0e93539fde {
constructor(type, value, pos, attributes){
this.type = type;
this.value = value;
this.from = pos - (value.length - 1);
this.to = pos;
this.from = pos;
this.to = pos + (value.length - 1);
this.attributes = attributes;
}
}
Expand All @@ -216,49 +216,51 @@ class $3aefcdddac337967$export$50792b0e93539fde {
let $882b6d93070905b3$var$State;
(function(State) {
State[State["Initial"] = 0] = "Initial";
State[State[// Symbol,
"Vowel"] = 1] = "Vowel";
State[State["Vowel"] = 1] = "Vowel";
State[State["Consonant"] = 2] = "Consonant";
State[State["ConjunctConsonant"] = 3] = "ConjunctConsonant";
})($882b6d93070905b3$var$State || ($882b6d93070905b3$var$State = {}));
const $882b6d93070905b3$var$tokenize = (input)=>{
const tokens = [];
let pos = 0;
let acc = "";
let varnasLength = 0;
let state = $882b6d93070905b3$var$State.Initial;
const resetVariables = ()=>{
pos = 0;
acc = "";
varnasLength = 0;
state = $882b6d93070905b3$var$State.Initial;
};
const createToken = (tokenType, value, pos, attributes)=>{
tokens.push(new (0, $3aefcdddac337967$export$50792b0e93539fde)(tokenType, value, pos, attributes));
const createToken = (tokenType, attributes)=>{
tokens.push(new (0, $3aefcdddac337967$export$50792b0e93539fde)(tokenType, acc, pos, attributes));
resetVariables();
};
for(let pos = 0; pos < input.length; pos += 1){
const char = new (0, $823e42faaa542640$export$3ae2e3e9a9c21123)(input[pos]);
const nextChar = new (0, $823e42faaa542640$export$3ae2e3e9a9c21123)(input[pos + 1]);
for(let i = 0, l = input.length; i < l; i += 1){
const char = new (0, $823e42faaa542640$export$3ae2e3e9a9c21123)(input[i]);
const nextChar = new (0, $823e42faaa542640$export$3ae2e3e9a9c21123)(input[i + 1]);
acc += char.value;
switch(state){
case $882b6d93070905b3$var$State.Initial:
pos = i;
if (char.isSymbol()) {
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Symbol, acc, pos);
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Symbol);
break;
}
if (char.isWhitespace()) {
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Whitespace, acc, pos);
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Whitespace);
break;
}
if (char.isUnrecognised()) {
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Unrecognised, acc, pos);
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Unrecognised);
break;
}
if (char.isVowel()) {
if (nextChar.isVowelAttachment()) {
state = $882b6d93070905b3$var$State.Vowel;
break;
}
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, acc, pos, {
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, {
varnasLength: 1
});
break;
Expand All @@ -269,23 +271,23 @@ const $882b6d93070905b3$var$tokenize = (input)=>{
state = $882b6d93070905b3$var$State.Consonant;
break;
}
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, acc, pos, {
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, {
varnasLength: 2
});
break;
}
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Invalid, acc, pos);
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Invalid);
break;
case $882b6d93070905b3$var$State.Vowel:
if (char.isAccent()) {
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, acc, pos, {
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, {
varnasLength: 1
});
break;
}
if (char.isYogavaha()) {
if (nextChar.isAccent()) break;
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, acc, pos, {
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, {
varnasLength: 1
});
break;
Expand All @@ -294,7 +296,7 @@ const $882b6d93070905b3$var$tokenize = (input)=>{
case $882b6d93070905b3$var$State.Consonant:
if (char.isNukta()) {
if (nextChar.isConsonantAttachment()) break;
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, acc, pos, {
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, {
varnasLength: 2
});
break;
Expand All @@ -305,7 +307,7 @@ const $882b6d93070905b3$var$tokenize = (input)=>{
state = $882b6d93070905b3$var$State.ConjunctConsonant;
break;
}
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, acc, pos, {
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, {
varnasLength: varnasLength
});
break;
Expand All @@ -316,23 +318,23 @@ const $882b6d93070905b3$var$tokenize = (input)=>{
state = $882b6d93070905b3$var$State.ConjunctConsonant;
break;
}
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, acc, pos, {
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, {
varnasLength: varnasLength
});
break;
}
if (char.isVowelMarkAttachment()) {
varnasLength += 1;
if (nextChar.isAccent()) break;
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, acc, pos, {
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, {
varnasLength: varnasLength
});
break;
}
if (char.isVowelMark()) {
if (nextChar.isVowelMarkAttachment()) break;
varnasLength += 1;
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, acc, pos, {
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, {
varnasLength: varnasLength
});
break;
Expand All @@ -344,7 +346,7 @@ const $882b6d93070905b3$var$tokenize = (input)=>{
break;
}
varnasLength += 2;
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, acc, pos, {
createToken((0, $3aefcdddac337967$export$f435f793048e7a0f).Akshara, {
varnasLength: varnasLength
});
break;
Expand Down
Loading

0 comments on commit 0999c12

Please sign in to comment.