Last active
January 4, 2019 20:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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