RioChndr / jaksel-language

Jaksel Script, Programming language very modern and Indonesian style
MIT License
926 stars 91 forks source link

fix: fix flexing command #48

Closed hkar19 closed 2 years ago

hkar19 commented 2 years ago

fs.readFileSync in jaksel-interpreter.js will yield different result when run on windows platform. see this stackoverflow answer

we need to replace endline \r\n with \n to accomodate further parsing downstream.

# run on windows
# notice the `\r\n` does not exist in mac or linux. 
{
  inputJaksel: 'literally umur itu 21\r\n' +
    'spill "Umur lu " + umur\r\n' +
    'kalo umur lebih gede 20\r\n' +
    '  spill "Elu tua"\r\n' +
    '  literally umurgua itu umur + 10\r\n' +
    '  spill "Kalo gua umurnya " + umurgua\r\n' +
    '  kalo umurgua lebih gede 30\r\n' +
    '    spill "gua lebih tua"\r\n' +
    '  udahan\r\n' +
    'kalogak\r\n' +
    '  spill "dasar bocil"\r\n' +
    'udahan\r\n' +
    'spill "Udahan ah"'
}
{
  cmdLines: [
    'literally umur itu 21',
    'spill "Umur lu " + umur\r',
    'kalo umur lebih gede 20\r',
    '  spill "Elu tua"\r',
    '  literally umurgua itu umur + 10\r',
    '  spill "Kalo gua umurnya " + umurgua\r',
    '  kalo umurgua lebih gede 30\r',
    '    spill "gua lebih tua"\r',
    '  udahan\r',
    'kalogak\r',
    '  spill "dasar bocil"\r',
    'udahan\r',
    'spill "Udahan ah"'
  ],
  cmds: [
    { exp: 'let umur = 21;' },
    { exp: 'console.log("Umur lu " + umur);' },
    { exp: 'if (umur  >  20\r)', openGroup: true },
    { exp: 'console.log("Elu tua");' },
    { exp: 'let umurgua = umur + 10\r;' },
    { exp: 'console.log("Kalo gua umurnya " + umurgua);' },
    { exp: 'if (umurgua  >  30\r)', openGroup: true },
    { exp: 'console.log("gua lebih tua");' },
    { exp: 'console.log("dasar bocil");' },
    { exp: 'console.log("Udahan ah");' }
  ],
  input: 'literally umur itu 21\r\n' +
    'spill "Umur lu " + umur\r\n' +
    'kalo umur lebih gede 20\r\n' +
    '  spill "Elu tua"\r\n' +
    '  literally umurgua itu umur + 10\r\n' +
    '  spill "Kalo gua umurnya " + umurgua\r\n' +
    '  kalo umurgua lebih gede 30\r\n' +
    '    spill "gua lebih tua"\r\n' +
    '  udahan\r\n' +
    'kalogak\r\n' +
    '  spill "dasar bocil"\r\n' +
    'udahan\r\n' +
    'spill "Udahan ah"',
}
RioChndr commented 2 years ago

Nice fix !, Thank you.