summaryrefslogtreecommitdiff
path: root/vendor/bundle/ruby/3.4.0/gems/rouge-4.5.2/lib/rouge/lexers/mosel.rb
blob: bad56d0f650dcc1d4baa32fa7fa0c1b883cead9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
  module Lexers
    class Mosel < RegexLexer
      tag 'mosel'
      filenames '*.mos'
      title "Mosel"
      desc "An optimization language used by Fico's Xpress."
      # http://www.fico.com/en/products/fico-xpress-optimization-suite
      filenames '*.mos'

      mimetypes 'text/x-mosel'

      id = /[a-zA-Z_][a-zA-Z0-9_]*/

      ############################################################################################################################
      #  General language lements
      ############################################################################################################################

      core_keywords = %w(
        and array as
        boolean break
        case count counter
        declarations div do dynamic
        elif else end evaluation exit
        false forall forward from function
        if imports in include initialisations initializations integer inter is_binary is_continuous is_free is_integer is_partint is_semcont is_semint is_sos1 is_sos2
        linctr list
        max min mod model mpvar
        next not of options or
        package parameters procedure
        public prod range real record repeat requirements
        set string sum
        then to true
        union until uses
        version
        while with
      )

      core_functions = %w(
        abs arctan assert
        bitflip bitneg bitset bitshift bittest bitval
        ceil cos create currentdate currenttime cuthead cuttail
        delcell exists exit exp exportprob
        fclose fflush finalize findfirst findlast floor fopen fselect fskipline
        getact getcoeff getcoeffs getdual getfid getfirst gethead getfname getlast getobjval getparam getrcost getreadcnt getreverse getsize getslack getsol gettail gettype getvars
        iseof ishidden isodd ln log
        makesos1 makesos2 maxlist minlist
        publish
        random read readln reset reverse round
        setcoeff sethidden setioerr setname setparam setrandseed settype sin splithead splittail sqrt strfmt substr
        timestamp
        unpublish
        write writeln
      )

      ############################################################################################################################
      # mmxprs module elements
      ############################################################################################################################

      mmxprs_functions = %w(
        addmipsol
        basisstability
        calcsolinfo clearmipdir clearmodcut command copysoltoinit
        defdelayedrows defsecurevecs
        estimatemarginals
        fixglobal
        getbstat getdualray getiis getiissense getiistype getinfcause getinfeas getlb getloadedlinctrs getloadedmpvars getname getprimalray getprobstat getrange getsensrng getsize getsol getub getvars
        implies indicator isiisvalid isintegral loadbasis
        loadmipsol loadprob
        maximize minimize
        postsolve
        readbasis readdirs readsol refinemipsol rejectintsol repairinfeas resetbasis resetiis resetsol
        savebasis savemipsol savesol savestate selectsol setbstat setcallback setcbcutoff setgndata setlb setmipdir setmodcut setsol setub setucbdata stopoptimize
        unloadprob
        writebasis writedirs writeprob writesol
        xor
      )

      mmxpres_constants = %w(XPRS_OPT  XPRS_UNF  XPRS_INF XPRS_UNB XPRS_OTH)

      mmxprs_parameters = %w(XPRS_colorder XPRS_enumduplpol XPRS_enummaxsol XPRS_enumsols XPRS_fullversion XPRS_loadnames XPRS_problem XPRS_probname XPRS_verbose)


      ############################################################################################################################
      # mmsystem module elements
      ############################################################################################################################

      mmsystem_functions = %w(
        addmonths
        copytext cuttext
        deltext
        endswith expandpath
        fcopy fdelete findfiles findtext fmove
        getasnumber getchar getcwd getdate getday getdaynum getdays getdirsep
        getendparse setendparse
        getenv getfsize getfstat getftime gethour getminute getmonth getmsec getpathsep
        getqtype setqtype
        getsecond
        getsepchar setsepchar
        getsize
        getstart setstart
        getsucc setsucc
        getsysinfo getsysstat gettime
        gettmpdir
        gettrim settrim
        getweekday getyear
        inserttext isvalid
        makedir makepath newtar
        newzip nextfield
        openpipe
        parseextn parseint parsereal parsetext pastetext pathmatch pathsplit
        qsort quote
        readtextline regmatch regreplace removedir removefiles
        setchar setdate setday setenv sethour
        setminute setmonth setmsec setsecond settime setyear sleep startswith system
        tarlist textfmt tolower toupper trim
        untar unzip
        ziplist
      )

      mmsystem_parameters = %w(datefmt datetimefmt monthnames sys_endparse sys_fillchar sys_pid sys_qtype sys_regcache sys_sepchar)

      ############################################################################################################################
      # mmjobs  module elements
      ############################################################################################################################

      mmjobs_instance_mgmt_functions = %w(
        clearaliases connect
        disconnect
        findxsrvs
        getaliases getbanner gethostalias
        sethostalias
      )

      mmjobs_model_mgmt_functions = %w(
        compile
        detach
        getannidents getannotations getexitcode getgid getid getnode getrmtid getstatus getuid
        load
        reset resetmodpar run
        setcontrol setdefstream setmodpar setworkdir stop
        unload
      )

      mmjobs_synchornization_functions = %w(
        dropnextevent
        getclass getfromgid getfromid getfromuid getnextevent getvalue
        isqueueempty
        nullevent
        peeknextevent
        send setgid setuid
        wait waitfor
      )

      mmjobs_functions = mmjobs_instance_mgmt_functions + mmjobs_model_mgmt_functions + mmjobs_synchornization_functions

      mmjobs_parameters = %w(conntmpl defaultnode fsrvdelay fsrvnbiter fsrvport jobid keepalive nodenumber parentnumber)


      state :whitespace do
        # Spaces
        rule %r/\s+/m, Text
        # ! Comments
        rule %r((!).*$\n?), Comment::Single
        # (! Comments !)
        rule %r(\(!.*?!\))m, Comment::Multiline

      end


      # From Mosel documentation:
      # Constant strings of characters must be quoted with single (') or double quote (") and may extend over several lines. Strings enclosed in double quotes may contain C-like escape sequences introduced by the 'backslash'
      # character (\a \b \f \n \r \t \v \xxx with xxx being the character code as an octal number).
      # Each sequence is replaced by the corresponding control character (e.g. \n is the `new line' command) or, if no control character exists, by the second character of the sequence itself (e.g. \\ is replaced by '\').
      # The escape sequences are not interpreted if they are contained in strings that are enclosed in single quotes.

      state :single_quotes do
        rule %r/'/, Str::Single, :pop!
        rule %r/[^']+/, Str::Single
      end

      state :double_quotes do
        rule %r/"/, Str::Double, :pop!
        rule %r/(\\"|\\[0-7]{1,3}\D|\\[abfnrtv]|\\\\)/, Str::Escape
        rule %r/[^"]/, Str::Double
      end

      state :base do

        rule %r{"}, Str::Double, :double_quotes
        rule %r{'}, Str::Single, :single_quotes

        rule %r{((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?}, Num
        rule %r{[~!@#\$%\^&\*\(\)\+`\-={}\[\]:;<>\?,\.\/\|\\]}, Punctuation
#        rule %r{'([^']|'')*'}, Str
#        rule %r/"(\\\\|\\"|[^"])*"/, Str



        rule %r/(true|false)\b/i, Name::Builtin
        rule %r/\b(#{core_keywords.join('|')})\b/i, Keyword
        rule %r/\b(#{core_functions.join('|')})\b/, Name::Builtin



        rule %r/\b(#{mmxprs_functions.join('|')})\b/, Name::Function
        rule %r/\b(#{mmxpres_constants.join('|')})\b/, Name::Constant
        rule %r/\b(#{mmxprs_parameters.join('|')})\b/i, Name::Property

        rule %r/\b(#{mmsystem_functions.join('|')})\b/i, Name::Function
        rule %r/\b(#{mmsystem_parameters.join('|')})\b/, Name::Property

        rule %r/\b(#{mmjobs_functions.join('|')})\b/i, Name::Function
        rule %r/\b(#{mmjobs_parameters.join('|')})\b/, Name::Property

        rule id, Name
      end

      state :root do
        mixin :whitespace
        mixin :base
      end
    end
  end
end