Skip to content

Instantly share code, notes, and snippets.

@peterbe
Created May 13, 2021 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterbe/ec855768f8921db49f09d5e368524d0f to your computer and use it in GitHub Desktop.
Save peterbe/ec855768f8921db49f09d5e368524d0f to your computer and use it in GitHub Desktop.
function* fastKSParser(s) {
for (const match of s.matchAll(
/\{\{\s*(\w+[\w-\.]*\w+)\s*(\((.*?)\)|)\s*\}\}/gms
)) {
const { index } = match;
if (s.charAt(index - 1) === "\\") {
continue;
}
const split = (match[3] || "").trim().split(",");
yield {
name: match[1],
args: split,
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment