vscode_mikrotik_routeros_script
vscode_mikrotik_routeros_script copied to clipboard
Strange highlighting issue (related to keywords in _comments_)
Everything on a line following the #
comment delimiter should be ignored.
If the keyword CREATE
or SET
exists in a comment, it seems to break the parsing / highlighting going forward.
Example 1:
Example 2 (CREATE
changed to CREATe
and OFFSET
changed to OFFSEt
):
I don't know why this is happening. Any ideas on directions for a possible fix?
(sample script - see e.g. line 63 when highlighted with this extension)
:global datetime do={
# 2021-10-19 Modified (manually) by Jim Grisham
#
# To load: /system script run create-datetime-function
# To use: type ":global datetime"
# :put ([$datetime]->"tzshort")
# :put ([$datetime]->"ymdtz")
# PART 1 - THE BASICS
:local months {
"jan"="01"
"feb"="02"
"mar"="03"
"apr"="04"
"may"="05"
"jun"="06"
"jul"="07"
"aug"="08"
"sep"="09"
"oct"="10"
"nov"="11"
"dec"="12"
}
:local dNames {"Sunday"; "Monday"; "Tuesday"; "Wednesday"; "Thursday"; "Friday"; "Saturday"}
:local dt
:local ti
# this loop protects in the rare event we hit midnight between getting the date and time
do {
:set dt [/system clock get date]
:set ti [/system clock get time]
} while=($dt != [/system clock get date])
:local b [:pick $dt 0 3 ]
:local Y [:pick $dt 7 11 ]
:local y [:pick $dt 9 11]
:local m ($months->$b)
:local d [:pick $dt 4 6]
:local H [:pick $ti 0 2]
# :local M [:pick $ti 3 5]
# :local S [:pick $ti 6 8]
# :local ymd "$Y-$m-$d"
:local I ($H % 12)
:if ($I = 0) do={
:set I 12
}
:if ([:len $I] < 2) do={
:set I ("0$I")
}
:local p
:if ($H < 12) do={
:set p "am"
} else={
:set p "pm"
}
# PART 2 - CREATE GMT OFFSET STRING
:local oInt [/system clock get gmt-offset]
:local oSign
# GMT offset is returned as an unsigned integer containing a signed integer
# so for negative numbers, it comes out as 4 billion instead of, say -18000
# Additionally, the bitwise NOT operator doesn't work for numbers so we
# have to do this ugly thing here
:if ($oInt > 2147483647) do={
:set oInt (4294967296 - $oInt)
:set oSign "-"
} else={
:set oSign "+"
}
# GMT Offset Hours
:local oHrs ($oInt / 3600)
# GMT Offset Minutes
:local oMin (($oInt % 3600) / 60)
:if ([:len $oHrs] < 2) do={
:set oHrs ("0$oHrs")
}
:if ([:len $oMin] < 2) do={
:set oMin ("0$oMin")
}
:local z "$oSign$oHrs$oMin"
# PART 2.1 - CREATE TIME ZONE LABEL
# Added by Jim Grisham
# Is "Summer Time" / "Daylight Savings Time" enabled?
:local dst [/system clock get dst-active]
# :local tz-name [/system clock get time-zone-name]
# :if ( $z = "-0700" && $dst = true ) do={ :set tz-short "PDT" }
# Line 105
# :if ( $z = "-0700" ) do={ :beep }
#:put $z
# Column ruler for script debugging (jhg 2021-10)
#
# 1 2 3 4 5
#2345678901234567890123456789012345678901234567890123456789
# Line 112
:local tzshort
:if ( $z = "-0700" ) do={ :set tzshort ("PDT") } ;
# Add additional time zone abbreviations here as needed:
:if ( $dst = true ) do={
:if ( $z = "-0700" ) do={ :set tzshort ("PDT") }
:if ( $z = "-0600" ) do={ :set tzshort ("MDT") }
:if ( $z = "-0500" ) do={ :set tzshort ("CDT") }
:if ( $z = "-0400" ) do={ :set tzshort ("EDT") }
} else {
:if ( $z = "-0800" ) do={ :set tzshort ("PST") }
:if ( $z = "-0700" ) do={ :set tzshort ("MST") }
:if ( $z = "-0600" ) do={ :set tzshort ("CST") }
:if ( $z = "-0500" ) do={ :set tzshort ("EST") }
:if ( $z = "-0000" || $z = "+0000" || $z = "0000" ) do={ :set tzshort ("GMT") }
}
# :if ( $tz-name = "America/Los_Angeles"
# :if ( $tz-name = "America/Los_Angeles" && $dst = true ) do={ :set tz-short "PDT" }[:len $oHrs] < 2) do={
# :set oHrs ("0$oHrs")
# }
# {
# :local myBool true;
# :if ($myBool = false) do={ :put "value is false" } else={ :put "value is true" }
# }
# :if ([:len $oHrs] < 2) do={
# :set oHrs ("0$oHrs")
# }
# PART 3 - DAY OF THE WEEK CALCULATION
# this entire section inspired by https://cs.uwaterloo.ca/~alopez-o/math-faq/node73.html
:local leapYear ( (($Y % 4) = 0) && ( (($Y % 100) != 0) || (($Y % 400) = 0) ) )
:local monthKeyVal {1; 4; 4; 0; 2; 5; 0; 3; 6; 1; 4; 6}
:local mkv ($monthKeyVal->($m-1))
# January and February of a leap year get special treatment
:if ( $leapYear && ( $m <= 2 ) ) do={
:set mkv ($mkv - 1)
}
:local w ( (($y / 4) + $d) + $mkv )
:if ($Y >= 2000) do={
:set w ($w + 6)
}
:set w ((($w + $y) - 1) % 7)
:local A ($dNames->w)
:local a [:pick $A 0 3]
# PART 4 - RETURN the results as an dictionary/array
:local dtobject {
"b"=$b
"m"=$m
"d"=$d
"Y"=$Y
"y"=$y
"time"=$ti
"H"=$H
"M"=[:pick $ti 3 5]
"S"=[:pick $ti 6 8]
"date"=$dt
"ymd"="$Y-$m-$d"
"I"=$I
"p"=$p
"z"=$z
"w"=$w
"A"=$A
"a"=$a
"Z"=[/system clock get time-zone-name]
# added 2021-10-19 by Jim Grisham
# "ymdt"=( "$Y-$m-$d_$H" . [:pick $ti 3 5] . "_" . [/system clock get time-zone-name] )
"ymdt"=( "$Y-$m-$d_$H" . [:pick $ti 3 5] )
"ymdtz"=( "$Y-$m-$d_$H" . [:pick $ti 3 5] . "_" . $tzshort )
"ymdtsz"=( "$Y-$m-$d_$H" . [:pick $ti 3 5] . [:pick $ti 6 8] . "_" . $tzshort )
"tz"=$tzshort
"tzshort"=$tzshort
}
:return $dtobject
}
Note: the GitHub bash
highlighter doesn't seem to like it either, but the ruby
one (used in this code block) is fine.
The same thing happens with this extension:
- https://marketplace.visualstudio.com/items?itemName=cperezabo.routeros-syntax
... but not with this one:
- https://marketplace.visualstudio.com/items?itemName=lautaportti.routeros-conf / https://github.com/dokai/routeros-conf
...
Other (not VSCode-related) RouterOS highlighters:
- https://github.com/git-touch/highlight.dart/blob/master/highlight/lib/languages/routeros.dart
- https://github.com/zainin/vim-mikrotik
References:
- VSCode highlighting
- https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide
- https://code.visualstudio.com/api/get-started/your-first-extension
- RouterOS Scripting
- https://wiki.mikrotik.com/wiki/Manual:Scripting
- https://help.mikrotik.com/docs/display/ROS/Scripting
- Syntax highlighting on GitHub
- https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
- https://www.rubycoloredglasses.com/2013/04/languages-supported-by-github-flavored-markdown/
- https://stackoverflow.com/questions/11568093/syntax-highlighting-on-githubs-wiki-specifying-the-programming-language
- https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#syntax-highlighting
What theme are you using?