@Igor Barboza
You can use %Library.SyntaxColor to parse ObjectScript. Here's some code to get you started:
ClassMethod WriteAllCommands()
{
Set syn = ##class(%SyntaxColor).%New(), in = ##class(%Stream.TmpCharacter).%New(), out = ##class(%Stream.TmpCharacter).%New()
#; TODO Put your document's contents into "in"
Do syn.Color(in,out,"COS" /* or "INT" or "CLS" */,"KE" /* K means JSON output, E means keep empty lines */)
#; Format of the JSON output:
#; [
#; #; One array for each source line
#; [
#; {
#; #; Language of the token. See Languages() in %Library.SyntaxColor.
#; "l": %Integer,
#; #; Attribute of the token. See Attributes() in %Library.SyntaxColor.
#; "s": %Integer,
#; #; Zero-indexed start position of the token on the line
#; "p": %Integer,
#; #; Length of the token in characters
#; "c": %Integer
#; }
#; ]
#; ]
Set json = ##class(%DynamicArray).%FromJSON(out), lineIter = json.%GetIterator()
While lineIter.%GetNext(.lineNum,.lineTokens) {
Set tokensIter = lineTokens.%GetIterator()
While tokensIter.%GetNext(,.token) {
If (
#; COS
(token.l = 1) && (
#; Command
(token.s = 32) ||
#; User-defined Z command
(token.s = 52)
)
) {
Write "Command starting in column ",token.p + 1," of line ",lineNum + 1,!
}
}
}
}- Log in to post comments


.png)