Skip to content

Commit

Permalink
[fix]: support for inline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravfs-14 committed Dec 15, 2024
1 parent a4661da commit e24b1ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions example/example.bhn
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ bhanai("Namaste, " + name + "! Welcome to Bhanai.")

rakha("num1", sodhNumber("Enter the first number: "))
rakha("num2", sodhNumber("Enter the second number: "))
rakha("sum", jod(num1, num2))
rakha("sum", jod(num1, num2)) # yo inline comment ho

bhanai("The sum of " + num1 + " and " + num2 + " is: " + sum)
bhanai("The sum of " + num1 + " and " + num2 + " is: " + sum) tippani yo pani inline comment ho
14 changes: 12 additions & 2 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,18 @@ const parseLine = async (line) => {
// Ignore empty lines
if (!line) return;

// Ignore single-line comments starting with # or tippani
if (line.startsWith("#") || line.startsWith("tippani")) return;
// Handle inline comments with # or tippani
const commentIndex = Math.min(
...["#", "tippani"].map((marker) =>
line.indexOf(marker) >= 0 ? line.indexOf(marker) : Infinity
)
);
if (commentIndex !== Infinity) {
line = line.slice(0, commentIndex).trim(); // Remove the inline comment
}

// Ignore the line if it's now empty after removing comments
if (!line) return;

// Match and parse commands
const commandMatch = line.match(/^(\w+)\((.*)\)$/);
Expand Down

0 comments on commit e24b1ad

Please sign in to comment.