DulLabs / bhai-lang

A toy programming language written in Typescript
https://bhailang.js.org/
MIT License
3.97k stars 499 forks source link

fix: bhaiLangSpec - fixed sahi and galat regex #207

Closed Nikhil216 closed 2 years ago

Nikhil216 commented 2 years ago

Tasks

Context

Try this code in bhai lang playground

hi bhai
  bhai ye hai sahiValue = sahi;
  bhai ye hai galatValue = 10;
bye bhai

Now bhai is mad because he thinks sahiValue is the literal boolean value sahi and not as an identifier. Same thing occurs with galat These line in the spec are to blame https://github.com/DulLabs/bhai-lang/blob/10e6b024f057316b0f97305bdc460f46201ceb19/packages/parser/src/constants/bhaiLangSpec.ts#L95-L96

Unlike all the other keywords, the flanked \b are missing in regex and they match on any token starting with sahi / galat instead of matching on the word sahi / galat. Refer to this \b assertion

I have also added couple of tests (examples mentioned above are the tests)

aniketsingh0104 commented 2 years ago

Thanks for fixing this. :)