OMCompiler/Compiler/Lexers/LexerJSON.mo
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | encapsulated package LexerJSON "Automatically generated lexer based on flex, generated OMCCp v0.11.0 OpenModelica lexer and parser generator (2015)" | ||
| 2 | /* | ||
| 3 | Template for Lexer Code | ||
| 4 | replace keywords: | ||
| 5 | %LexerCode | ||
| 6 | %time | ||
| 7 | %Token | ||
| 8 | %Lexer | ||
| 9 | %LexTable | ||
| 10 | %constant | ||
| 11 | %nameSpan | ||
| 12 | %functions | ||
| 13 | %caseAction | ||
| 14 | */ | ||
| 15 | |||
| 16 | import System; | ||
| 17 | |||
| 18 | constant Boolean debug = false; | ||
| 19 | |||
| 20 | replaceable package LexTable | ||
| 21 | constant Integer yy_limit; | ||
| 22 | constant Integer yy_finish; | ||
| 23 | constant array<Integer> yy_acclist; | ||
| 24 | constant array<Integer> yy_accept; | ||
| 25 | constant array<Integer> yy_ec; | ||
| 26 | constant array<Integer> yy_meta; | ||
| 27 | constant array<Integer> yy_base; | ||
| 28 | constant array<Integer> yy_def; | ||
| 29 | constant array<Integer> yy_nxt; | ||
| 30 | constant array<Integer> yy_chk; | ||
| 31 | end LexTable; | ||
| 32 | |||
| 33 | function scan "Scan starts the lexical analysis, load the tables and consume the program to output the tokens" | ||
| 34 | input String fileName "input source code file"; | ||
| 35 | output list<Token> tokens "return list of tokens"; | ||
| 36 | output list<Token> errorTokens; | ||
| 37 | protected | ||
| 38 | String contents; | ||
| 39 | algorithm | ||
| 40 | ✗ | contents := System.readFile(fileName); | |
| 41 | ✗ | (tokens, errorTokens) := lex(fileName,contents); | |
| 42 | end scan; | ||
| 43 | |||
| 44 | function scanString "Scan starts the lexical analysis, load the tables and consume the program to output the tokens" | ||
| 45 | input String fileSource "input source code file"; | ||
| 46 | input String fileName = "<StringSource>"; | ||
| 47 | output list<Token> tokens "return list of tokens"; | ||
| 48 | output list<Token> errorTokens; | ||
| 49 | algorithm | ||
| 50 | ✗ | (tokens, errorTokens) := lex(fileName,fileSource); | |
| 51 | end scanString; | ||
| 52 | |||
| 53 | |||
| 54 | /* grammar according to json.org */ | ||
| 55 | protected | ||
| 56 | import Error; | ||
| 57 | public | ||
| 58 | function action | ||
| 59 | input Integer act; | ||
| 60 | input Integer startSt; | ||
| 61 | input Integer mm_currSt,mm_pos,mm_sPos,mm_ePos,mm_linenr,lineNrStart; | ||
| 62 | input Integer buffer; | ||
| 63 | input String fileNm; | ||
| 64 | input String fileContents; | ||
| 65 | input list<Token> inErrorTokens; | ||
| 66 | output Token token; | ||
| 67 | output Integer mm_startSt; | ||
| 68 | output Integer bufferRet; | ||
| 69 | output list<Token> errorTokens=inErrorTokens; | ||
| 70 | protected | ||
| 71 | algorithm | ||
| 72 | mm_startSt := startSt; | ||
| 73 | // nameSpan := 255; | ||
| 74 | bufferRet := 0; | ||
| 75 | token := match act | ||
| 76 | local | ||
| 77 | Token tok; | ||
| 78 | case 1 // #line 25 "lexerJSON.l" | ||
| 79 | algorithm | ||
| 80 | ✗ | tok := TOKEN(fileNm,TokenId.STRING,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 81 | then tok; | ||
| 82 | case 2 // #line 26 "lexerJSON.l" | ||
| 83 | algorithm | ||
| 84 | ✗ | tok := TOKEN(fileNm,TokenId.STRING,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 85 | then tok; | ||
| 86 | case 3 // #line 27 "lexerJSON.l" | ||
| 87 | algorithm | ||
| 88 | ✗ | tok := TOKEN(fileNm,TokenId.NUMBER,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 89 | then tok; | ||
| 90 | case 4 // #line 28 "lexerJSON.l" | ||
| 91 | algorithm | ||
| 92 | ✗ | tok := TOKEN(fileNm,TokenId.NUMBER,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 93 | then tok; | ||
| 94 | case 5 // #line 29 "lexerJSON.l" | ||
| 95 | algorithm | ||
| 96 | ✗ | tok := TOKEN(fileNm,TokenId.INTEGER,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 97 | then tok; | ||
| 98 | case 6 // #line 30 "lexerJSON.l" | ||
| 99 | algorithm | ||
| 100 | ✗ | tok := TOKEN(fileNm,TokenId.TRUE,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 101 | then tok; | ||
| 102 | case 7 // #line 31 "lexerJSON.l" | ||
| 103 | algorithm | ||
| 104 | ✗ | tok := TOKEN(fileNm,TokenId.FALSE,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 105 | then tok; | ||
| 106 | case 8 // #line 32 "lexerJSON.l" | ||
| 107 | algorithm | ||
| 108 | ✗ | tok := TOKEN(fileNm,TokenId.NULL,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 109 | then tok; | ||
| 110 | case 9 // #line 33 "lexerJSON.l" | ||
| 111 | algorithm | ||
| 112 | ✗ | tok := TOKEN(fileNm,TokenId.OBJECTBEGIN,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 113 | then tok; | ||
| 114 | case 10 // #line 34 "lexerJSON.l" | ||
| 115 | algorithm | ||
| 116 | ✗ | tok := TOKEN(fileNm,TokenId.OBJECTEND,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 117 | then tok; | ||
| 118 | case 11 // #line 36 "lexerJSON.l" | ||
| 119 | algorithm | ||
| 120 | ✗ | tok := TOKEN(fileNm,TokenId.ARRAYBEGIN,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 121 | then tok; | ||
| 122 | case 12 // #line 38 "lexerJSON.l" | ||
| 123 | algorithm | ||
| 124 | ✗ | tok := TOKEN(fileNm,TokenId.ARRAYEND,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 125 | then tok; | ||
| 126 | case 13 // #line 40 "lexerJSON.l" | ||
| 127 | algorithm | ||
| 128 | ✗ | tok := TOKEN(fileNm,TokenId.COMMA,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 129 | then tok; | ||
| 130 | case 14 // #line 41 "lexerJSON.l" | ||
| 131 | algorithm | ||
| 132 | ✗ | tok := TOKEN(fileNm,TokenId.COLON,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 133 | then tok; | ||
| 134 | case 15 // #line 43 "lexerJSON.l" | ||
| 135 | algorithm | ||
| 136 | then noToken; | ||
| 137 | case 16 // #line 45 "lexerJSON.l" | ||
| 138 | algorithm | ||
| 139 | ✗ | tok := TOKEN(fileNm,TokenId._NO_TOKEN,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 140 | errorTokens := tok :: errorTokens; | ||
| 141 | then noToken; | ||
| 142 | |||
| 143 | else | ||
| 144 | algorithm | ||
| 145 | ✗ | print("\nLexer unknown rule, action="+String(act)+"\n"); | |
| 146 | ✗ | tok := TOKEN(fileNm,TokenId._NO_TOKEN,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1); | |
| 147 | ✗ | print(printToken(tok)); | |
| 148 | ✗ | then fail(); | |
| 149 | end match; | ||
| 150 | end action; | ||
| 151 | |||
| 152 | type TokenId = enumeration( | ||
| 153 | _NO_TOKEN, | ||
| 154 | ARRAYBEGIN, | ||
| 155 | ARRAYEND, | ||
| 156 | COLON, | ||
| 157 | COMMA, | ||
| 158 | FALSE, | ||
| 159 | INTEGER, | ||
| 160 | NULL, | ||
| 161 | NUMBER, | ||
| 162 | OBJECTBEGIN, | ||
| 163 | OBJECTEND, | ||
| 164 | STRING, | ||
| 165 | TRUE | ||
| 166 | ); | ||
| 167 | |||
| 168 | uniontype Token | ||
| 169 | record TOKEN | ||
| 170 | String fileName; | ||
| 171 | TokenId id; | ||
| 172 | String fileContents; | ||
| 173 | Integer byteOffset,length; | ||
| 174 | Integer lineNumberStart; | ||
| 175 | Integer columnNumberStart; | ||
| 176 | Integer lineNumberEnd; | ||
| 177 | Integer columnNumberEnd; | ||
| 178 | end TOKEN; | ||
| 179 | end Token; | ||
| 180 | |||
| 181 | constant Token noToken = TOKEN("<NoFile>",TokenId._NO_TOKEN,"",0,0,0,0,0,0); | ||
| 182 | |||
| 183 | function printToken | ||
| 184 | input Token token; | ||
| 185 | output String strTk; | ||
| 186 | protected | ||
| 187 | TokenId id; | ||
| 188 | String contents; | ||
| 189 | Integer byteOffset,length; | ||
| 190 | algorithm | ||
| 191 | ✗ | TOKEN(id=id, fileContents=contents, byteOffset=byteOffset, length=length) := token; | |
| 192 | ✗ | contents := if length>0 then substring(contents,byteOffset,byteOffset+length-1) else ""; | |
| 193 | ✗ | strTk := "[TOKEN:" + String(id) + " '" + contents +"' (" + intString(token.lineNumberStart) + ":" + intString(token.columnNumberStart) + "-"+ intString(token.lineNumberEnd) + ":" + intString(token.columnNumberEnd) +")]"; | |
| 194 | end printToken; | ||
| 195 | |||
| 196 | function tokenContent | ||
| 197 | input Token token; | ||
| 198 | output String contents; | ||
| 199 | protected | ||
| 200 | Integer byteOffset,length; | ||
| 201 | algorithm | ||
| 202 | ✗ | TOKEN(fileContents=contents,byteOffset=byteOffset,length=length) := token; | |
| 203 | ✗ | contents := if length>0 then substring(contents,byteOffset,byteOffset+length-1) else ""; | |
| 204 | end tokenContent; | ||
| 205 | |||
| 206 | function tokenContentEq | ||
| 207 | input Token token1, token2; | ||
| 208 | output Boolean b; | ||
| 209 | protected | ||
| 210 | String contents1,contents2; | ||
| 211 | Integer offset1,length1,offset2,length2; | ||
| 212 | algorithm | ||
| 213 | ✗ | TOKEN(fileContents=contents1,byteOffset=offset1,length=length1) := token1; | |
| 214 | ✗ | TOKEN(fileContents=contents2,byteOffset=offset2,length=length2) := token2; | |
| 215 | // We do not need to know in which order to sort. If lengths differ, the tokens differ | ||
| 216 | ✗ | b := if length1 <> length2 then false else (0 == System.strcmp_offset(contents1, offset1, length1, contents2, offset2, length2)); | |
| 217 | end tokenContentEq; | ||
| 218 | |||
| 219 | function tokenSourceInfo | ||
| 220 | input Token token; | ||
| 221 | output SourceInfo info; | ||
| 222 | algorithm | ||
| 223 | info := match t as token | ||
| 224 | ✗ | case TOKEN() then SOURCEINFO(t.fileName, false, t.lineNumberStart, t.columnNumberStart, t.lineNumberEnd, t.columnNumberEnd, 0.0); | |
| 225 | end match; | ||
| 226 | end tokenSourceInfo; | ||
| 227 | |||
| 228 | protected | ||
| 229 | |||
| 230 | function lex "Scan starts the lexical analysis, load the tables and consume the program to output the tokens" | ||
| 231 | input String fileName "input source code file"; | ||
| 232 | input String contents; | ||
| 233 | output list<Token> tokens "return list of tokens"; | ||
| 234 | output list<Token> errorTokens={}; | ||
| 235 | protected | ||
| 236 | Integer startSt,i,cTok,currSt,pos,sPos,ePos,linenr,contentLen,numBacktrack,buffer,lineNrStart; | ||
| 237 | list<Integer> states; | ||
| 238 | import MetaModelica.Dangerous.listReverseInPlace; | ||
| 239 | import stringGet = MetaModelica.Dangerous.stringGetNoBoundsChecking; | ||
| 240 | algorithm | ||
| 241 | // load arrays | ||
| 242 | |||
| 243 | // Initialize the Env Variables | ||
| 244 | ✗ | startSt := 1; | |
| 245 | ✗ | currSt := 1; | |
| 246 | ✗ | pos := 1; | |
| 247 | ✗ | sPos := 0; | |
| 248 | ✗ | ePos := 0; | |
| 249 | ✗ | linenr := 1; | |
| 250 | ✗ | lineNrStart := 1; | |
| 251 | ✗ | buffer := 0; | |
| 252 | |||
| 253 | ✗ | states := {}; | |
| 254 | |||
| 255 | if (debug==true) then | ||
| 256 | print("\nLexer analyzer LexerCode..." + fileName + "\n"); | ||
| 257 | //printAny("\nLexer analyzer LexerCode..." + fileName + "\n"); | ||
| 258 | end if; | ||
| 259 | |||
| 260 | tokens := {}; | ||
| 261 | if (debug) then | ||
| 262 | print("\n TOTAL Chars:"); | ||
| 263 | print(intString(stringLength(contents))); | ||
| 264 | end if; | ||
| 265 | ✗ | contentLen := stringLength(contents); | |
| 266 | i := 1; | ||
| 267 | ✗ | while i <= contentLen loop | |
| 268 | ✗ | cTok := stringGet(contents,i); | |
| 269 | ✗ | (tokens,numBacktrack,startSt,currSt,pos,sPos,ePos,linenr,lineNrStart,buffer,states,errorTokens) := consume(cTok,tokens,contents,startSt,currSt,pos,sPos,ePos,linenr,lineNrStart,buffer,states,fileName,errorTokens); | |
| 270 | ✗ | i := i - numBacktrack + 1; | |
| 271 | end while; | ||
| 272 | ✗ | tokens := listReverseInPlace(tokens); | |
| 273 | ✗ | errorTokens := listReverseInPlace(errorTokens); | |
| 274 | end lex; | ||
| 275 | |||
| 276 | function consume | ||
| 277 | input Integer cp; | ||
| 278 | input list<Token> tokens; | ||
| 279 | input String fileContents; | ||
| 280 | input Integer startSt; | ||
| 281 | input Integer currSt,pos,sPos,ePos,linenr,inLineNrStart; | ||
| 282 | input Integer inBuffer; | ||
| 283 | input list<Integer> inStates; | ||
| 284 | input String fileName; | ||
| 285 | input list<Token> inErrorTokens; | ||
| 286 | output list<Token> resToken; | ||
| 287 | output Integer bkBuffer = 0; | ||
| 288 | output Integer mm_startSt; | ||
| 289 | output Integer mm_currSt; | ||
| 290 | output Integer mm_pos; | ||
| 291 | output Integer mm_sPos; | ||
| 292 | output Integer mm_ePos; | ||
| 293 | output Integer mm_linenr; | ||
| 294 | output Integer lineNrStart; | ||
| 295 | output Integer buffer; | ||
| 296 | output list<Integer> states; | ||
| 297 | output list<Token> errorTokens=inErrorTokens; | ||
| 298 | protected | ||
| 299 | Token tok; | ||
| 300 | Integer act,buffer2; | ||
| 301 | Integer c,baseCond; | ||
| 302 | algorithm | ||
| 303 | ✗ | mm_startSt := startSt; | |
| 304 | ✗ | mm_currSt := currSt; | |
| 305 | ✗ | mm_pos := pos; | |
| 306 | ✗ | mm_sPos := sPos; | |
| 307 | mm_ePos := ePos; | ||
| 308 | ✗ | mm_linenr := linenr; | |
| 309 | lineNrStart := inLineNrStart; | ||
| 310 | ✗ | buffer := inBuffer; | |
| 311 | ✗ | states := inStates; | |
| 312 | |||
| 313 | ✗ | baseCond := LexTable.yy_base[mm_currSt]; | |
| 314 | if (debug==true) then | ||
| 315 | print("\nPROGRAM:{" + intString(cp) + "} "); | ||
| 316 | print("\nBUFFER:{" + intString(buffer) + "} "); | ||
| 317 | print("base:" + intString(baseCond) + " st:" + intString(mm_currSt)+" "); | ||
| 318 | end if; | ||
| 319 | |||
| 320 | ✗ | buffer := buffer+1; | |
| 321 | ✗ | mm_pos := mm_pos+1; | |
| 322 | |||
| 323 | ✗ | if (cp==10) then | |
| 324 | ✗ | mm_linenr := mm_linenr+1; | |
| 325 | ✗ | mm_sPos := 0; | |
| 326 | else | ||
| 327 | ✗ | mm_sPos := mm_sPos+1; | |
| 328 | end if; | ||
| 329 | if (debug==true) then | ||
| 330 | print("\n[Reading:'" + intStringChar(cp) +"' at p:" + intString(mm_pos-1) + " line:"+ intString(mm_linenr) + " rPos:" + intString(mm_sPos) +"]"); | ||
| 331 | end if; | ||
| 332 | ✗ | c := LexTable.yy_ec[cp]; | |
| 333 | |||
| 334 | if (debug==true) then | ||
| 335 | print(" evalState Before[c" + intString(c) + ",s"+ intString(mm_currSt)+"]"); | ||
| 336 | end if; | ||
| 337 | ✗ | (mm_currSt,c) := evalState(mm_currSt,c); | |
| 338 | if (debug==true) then | ||
| 339 | print(" After[c" + intString(c) + ",s"+ intString(mm_currSt)+"]"); | ||
| 340 | end if; | ||
| 341 | ✗ | if (mm_currSt>0) then | |
| 342 | ✗ | mm_currSt := LexTable.yy_base[mm_currSt]; | |
| 343 | // print("BASE:"+ intString(mm_currSt)+"]"); | ||
| 344 | ✗ | mm_currSt := LexTable.yy_nxt[mm_currSt + c]; | |
| 345 | // print("NEXT:"+ intString(mm_currSt)+"]"); | ||
| 346 | else | ||
| 347 | ✗ | mm_currSt := LexTable.yy_nxt[c]; | |
| 348 | end if; | ||
| 349 | ✗ | states := mm_currSt::states; | |
| 350 | |||
| 351 | ✗ | baseCond := LexTable.yy_base[mm_currSt]; | |
| 352 | ✗ | if (baseCond==LexTable.yy_finish) then | |
| 353 | if (debug==true) then | ||
| 354 | print("\n[RESTORE=" + intString(LexTable.yy_accept[mm_currSt]) + "]"); | ||
| 355 | end if; | ||
| 356 | |||
| 357 | ✗ | (act, mm_currSt, mm_pos, mm_sPos, mm_linenr, buffer, bkBuffer, states) := findRule(fileContents, mm_currSt, mm_pos, mm_sPos, mm_ePos, mm_linenr, buffer, bkBuffer, states); | |
| 358 | |||
| 359 | if (debug==true) then | ||
| 360 | print("\nFound rule: " + String(act)); | ||
| 361 | end if; | ||
| 362 | |||
| 363 | ✗ | (tok,mm_startSt,buffer2,errorTokens) := action(act,mm_startSt,mm_currSt,mm_pos,mm_sPos,mm_ePos,mm_linenr,lineNrStart,buffer,fileName,fileContents,errorTokens); | |
| 364 | |||
| 365 | if (debug==true) then | ||
| 366 | print("\nDid action"); | ||
| 367 | end if; | ||
| 368 | |||
| 369 | ✗ | mm_currSt := mm_startSt; | |
| 370 | ✗ | states := {}; | |
| 371 | |||
| 372 | /* Either a token was output (get new positions for next token). Or a whitespace was emitted. */ | ||
| 373 | ✗ | if buffer <> buffer2 then | |
| 374 | ✗ | mm_ePos := mm_sPos; | |
| 375 | lineNrStart := linenr; | ||
| 376 | end if; | ||
| 377 | ✗ | buffer := buffer2; | |
| 378 | |||
| 379 | resToken := match tok | ||
| 380 | case TOKEN(id=TokenId._NO_TOKEN) then tokens; | ||
| 381 | else tok::tokens; | ||
| 382 | end match; | ||
| 383 | if(debug) then | ||
| 384 | print("\n CountTokens:" + intString(listLength(resToken))); | ||
| 385 | end if; | ||
| 386 | else | ||
| 387 | ✗ | bkBuffer := 0; // consume the character | |
| 388 | resToken := tokens; | ||
| 389 | end if; | ||
| 390 | |||
| 391 | end consume; | ||
| 392 | |||
| 393 | |||
| 394 | function findRule | ||
| 395 | input String fileContents; | ||
| 396 | input Integer currSt; | ||
| 397 | input Integer pos; | ||
| 398 | input Integer sPos; | ||
| 399 | input Integer mm_ePos; | ||
| 400 | input Integer linenr; | ||
| 401 | input Integer inBuffer; | ||
| 402 | input Integer inBkBuffer; | ||
| 403 | input list<Integer> inStates; | ||
| 404 | output Integer action; | ||
| 405 | output Integer mm_currSt; | ||
| 406 | output Integer mm_pos; | ||
| 407 | output Integer mm_sPos; | ||
| 408 | output Integer mm_linenr; | ||
| 409 | output Integer buffer; | ||
| 410 | output Integer bkBuffer; | ||
| 411 | output list<Integer> states; | ||
| 412 | protected | ||
| 413 | Integer lp,lp1,stCmp,cp; | ||
| 414 | Boolean st; | ||
| 415 | import arrayGet = MetaModelica.Dangerous.arrayGetNoBoundsChecking; // Bounds checked with debug=true | ||
| 416 | import stringGet = MetaModelica.Dangerous.stringGetNoBoundsChecking; | ||
| 417 | algorithm | ||
| 418 | mm_currSt := currSt; | ||
| 419 | mm_pos := pos; | ||
| 420 | mm_sPos := sPos; | ||
| 421 | mm_linenr := linenr; | ||
| 422 | buffer := inBuffer; | ||
| 423 | bkBuffer := inBkBuffer; | ||
| 424 | states := inStates; | ||
| 425 | |||
| 426 | ✗ | stCmp := listGet(states, 1); | |
| 427 | ✗ | lp := LexTable.yy_accept[stCmp]; | |
| 428 | ✗ | lp1 := LexTable.yy_accept[stCmp+1]; | |
| 429 | |||
| 430 | ✗ | st := intGt(lp,0) and intLt(lp,lp1); | |
| 431 | ✗ | if st then | |
| 432 | if debug then | ||
| 433 | checkArrayModelica(LexTable.yy_accept,stCmp,sourceInfo()); | ||
| 434 | checkArrayModelica(LexTable.yy_acclist,lp,sourceInfo()); | ||
| 435 | end if; | ||
| 436 | lp := LexTable.yy_accept[stCmp]; | ||
| 437 | ✗ | action := LexTable.yy_acclist[lp]; | |
| 438 | else | ||
| 439 | ✗ | cp := stringGet(fileContents,mm_pos-1); | |
| 440 | ✗ | buffer := buffer-1; | |
| 441 | ✗ | bkBuffer := bkBuffer+1; | |
| 442 | ✗ | mm_pos := mm_pos - 1; | |
| 443 | ✗ | mm_sPos := mm_sPos -1; | |
| 444 | ✗ | if (cp==10) then | |
| 445 | mm_sPos := mm_ePos; | ||
| 446 | ✗ | mm_linenr := mm_linenr-1; | |
| 447 | end if; | ||
| 448 | ✗ | mm_currSt::states := states; | |
| 449 | ✗ | (action, mm_currSt, mm_pos, mm_sPos, mm_linenr, buffer, bkBuffer, states) := findRule(fileContents, mm_currSt, mm_pos, mm_sPos, mm_ePos, mm_linenr, buffer, bkBuffer, states); | |
| 450 | end if; | ||
| 451 | end findRule; | ||
| 452 | |||
| 453 | function evalState | ||
| 454 | input Integer cState; | ||
| 455 | input Integer c; | ||
| 456 | output Integer new_state; | ||
| 457 | output Integer new_c; | ||
| 458 | protected | ||
| 459 | Integer cState1=cState; | ||
| 460 | Integer c1=c; | ||
| 461 | Integer val,val2,chk; | ||
| 462 | algorithm | ||
| 463 | ✗ | chk := LexTable.yy_base[cState1]; | |
| 464 | ✗ | chk := chk + c1; | |
| 465 | ✗ | val := LexTable.yy_chk[chk]; | |
| 466 | val2 := LexTable.yy_base[cState1] + c1; | ||
| 467 | ✗ | if cState1<>val then | |
| 468 | ✗ | cState1 := LexTable.yy_def[cState1]; | |
| 469 | ✗ | if cState1 >= LexTable.yy_limit then | |
| 470 | ✗ | c1 := LexTable.yy_meta[c1]; | |
| 471 | end if; | ||
| 472 | ✗ | if (cState1>0) then | |
| 473 | ✗ | (cState1,c1) := evalState(cState1,c1); | |
| 474 | end if; | ||
| 475 | end if; | ||
| 476 | new_state := cState1; | ||
| 477 | ✗ | new_c := c1; | |
| 478 | end evalState; | ||
| 479 | |||
| 480 | function checkArray<T> | ||
| 481 | input array<T> arr; | ||
| 482 | input Integer index; | ||
| 483 | input SourceInfo info; | ||
| 484 | protected | ||
| 485 | String filename; | ||
| 486 | Integer lineStart; | ||
| 487 | algorithm | ||
| 488 | ✗ | if index<1 or index>arrayLength(arr) then | |
| 489 | ✗ | SOURCEINFO(fileName=filename, lineNumberStart=lineStart) := info; | |
| 490 | ✗ | print("\n[" + filename + ":" + String(lineStart) + "]: checkArray failed: arrayLength="+String(arrayLength(arr))+" index=" + String(index) + "\n"); | |
| 491 | ✗ | fail(); | |
| 492 | end if; | ||
| 493 | end checkArray; | ||
| 494 | |||
| 495 | function checkArrayModelica | ||
| 496 | input array<Integer> arr; | ||
| 497 | input Integer index; | ||
| 498 | input SourceInfo info; | ||
| 499 | protected | ||
| 500 | String filename; | ||
| 501 | Integer lineStart; | ||
| 502 | algorithm | ||
| 503 | ✗ | if index<1 or index>arrayLength(arr) then | |
| 504 | ✗ | SOURCEINFO(fileName=filename, lineNumberStart=lineStart) := info; | |
| 505 | ✗ | print("\n[" + filename + ":" + String(lineStart) + "]: checkArray failed: arrayLength="+String(arrayLength(arr))+" index=" + String(index) + "\n"); | |
| 506 | ✗ | fail(); | |
| 507 | end if; | ||
| 508 | end checkArrayModelica; | ||
| 509 | |||
| 510 | package LexTable | ||
| 511 | constant Integer yy_limit = 46; | ||
| 512 | constant Integer yy_finish = 82; | ||
| 513 | constant array<Integer> yy_acclist = MetaModelica.Dangerous.listArrayLiteral({ | ||
| 514 | 17, 16, 15, 16, 16, 13, 16, 5, 16, 14, | ||
| 515 | 16, 11, 16, 12, 16, 16, 16, 16, 9, 16, | ||
| 516 | 10, 16, 15, 1, 5, 2, 3, 4, 8, 6, | ||
| 517 | 3, 7 | ||
| 518 | }); | ||
| 519 | constant array<Integer> yy_accept = MetaModelica.Dangerous.listArrayLiteral({ | ||
| 520 | 1, 1, 1, 2, 3, 5, 6, 8, 10, 12, | ||
| 521 | 14, 16, 17, 18, 19, 21, 23, 24, 24, 25, | ||
| 522 | 25, 25, 26, 26, 26, 26, 26, 27, 27, 28, | ||
| 523 | 28, 29, 29, 29, 29, 29, 29, 29, 30, 31, | ||
| 524 | 31, 31, 32, 33, 33, 33 | ||
| 525 | }); | ||
| 526 | constant array<Integer> yy_ec = MetaModelica.Dangerous.listArrayLiteral({ | ||
| 527 | 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, | ||
| 528 | 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, | ||
| 529 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 530 | 1, 2, 1, 3, 1, 1, 1, 1, 1, 1, | ||
| 531 | 1, 1, 4, 5, 6, 7, 8, 9, 9, 9, | ||
| 532 | 9, 9, 9, 9, 9, 9, 9, 10, 1, 1, | ||
| 533 | 1, 1, 1, 1, 11, 11, 11, 11, 12, 11, | ||
| 534 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 535 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 536 | 13, 14, 15, 1, 1, 1, 16, 17, 11, 11, | ||
| 537 | |||
| 538 | 18, 19, 1, 1, 1, 1, 1, 20, 1, 21, | ||
| 539 | 1, 1, 1, 22, 23, 24, 25, 1, 1, 1, | ||
| 540 | 1, 1, 26, 1, 27, 1, 1, 1, 1, 1, | ||
| 541 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 542 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 543 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 544 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 545 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 546 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 547 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 548 | |||
| 549 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 550 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 551 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 552 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 553 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 554 | 1, 1, 1, 1, 1 | ||
| 555 | }); | ||
| 556 | constant array<Integer> yy_meta = MetaModelica.Dangerous.listArrayLiteral({ | ||
| 557 | 1, 1, 2, 1, 1, 1, 1, 2, 3, 1, | ||
| 558 | 3, 3, 1, 2, 1, 3, 4, 3, 4, 1, | ||
| 559 | 2, 2, 1, 2, 2, 1, 1 | ||
| 560 | }); | ||
| 561 | constant array<Integer> yy_base = MetaModelica.Dangerous.listArrayLiteral({ | ||
| 562 | 0, 0, 81, 82, 78, 25, 82, 22, 82, 82, | ||
| 563 | 82, 63, 53, 55, 82, 82, 74, 27, 82, 50, | ||
| 564 | 65, 26, 39, 53, 52, 37, 82, 0, 37, 45, | ||
| 565 | 43, 27, 27, 24, 0, 47, 19, 82, 82, 0, | ||
| 566 | 27, 23, 82, 0, 82, 56, 59, 61, 63, 65, | ||
| 567 | 67 | ||
| 568 | }); | ||
| 569 | constant array<Integer> yy_def = MetaModelica.Dangerous.listArrayLiteral({ | ||
| 570 | 45, 1, 45, 45, 45, 46, 45, 45, 45, 45, | ||
| 571 | 45, 45, 45, 45, 45, 45, 45, 46, 45, 47, | ||
| 572 | 45, 45, 45, 45, 45, 45, 45, 48, 45, 45, | ||
| 573 | 45, 45, 45, 45, 49, 45, 45, 45, 45, 50, | ||
| 574 | 45, 45, 45, 51, 0, 45, 45, 45, 45, 45, | ||
| 575 | 45 | ||
| 576 | }); | ||
| 577 | constant array<Integer> yy_nxt = MetaModelica.Dangerous.listArrayLiteral({ | ||
| 578 | 4, 5, 6, 4, 7, 4, 4, 4, 8, 9, | ||
| 579 | 4, 4, 10, 4, 11, 4, 4, 4, 12, 4, | ||
| 580 | 13, 4, 4, 14, 4, 15, 16, 19, 21, 27, | ||
| 581 | 22, 42, 21, 23, 22, 42, 43, 23, 20, 23, | ||
| 582 | 20, 39, 30, 23, 30, 29, 38, 31, 36, 37, | ||
| 583 | 41, 31, 41, 31, 36, 42, 18, 18, 18, 18, | ||
| 584 | 18, 34, 18, 35, 35, 40, 40, 44, 44, 18, | ||
| 585 | 18, 33, 32, 29, 28, 17, 26, 25, 24, 17, | ||
| 586 | 45, 3, 45, 45, 45, 45, 45, 45, 45, 45, | ||
| 587 | 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, | ||
| 588 | |||
| 589 | 45, 45, 45, 45, 45, 45, 45, 45, 45 | ||
| 590 | }); | ||
| 591 | constant array<Integer> yy_chk = MetaModelica.Dangerous.listArrayLiteral({ | ||
| 592 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 593 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 594 | 1, 1, 1, 1, 1, 1, 1, 6, 8, 18, | ||
| 595 | 8, 42, 22, 8, 22, 41, 37, 22, 6, 8, | ||
| 596 | 18, 34, 23, 22, 23, 29, 33, 23, 29, 32, | ||
| 597 | 36, 31, 36, 30, 29, 36, 46, 46, 46, 46, | ||
| 598 | 47, 26, 47, 48, 48, 49, 49, 50, 50, 51, | ||
| 599 | 51, 25, 24, 21, 20, 17, 14, 13, 12, 5, | ||
| 600 | 3, 45, 45, 45, 45, 45, 45, 45, 45, 45, | ||
| 601 | 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, | ||
| 602 | |||
| 603 | 45, 45, 45, 45, 45, 45, 45, 45, 45 | ||
| 604 | }); | ||
| 605 | |||
| 606 | end LexTable; | ||
| 607 | |||
| 608 | |||
| 609 | |||
| 610 | annotation(__OpenModelica_Interface="util"); | ||
| 611 | |||
| 612 | |||
| 613 | end LexerJSON; | ||
| 614 |