Skip to content

Instantly share code, notes, and snippets.

@dockimbel
Last active January 4, 2019 20:24
Show Gist options
  • Save dockimbel/709247c676640d867f62ca8c4585e7ff to your computer and use it in GitHub Desktop.
Save dockimbel/709247c676640d867f62ca8c4585e7ff to your computer and use it in GitHub Desktop.
PoC script for checking if brackets/parens are matching in a Red file
Red [
Purpose: "PoC script for checking if brackets/parens are matching in a Red file"
]
check-brackets: function [file [file!]][
line: 1
stack: clear []
skip-chars: complement charset "[]()^/"
parse read file [
some [
some skip-chars
| pos: [
#"^/" (line: line + 1)
| [#"(" | #"["] (repend stack [pos/1 line])
| [#")" | #"]"] (
either (select ")(][" pos/1) = first entry: skip tail stack -2 [clear entry][
unless empty? stack [line: last stack]
print ["No opening match for closing" pos/1 "at line" line]
exit
]
)
]
]
]
either empty? stack [none][
entry: skip tail stack -2
print ["Opening" entry/1 "at line" entry/2 "not closed"]
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment