"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/langDefs/purebasic.lang" (12 May 2020, 16229 Bytes) of package /windows/www/highlight-3.57-x64.zip:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "purebasic.lang": 3.53_vs_3.54.

    1 --[[
    2 ******************************************************************************
    3 *                                                                            *
    4 *                       PureBASIC Language Definition                        *
    5 *                                                                            *
    6 *                            v1.7.1 - 2017/11/18                             *
    7 *                                                                            *
    8 ******************************************************************************
    9 PureBASIC v5.00-5.61 -- The goal of this language definition is to emulate the
   10 way PureBASIC's native IDE highlights its code, including inline Assembly
   11 syntax coloring. When used with the "edit-purebasic" theme, PureBASIC code
   12 will be highlighted just like in its native IDE.
   13 
   14 Keywords from all PureBASIC versions (from 5.00 up to current) are added to
   15 the list (deprecated keywords are preserved) to ensure that any code written
   16 for PureBASIC >=5.00 will be parsed and highlighted correctly.
   17 
   18 Comments in color definitions refer to PureBASIC native IDE's default palette.
   19 ------------------------------------------------------------------------------
   20 This language definition is maintained at the PureBASIC Archives project:
   21     https://github.com/tajmone/purebasic-archives/tree/master/syntax-highlighting/highlight
   22 
   23 (visit the above link for more info and resources on this lang definition)
   24 ------------------------------------------------------------------------------
   25 Written by Tristano Ajmone:
   26     <tajmone@gmail.com>
   27     https://github.com/tajmone
   28 Released into the public domain according to the Unlicense terms:
   29     http://unlicense.org/
   30 ------------------------------------------------------------------------------
   31   ]]
   32 
   33 Description="PureBASIC"
   34 
   35 Categories = {"source"}
   36 
   37 IgnoreCase=false
   38 
   39 Comments={  -- PB IDE color: #00AAAA (Persian Green/Tradewind)
   40   { Block=false,
   41     Nested=false,
   42     Delimiter = { [[ ; ]] }
   43   }
   44 }
   45 
   46 Strings={   -- PB IDE color: #0080FF (Azure Radiance)
   47   Delimiter=[[ " ]],
   48   Escape=[=[\\[abfnrtv"\\]]=], -- PB IDE color: same as String
   49 }
   50 --[[ STRINGS NOTE: There's more to PB strings than this delimiter definition.
   51         Escaped strings (~"") are handled via `Keyword Id=4` and custom code in
   52         the `OnStateChange()` function found below.
   53 --]]
   54 
   55 Operators=[[\&|<|>|\!|\||\=|\/|\*|\%|\+|\-|~]] -- PB IDE color: same as normal text (Black)
   56 
   57 -- NUMBERS > PB IDE color: same as normal text (Black)
   58 Digits=[[ (?x)
   59         # ============ HEX ============
   60         # Pascal style ($FF):
   61 
   62           \$[0-9a-fA-F]+\b
   63 
   64         # ============ BINARY ============
   65         | %[01]+\b
   66 
   67 
   68         # ============ FLOAT ============
   69         # With decimal point separator:
   70 
   71         | \b[-]?\d+\.\d+(?:[eE][\-\+]?\d+)?[a-zA-Z]*\b
   72 
   73         # Without decimal point separator:
   74 
   75         | \b[-]?\d+(?:[eE][\-\+]?\d+)[a-zA-Z]*\b
   76 
   77 
   78         # ============ DECIMAL ============
   79         | (?<!\$)\b\d+\b
   80 
   81       ]]
   82 -- FLOATS NOTE: PureBASIC strips and ignores all suffixes from float numbers.
   83 --    Therefore "1.575e+1" and "1.575e+1bananas" are both valid float values
   84 --    in PureBASIC code (both yelding the smae value of 15.75).
   85 
   86 
   87 Keywords={
   88   { Id=1,   -- PureBASIC Keywords > PB IDE color: #006666 (Blue Stone) + Bold
   89     List={
   90         -- Keywords list built by parsing the tokens inside PureBASIC SDK's
   91         -- "SyntaxHilighting.dll" (from each PureBASIC version)...
   92         "Align", "And", "Array", "As", "Break", "CallDebugger", "Case", "CompilerCase", "CompilerDefault",
   93         "CompilerElse", "CompilerElseIf", "CompilerEndIf", "CompilerEndSelect", "CompilerError",
   94         "CompilerIf", "CompilerSelect", "CompilerWarning", "Continue", "Data", "DataSection", "Debug",
   95         "DebugLevel", "Declare", "DeclareC", "DeclareCDLL", "DeclareDLL", "DeclareModule", "Default",
   96         "Define", "Dim", "DisableASM", "DisableDebugger", "DisableExplicit", "Else", "ElseIf", "EnableASM",
   97         "EnableDebugger", "EnableExplicit", "End", "EndDataSection", "EndDeclareModule", "EndEnumeration",
   98         "EndIf", "EndImport", "EndInterface", "EndMacro", "EndModule", "EndProcedure", "EndSelect",
   99         "EndStructure", "EndStructureUnion", "EndWith", "Enumeration", "EnumerationBinary", "Extends",
  100         "FakeReturn", "For", "ForEach", "ForEver", "Global", "Gosub", "Goto", "If", "Import", "ImportC",
  101         "IncludeBinary", "IncludeFile", "IncludePath", "Interface", "List", "Macro", "MacroExpandedCount",
  102         "Map", "Module", "NewList", "NewMap", "Next", "Not", "Or", "Procedure", "ProcedureC",
  103         "ProcedureCDLL", "ProcedureDLL", "ProcedureReturn", "Protected", "Prototype", "PrototypeC", "ReDim",
  104         "Read", "Repeat", "Restore", "Return", "Runtime", "Select", "Shared", "Static", "Step", "Structure",
  105         "StructureUnion", "Swap", "Threaded", "To", "UndefineMacro", "Until", "Until ", "UnuseModule",
  106         "UseModule", "Wend", "While", "With", "XIncludeFile", "XOr",        },
  107     },
  108   { Id=2,   -- Constants > PB IDE color: #924B72 (Cannon Pink)
  109     Regex=[[ (#[a-zA-Z_]\w*\$?) ]]
  110     },
  111   { Id=2,   -- Inline ASM > PB IDE color: #924B72 (Cannon Pink)
  112     Regex=[[ ^\s*(![^;]*) ]], Group=1
  113     },
  114   { Id=2,   -- ASM Keywords > PB IDE color: #924B72 (Cannon Pink)
  115     List={
  116         -- Keywords list built by parsing the tokens inside PureBASIC SDK's
  117         -- "SyntaxHilighting.dll" (from each PureBASIC version)...
  118         "AAA", "AAD", "AAM", "AAS", "ADC", "ADD", "AND", "ARPL", "BOUND", "BSF", "BSR", "BSWAP", "BT",
  119         "BTC", "BTR", "BTS", "CALL", "CBW", "CDQ", "CLC", "CLD", "CLI", "CLTS", "CMC", "CMOVA", "CMOVAE",
  120         "CMOVB", "CMOVBE", "CMOVC", "CMOVE", "CMOVG", "CMOVGE", "CMOVL", "CMOVLE", "CMOVNA", "CMOVNAE",
  121         "CMOVNB", "CMOVNBE", "CMOVNC", "CMOVNE", "CMOVNG", "CMOVNGE", "CMOVNL", "CMOVNLE", "CMOVNO",
  122         "CMOVNP", "CMOVNS", "CMOVNZ", "CMOVO", "CMOVP", "CMOVPE", "CMOVPO", "CMOVS", "CMOVZ", "CMP", "CMPS",
  123         "CMPSB", "CMPSD", "CMPSW", "CMPXCHG", "CMPXCHG8B", "CWD", "CWDE", "DAA", "DAS", "DB", "DD", "DEC",
  124         "DIV", "DW", "EMMS", "ENTER", "ESC", "F2XM1", "FABS", "FADD", "FADDP", "FBLD", "FBSTP", "FCHS",
  125         "FCLEX", "FCMOVB", "FCMOVBE", "FCMOVE", "FCMOVNB", "FCMOVNBE", "FCMOVNE", "FCMOVNU", "FCMOVU",
  126         "FCOM", "FCOMI", "FCOMIP", "FCOMP", "FCOMPP", "FCOS", "FDECSTP", "FDIV", "FDIVP", "FDIVR", "FDIVRP",
  127         "FFREE", "FIADD", "FICOM", "FICOMP", "FIDIV", "FIDIVR", "FILD", "FIMUL", "FINCSTP", "FINIT", "FIST",
  128         "FISTP", "FISUB", "FISUBR", "FLD", "FLD1", "FLDCW", "FLDENV", "FLDL2E", "FLDL2T", "FLDLG2",
  129         "FLDLN2", "FLDPI", "FLDZ", "FMUL", "FMULP", "FNCLEX", "FNINIT", "FNOP", "FNSAVE", "FNSTCW",
  130         "FNSTENV", "FNSTSW", "FPATAN", "FPREM", "FPREM1", "FPTAN", "FRNDINT", "FRSTOR", "FSAVE", "FSCALE",
  131         "FSETPM", "FSIN", "FSINCOS", "FSQRT", "FST", "FSTCW", "FSTENV", "FSTP", "FSTSW", "FSUB", "FSUBP",
  132         "FSUBR", "FSUBRP", "FTST", "FUCOM", "FUCOMI", "FUCOMIP", "FUCOMP", "FUCOMPP", "FWAIT", "FXAM",
  133         "FXCH", "FXTRACT", "FYL2X", "FYL2XP1", "HLT", "IDIV", "IMUL", "IN", "INC", "INS", "INSB", "INSD",
  134         "INSW", "INT", "INTO", "INVD", "INVLPG", "IRET", "IRETD", "JA", "JAE", "JB", "JBE", "JC", "JCXZ",
  135         "JE", "JECXZ", "JG", "JGE", "JL", "JLE", "JMP", "JNA", "JNAE", "JNB", "JNBE", "JNC", "JNE", "JNG",
  136         "JNGE", "JNL", "JNLE", "JNO", "JNP", "JNS", "JNZ", "JO", "JP", "JPE", "JPO", "JS", "JZ", "LAHF",
  137         "LAR", "LDS", "LEA", "LEAVE", "LES", "LFS", "LGDT", "LGS", "LIDT", "LLDT", "LMSW", "LOCK", "LODS",
  138         "LODSB", "LODSD", "LODSW", "LOOP", "LOOPE", "LOOPNE", "LOOPNZ", "LOOPZ", "LSL", "LSS", "LTR", "MOV",
  139         "MOVD", "MOVQ", "MOVS", "MOVSB", "MOVSD", "MOVSW", "MOVSX", "MOVZX", "MUL", "NEG", "NOP", "NOT",
  140         "OR", "OUT", "OUTS", "OUTSB", "OUTSD", "OUTSW", "PACKSSDW", "PACKSSWB", "PACKUSWB", "PADDB",
  141         "PADDD", "PADDSB", "PADDSW", "PADDUSB", "PADDUSW", "PADDW", "PAND", "PANDN", "PCMPEQB", "PCMPEQD",
  142         "PCMPEQW", "PCMPGTB", "PCMPGTD", "PCMPGTW", "PMADDWD", "PMULHW", "POP", "POPA", "POPAD", "POPF",
  143         "POPFD", "POR", "PSLLD", "PSLLQ", "PSLLW", "PSRAD", "PSRAW", "PSRLD", "PSRLQ", "PSRLW", "PSUBB",
  144         "PSUBD", "PSUBSB", "PSUBSW", "PSUBUSB", "PSUBUSW", "PSUBW", "PUNPCKHBW", "PUNPCKHDQ", "PUNPCKHWD",
  145         "PUNPCKLBW", "PUNPCKLDQ", "PUNPCKLWD", "PUSH", "PUSHA", "PUSHAD", "PUSHF", "PUSHFD", "PXOR", "RCL",
  146         "RCR", "RDMSR", "RDPMC", "RDTSC", "REP", "REPE", "REPNE", "REPNZ", "REPZ", "RET", "RETF", "ROL",
  147         "ROR", "RSM", "SAHF", "SAL", "SAR", "SBB", "SCAS", "SCASB", "SCASD", "SCASW", "SETA", "SETAE",
  148         "SETB", "SETBE", "SETC", "SETE", "SETG", "SETGE", "SETL", "SETLE", "SETNA", "SETNAE", "SETNB",
  149         "SETNBE", "SETNC", "SETNE", "SETNG", "SETNGE", "SETNL", "SETNLE", "SETNO", "SETNP", "SETNS",
  150         "SETNZ", "SETO", "SETP", "SETPE", "SETPO", "SETS", "SETZ", "SGDT", "SHL", "SHLD", "SHR", "SHRD",
  151         "SIDT", "SLDT", "SMSW", "STC", "STD", "STI", "STOS", "STOSB", "STOSD", "STOSW", "STR", "SUB",
  152         "TEST", "UD2", "VERR", "VERW", "WAIT", "WBINVD", "WRMSR", "XADD", "XCHG", "XLAT", "XLATB", "XOR" },
  153     },
  154   { Id=3,   -- Procedure calls > PB IDE color: #006666 (Blue Stone)
  155     Regex=[[ ([a-zA-Z_]\w*)(?:(?:\s*)\() ]],
  156     Group=1
  157     },
  158   { Id=4,   -- Escaped-String Prefix ("~") > PB IDE color: same as strings
  159     Regex=[[ ~" ]], -- NOTE: In the final doc, this Keyword is converted to become
  160                     --       part of the string [see OnStateChange() func below]
  161     },
  162 }
  163 
  164 
  165 
  166 function OnStateChange(oldState, newState, token, kwgroup)
  167 
  168 --[[
  169 ========================
  170 Dismiss Escape-Sequences
  171 ========================
  172 Currently, I couldn't find a way to preserve escape sequences without causing
  173 stray behaviour in string. So, for the time being they are just dismissed. ]]
  174 
  175   if newState==HL_ESC_SEQ then
  176     if oldState==HL_STRING then
  177       -- ESCAPE SEQUENCE FOUND INSIDE A STRING:
  178       if escapedString~=true then
  179         -- String is Literal (no escaping allowed)...
  180         escapeSeq = false
  181         if token=='\\"' then
  182           -- rejecting a \" will cause the \ to become part of the curr. string
  183           -- but the " will be thrown again to the parser, which will mistake it
  184           -- for a new string start. We'll use the `forceStringEnd` var to
  185           -- prevent this...
  186           forceStringEnd = true
  187           return HL_REJECT
  188         else
  189           -- all other escape sequences can be suppresed by assimilating
  190           -- them to the current string...
  191           forceStringEnd=false
  192           return HL_REJECT --HL_STRING
  193         end
  194       else
  195         -- String is Escapable...
  196         escapeSeq = true
  197         forceStringEnd=false
  198         return HL_ESC_SEQ
  199       end
  200     -- HANDLE TWO ESCAPRE SEQUENCES IN A ROW:
  201     elseif oldState==HL_ESC_SEQ then
  202         escapeSeq = true
  203         escapedString = true
  204         forceStringEnd=false
  205         return HL_ESC_SEQ
  206     else
  207       -- ESCAPE SEQUENCE FOUND OUTSIDE A STRING
  208       escapeSeq = false
  209       forceStringEnd=false
  210         escapedString = false
  211       return HL_REJECT
  212     end
  213 
  214 --[[  PB Escape Strings (~"...")
  215       ==========================
  216       Keyword 4 (~") is converted to string state, so the tilda becomes part of
  217       the actual string. The boolean var `escapedString` tracks this process. ]]
  218   elseif newState==HL_KEYWORD and kwgroup==4 then
  219     -- If ~" occurs inside a string, it's just a string with a tilda as last char...
  220     if oldState==HL_STRING then
  221       -- We use the `forceStringEnd` var trick here, like we did with
  222       -- rejected \" escape sequences above...
  223       forceStringEnd=true
  224       return HL_REJECT -- HL_STRING -- HL_REJECT
  225     -- In all other cases it's an escaped string delimiter (opening)...
  226     else
  227       escapedString = true
  228       escapeSeq = false
  229       forceStringEnd=false
  230       return HL_STRING
  231     end
  232 
  233 --[[ NEW STATE IS STRING: ]]
  234   elseif newState==HL_STRING then
  235 
  236 --[[  Handle The " After A Rejcted  \" or ~" in Literal String
  237       =======================
  238       A rejected \" or ~" led to a spurious " being fed to the parser which can
  239       be mistaken for a new string delimiter ]]
  240     if forceStringEnd==true then
  241       forceStringEnd=false
  242       return HL_STRING_END
  243 
  244 --[[  Sanitize String Starts
  245       ======================
  246       Because Keyword 4 is converted to a string start, we must tell the parser
  247       to treat the next string delimiter as a string end! ]]
  248     elseif escapedString==true then
  249       escapedString = false
  250       return HL_STRING_END
  251 
  252 --[[  Sanitize String After Escape Sequence
  253       =====================================
  254       Ensure that a " immediately following an escape sequence is treated as
  255       a string-end delimiter. ]]
  256     elseif token=='"' and escapeSeq==true then
  257       escapeSeq = false
  258       forceStringEnd=false
  259       escapedString = false
  260       return HL_STRING_END
  261     else
  262       escapeSeq = false
  263       forceStringEnd=false
  264       return HL_STRING
  265     end
  266 
  267 --[[ FOR ALL OTHER SYNTAX ITEMS:]]
  268   elseif oldState~=HL_STRING and oldState~=HL_ESC_SEQ then
  269     -- Reset all Trackers' States: This is required to avoid some edge-cases
  270     -- of strings corruption in complex source code...
  271     escapeSeq = false
  272     escapedString = false
  273     forceStringEnd=false
  274     return newState
  275 
  276   end
  277 end
  278 
  279 
  280 --[[==========================================================================
  281                                       CHANGELOG
  282 ==============================================================================
  283 v1.7.1  - 2017/11/18 (PureBASIC v5.61)
  284         - Syntax checked against new PureBASIC v5.61 (no changes detected)
  285 v1.7    - 2017/10/02 (PureBASIC v5.60)
  286         - IMPROVEMENTS: Escape sequences are now corretcly parsed and highlighted.
  287 v1.6    - 2017/09/30 (PureBASIC v5.60)
  288         - IMPROVEMENTS: Added numbers definition (hex, binary, floats an decimals)
  289         - BUG-FIX: String concatenations didn't always parse correctly; now this
  290           was fixed (at the expenses of escaped sequences).
  291         - ABROGATED: parsing of escape sequences is now disabled because it caused
  292           too many problems with strings.
  293 v1.5    - 2017/09/28 (PureBASIC v5.60)
  294         - IMPROVEMENTS:
  295           - Escaped-String Prefix (~) is no longer handled as a keyword (ID=4/kwd)
  296             but its recognized as a valid string delimiter.
  297           - Escape Sequences are further sanitized so that they can occur only
  298             inside strings with the ~" opening delimiter.
  299         - ABROGATED:
  300           - The lang definition no longer uses Keyword 4 (Escaped-String Prefix).
  301 v1.4    - 2017/09/27 (PureBASIC v5.60)
  302         - BUG-FIX: Added sanitize function to avoid false positive Escape Sequences
  303           in structured vars (eg: "\v" in "SomeStructure\var1").
  304           (Thanks to André Simon -- see Issue #23:)
  305           -- https://github.com/andre-simon/highlight/issues/23
  306 v1.3    - 2017/05/20 (PureBASIC v5.60)
  307         - fixed single line comment delimiter
  308 v1.2    - 2017/05/11 (PureBASIC v5.60)
  309         - Added ASM keywords and support for inline ASM (via "!" syntax).
  310         - BUG-FIXES:
  311           - Repaired missing or mispelled PB Keywords (something went wrong in the
  312             keywords list of the v1.1 of this lang definition, some tokens were
  313             lost, other fused into a single token -- sorry about that).
  314 v1.1    - 2017/04/30 (PureBASIC v5.60)
  315         - Keywords list now built by extracting them from the PureBASIC SDK's
  316           "SyntaxHilighting.dll" (from each PureBASIC version). Tokens from each
  317           version are added to the list, and renamed or removed tokens are kept
  318           for the sake of covering all versions of the language from PureBASIC
  319           v5.00 upward. (NOTE: currently, there are no renamed or deprecated
  320           tokens in the keywords list). For more info, see:
  321           -- http://www.purebasic.fr/english/viewtopic.php?&p=506269
  322           -- https://github.com/tajmone/purebasic-archives/tree/master/syntax-highlighting/guidelines
  323 v1.0    - 2016/10/27 (PureBASIC v5.50)
  324         - First release. Keywords list taken and adapted from GuShH's PureBasic
  325           language file for GeSHi:
  326           -- https://github.com/easybook/geshi/blob/master/geshi/purebasic.php
  327 --]]