<lexer>
  <config>
    <name>RPGLE</name>
    <alias>SQLRPGLE</alias>
    <alias>RPG IV</alias>
    <filename>*.RPGLE</filename>
    <filename>*.rpgle</filename>
    <filename>*.SQLRPGLE</filename>
    <filename>*.sqlrpgle</filename>
    <mime_type>text/x-rpgle</mime_type>
    <mime_type>text/x-sqlrpgle</mime_type>
    <case_insensitive>true</case_insensitive>
    <analyse>
      <regex pattern="^\*\*free$" score="0.9"/>
      <regex pattern="ctl-opt" score="0.9"/>
      <regex pattern="dcl-(ds|s|f|proc|pr|pi)" score="0.9"/>
      <regex pattern="\*in[0-9][0-9]" score="0.5"/>
    </analyse>
  </config>
  <rules>
    <state name="root">
      <rule pattern="\/\/.*">
        <token type="Comment"/>
      </rule>
      <rule pattern="^\*\*free$">
        <token type="CommentSpecial"/>
      </rule>
      <rule pattern="\*\*((ctdata|ftrans|altseq)(\s+\w+)?)?(\r|\n|\r\n)">
        <token type="CommentSpecial"/> <!-- compile-time arrays at the end of the file, introduced by ** -->
        <push state="compile-time-array"/>
      </rule>
      <rule pattern="(\*(all(g|oc|ow|sep|thread|u|x)?|altseq|alwblanknum|ascii|astfill|aut[lo]|basic|blank(s)?|caller|cancl|cdmy(0)?|change|char|cl|cmd(y|y0)?|cnowiden|cntrld|col|comp(at)?|concurrent|constants|constructor|convert|copyright|crt(bndrpg|rpgmod)|ct(data|lbdy|lspec)|cur(lib|sym)|cvt(data)?|cwiden|cymd(0)?|data|date(time)?|day(s)?|dclcase|ddm|debugio|dec|delete|det[cl]|dft|diag|dmy|dtaara|dump|end|entry(exit)?|equate|escape|eur(0)?|exact|exclude|excp|exp(dds|include)|ext(desc|dft)?|file(s)?|first|ftrans|full|gen|getin|graph(ic)?|hex|hival|hms|hours|ignore|ilerpg|in([0-9]{2}|H[1-9]|K[A-Y]|L[1-9]|LR|O[AGV]|U[1-8])?|INFO|INHERIT|INIT|INP(UT(ONLY|PACKED)?)?|INZ(OFL|SR)|ISO(0)?|JAVA|JIS|JOB(RUN(0|MIX|_DBCS|_JAVA|_MIXED)?)?|JUL|KEEP|KEY|LANGID(SHR|UNQ)|LDA|LGL|LIB(L|RCRTAUT)|LIKE(DS)?|LIST|LOCK|LONG(JOBRUN(0)?|JUL(0)?)|LOVAL|LVL[12]|MAX(DIGITS)?|MDY(0)?|MINUTES|MIXED(ASCII|EBCDIC)|MN|MODE|MODULE|MONTH(S)?|MS(ECONDS)?|M[A-Z]{3}[0-9]{4}|NATURAL|NEW|NEXT|NO(ALLOW|CHGDSLEN|COL|CVT(DATA)?|DATETIME|DEBUGIO|EXACT|EXPDDS|EXPINCLUDE|EXT|GEN|GRAPHIC|IND|INPUTPACKED|INZOFL|KEY|PASS|RMVCOMMENT|SECLVL|SHOWCPY|SHOWSKP|SRCSTMT|UNREF|VARCHAR|VARGRAPHIC|XREF|ZONED)?|NONE|NOTIFY|NULL(IND)?|OFF|OFL|OMIT|ON(EXIT|LY)?|OPCODE|OUT(PUT)?|OWNER|PARM(S)?|PCML|PDA|PEP|PGM(BDY)?|PLACE|PROC|PROGRAM|PSSR|RECORD|REQUIRE|RESDECPOS|RETVAL|RIGHTADJ|RMVCOMMENT|ROUTINE|SECLVL|SECONDS|SELF|SERIALIZE|SHOW(CPY|SKP)|SIZE|SNGLVL|SRC(MBRTXT|STMT)?|START|STATUS|STDCHARSIZE|STGMDL|STRICTKEYS|STRING|SYS|TBL|TERASPACE|TERM|THREAD_(CONCURRENT|SERIALIZE)|TOT[CL]|TRIM|UCS2|UNIQUE|UNREF|UNSET|UPDATE|USA(0)?|USE(DECEDIT)?|USER|USR(CTL|SPC)|UTF(8|16)?|V[0-9]R[0-9]M[0-9]|V[678]|VAR(CHAR|GRAPHIC|SIZE)?|WARN|XMLSAX|XML_(ATTR_(CHARS|NAME|PREDEF_REF|UCS2_REF)|CHARS|COMMENT|DOCTYPE_DECL|ENCODING_DECL|END_(ATTR|CDATA|DOCUMENT|ELEMENT)|EXCEPTION|PI_(DATA|TARGET)|PREDEF_REF|STANDALONE_DECL|START_(CDATA|DOCUMENT|ELEMENT)|UCS2_REF|UNKNOWN_(ATTR_REF|REF)|VERSION_INFO)|XREF|YEAR(S)?|YES|YMD(0)?|ZERO(S)?|ZONED|[DHMNSY]))\b">
        <token type="Literal"/> <!-- Special values -->
      </rule>
      <rule pattern="\bexec\s+sql\b"> <!-- embedded SQL -->
        <token type="Keyword"/>
        <push state="exec-sql"/>
      </rule>
      <rule pattern="(%(abs|addr|alloc|bitand|bitnot|bitor|bitxor|char|charcount|check|checkr|concat|concatarr|data|date|days|dec|dech|decpos|diff|div|editc|editflt|editw|elem|eof|equal|error|fields|float|found|gen|graph|handler|hival|hours|int|inth|kds|left|len|list|lookup(lt|ge|gt|le)?|loval|lower|max|maxarr|min|minutes|minarr|months|mseconds|msg|nullind|occur|omitted|open|paddr|parms|parmnum|parser|passed|proc|range|realloc|rem|replace|right|scan|scanr|scanrpl|seconds|shtdn|size|split|sqrt|status|str|subarr|subdt|subst|target|this|time|timestamp|tlookup(lt|ge|gt|le)?|trim(l|r)?|ucs2|uns|unsh|upper|xfoot|xlate|xml|years))\b">
        <token type="NameFunctionMagic"/> <!-- builtin functions -->
      </rule>
      <rule pattern="\b(ind|int|uns|(var)?char|bindec|float|packed|zoned|time(stamp)?|date|pointer|clob|blob|(var)?graph|object|(var)?ucs2)\b">
        <token type="KeywordType"/> <!-- variable types -->
      </rule>
      <rule pattern="\b(dcl\-(ds|pi|proc|pr|[csf])|end\-(ds|pi|proc|pr)|ctl\-opt|const|value|to|downto|not)\b">
        <token type="Keyword"/> <!-- Syntax keywords -->
      </rule>
      <rule pattern="\b(acq|add|adddur|alloc|and(gt|lt|eq|ne|ge|le)?|begsr|bitoff|biton|cab(gt|lt|eq|ne|ge|le)?|call(b|p)?|cas(gt|lt|eq|ne|ge|le)?|cat|chain|check|checkr|clear|close|commit|comp|data-gen|data-into|dealloc|define|delete|div|do((u|w)(gt|lt|eq|ne|ge|le)?)?|dsply|dump|else(if)?|end(cs|do|for|if|mon|sl|sr)?|eval(r|-corr)?|except|exfmt|exsr|extrct|feod|for(-each)?|force|goto|if(gt|lt|eq|ne|ge|le)?|in|iter|kfld|klist|leave(sr)?|lookup|m(hh|hl|lh|ll)zo|monitor|move[al]?|mult|mvr|next|occur|on-(error|excp|exit)|open|or(gt|lt|eq|ne|ge|le)?|other|out|parm|plist|post|read(c|e|p|pe)?|realloc|rel|reset|return|rolbk|scan|select|set(gt|ll|off|on)|shtdn|snd-msg|sorta|sqrt|sub(dur|st)?|tag|test[bnz]?|time|unlock|update|when(gt|lt|eq|ne|ge|le)?|when-i[ns]|write|xfoot|slate|xml-(into|sax)|z-(add|sub))\b">
        <token type="Keyword"/> <!-- Operation codes -->
      </rule>
      <rule pattern="\b(alloc|altseq|ccsid|copy(nest|right)|cursym|dat(edit|fmt)|debug|dec(edit|prec)|dftname|expropts|extbinint|fltdiv|formsalign|ftrans|intprec|(no)?main|openopt|thread|timfmt|actgrp|alwnull|aut|bnddir|cvtopt|dateyy|dftactgrp|enbpfrcol|fixnbr|genlvl|indent|langid|optimize|option|pgminfo|prfdta|reqprexp|strseq|stgmdl|text|truncnbr|usrprf)\b">
        <token type="KeywordReserved"/> <!-- ctl-opt (former H spec) -->
      </rule>
      <rule pattern="\b(alias|block|commit|charcount|data|datfmt|devid|disk|ext(desc|file|ind|mbr)|form(len|ofl)|handler|ignore|include|in(dds|fds|fsr)|keyed|keyloc|likefile|maxdev|oflind|pass|pgmname|plist|prefix|printer|prtctl|qualified|rafdata|recno|rename|save(ds|ind)|seq|sfile|sln|special|static|template|timfmt|usage|usropn|workstn)\b">
        <token type="KeywordReserved"/> <!-- dcl-f (former F spec) -->
      </rule>
      <rule pattern="\b(\*(yes|no|natural|stdcharsize|(no)?cvt|ext(desc)?|inu[1-8]|char|only|file|noind|ext|compat|input|output|update|delete))\b">
        <token type="Literal"/> <!-- F spec special values-->
      </rule>
      <rule pattern="\b(alias|align|alt|altseq|ascend|based|ccsid|class|const|ctdata|datfmt|descend|dim|dtaara|export|ext(fld|fmt|name|pgm|proc)?|fromfile|import|inz|len|like(ds|file|rec)?|noopt|nullind|occurs|opdesc|options|overlay|overload|packeven|perrcd|pos|prefix|procptr|psds|qualified|reqproto|rtnparm|samepos|static|template|timfmt|tofile|value|varying)\b">
        <token type="KeywordReserved"/> <!-- Other keywords (not operation codes nor ctl-opt/H spec) -> mostly used with variables -->
      </rule>
      <rule pattern="(/(copy|define|eject|else|elseif|end-exec|end-free|endif|eof|exec|free|if|include|restore|set|space|title|undefine))\b">
        <token type="CommentPreproc"/> <!-- Preprocessor instructions -->
      </rule>
      <rule pattern="\b([0-9]+((\.[0-9]?)(e[+-][0-9]+)?)?)\b">
        <token type="LiteralNumber"/>
      </rule>
      <rule pattern="\bx'[0-9a-fA-F]*'">
        <token type="LiteralString"/> <!-- Hex string -->
      </rule>
      <rule pattern="'(''|[^'])*'">
        <token type="LiteralString"/>
      </rule>
      <rule pattern="[,:;\(\)\.]+">
        <token type="Punctuation"/>
      </rule>
      <rule pattern="((\*\*)|(&lt;&gt;)|=|([&lt;&gt;\+\-\*\/]=?))+">
        <token type="Operator"/> <!-- Arithmetic operators -->
      </rule>
      <rule pattern="\s">
        <token type="TextWhitespace"/>
      </rule>
      <rule pattern=".">
        <token type="Text"/>
      </rule>
    </state>
    <state name="exec-sql">
      <rule pattern=';'>
        <token type="Punctuation"/>
        <pop depth="1"/>
      </rule>
      <rule pattern="\s+">
        <token type="TextWhitespace"/>
      </rule>
      <rule pattern="--.*\n?">
        <token type="CommentSingle"/>
      </rule>
      <rule pattern="/\*">
        <token type="CommentMultiline"/>
        <push state="sql-multiline-comments"/>
      </rule>
      <rule pattern="&#39;">
        <token type="LiteralStringSingle"/>
        <push state="sql-string"/>
      </rule>
      <rule pattern="&#34;">
        <token type="LiteralStringDouble"/>
        <push state="sql-double-string"/>
      </rule>
      <rule pattern="(DATETIME_INTERVAL_PRECISION|PARAMETER_SPECIFIC_CATALOG|PARAMATER_ORDINAL_POSITION|USER_DEFINED_TYPE_CATALOG|PARAMATER_SPECIFIC_SCHEMA|TRANSACTIONS_ROLLED_BACK|USER_DEFINED_TYPE_SCHEMA|PARAMETER_SPECIFIC_NAME|DATETIME_INTERVAL_CODE|TRANSACTIONS_COMMITTED|USER_DEFINED_TYPE_NAME|CHARACTER_SET_CATALOG|DYNAMIC_FUNCTION_CODE|COMMAND_FUNCTION_CODE|RETURNED_OCTET_LENGTH|MESSAGE_OCTET_LENGTH|CHARACTER_SET_SCHEMA|CONSTRAINT_CATALOG|TRANSACTION_ACTIVE|CHARACTER_SET_NAME|CURRENT_TIMESTAMP|CONSTRAINT_SCHEMA|COLLATION_CATALOG|RETURNED_SQLSTATE|DYNAMIC_FUNCTION|CONDITION_NUMBER|CHARACTER_LENGTH|COMMAND_FUNCTION|COLLATION_SCHEMA|CHARACTERISTICS|TRIGGER_CATALOG|CONNECTION_NAME|SUBCLASS_ORIGIN|RETURNED_LENGTH|TIMEZONE_MINUTE|CONSTRAINT_NAME|ROUTINE_CATALOG|TRIGGER_SCHEMA|ROUTINE_SCHEMA|LOCALTIMESTAMP|IMPLEMENTATION|PARAMATER_NAME|MESSAGE_LENGTH|PARAMETER_MODE|COLLATION_NAME|TIMEZONE_HOUR|SPECIFIC_NAME|DETERMINISTIC|CORRESPONTING|AUTHORIZATION|INSTANTIABLE|CURRENT_TIME|CURRENT_USER|ROUTINE_NAME|NOCREATEUSER|MESSAGE_TEXT|SQLEXCEPTION|CATALOG_NAME|SESSION_USER|CLASS_ORIGIN|CURRENT_ROLE|SPECIFICTYPE|SERIALIZABLE|CURRENT_DATE|OCTET_LENGTH|CURRENT_PATH|TRIGGER_NAME|CHAR_LENGTH|SYSTEM_USER|REFERENCING|UNENCRYPTED|COLUMN_NAME|SQLWARNINIG|DIAGNOSTICS|CURSOR_NAME|SERVER_NAME|INSENSITIVE|SCHEMA_NAME|UNCOMMITTED|TRANSACTION|CONSTRUCTOR|LANCOMPILER|CARDINALITY|CONSTRAINTS|TRANSLATION|CHECKPOINT|CONSTRAINT|CONNECTION|PRIVILEGES|COMPLETION|CONVERSION|DELIMITERS|TABLE_NAME|INDITCATOR|INITIALIZE|DESCRIPTOR|REPEATABLE|CREATEUSER|DEFERRABLE|DESTRUCTOR|PROCEDURAL|DICTIONARY|DISCONNECT|TRANSFORMS|KEY_MEMBER|BIT_LENGTH|ASYMMETRIC|ASSIGNMENT|ASENSITIVE|OVERRIDING|PARAMETERS|REFERENCES|ORDINALITY|NOCREATEDB|STATISTICS|DEALLOCATE|SAVE_POINT|RECURSIVE|STRUCTURE|SUBSTRING|IMMEDIATE|GENERATED|SYMMETRIC|STATEMENT|INCREMENT|IMMUTABLE|INCLUDING|COMMITTED|TEMPORARY|INITIALLY|TERMINATE|PRECISION|DELIMITER|TIMESTAMP|INTERSECT|ISOLATION|TRANSFORM|TRANSLATE|ROW_COUNT|ASSERTION|PARAMETER|EXCLUSIVE|LOCALTIME|VALIDATOR|AGGREGATE|EXCLUDING|SENSITIVE|EXCEPTION|ENCRYPTED|OPERATION|HIERARCHY|COLLATION|PROCEDURE|CONTINUE|ENCODING|MINVALUE|SPECIFIC|ABSOLUTE|SECURITY|WHENEVER|EXISTING|VOLATILE|MAXVALUE|EXTERNAL|NULLABLE|VARIABLE|SQLERROR|DISTINCT|DISPATCH|END-EXEC|LOCATION|ALLOCATE|OVERLAPS|UNLISTEN|ROLLBACK|TRUNCATE|DESCRIBE|SQLSTATE|BACKWARD|FUNCTION|LANGUAGE|KEY_TYPE|CASCADED|POSITION|TRAILING|DEFERRED|RELATIVE|DEFAULTS|COALSECE|PREORDER|GROUPING|MODIFIES|INHERITS|PRESERVE|DATABASE|RESTRICT|IDENTITY|TEMPLATE|NATIONAL|CONTAINS|CREATEDB|IMPLICIT|OPERATOR|CONVERT|CURRENT|CONNECT|RECHECK|PRIMARY|STORAGE|DECLARE|DEFAULT|HANDLER|COLLATE|PREPARE|REINDEX|GRANTED|CHECKED|POSTFIX|REPLACE|INSTEAD|CATALOG|RESTART|INVOKER|PLACING|PENDANT|DEFINED|ITERATE|PARTIAL|CASCADE|BREADTH|GENERAL|TRIGGER|SESSION|BETWEEN|DEFINER|LATERAL|LEADING|RETURNS|TRUSTED|UNKNOWN|FORWARD|UNNAMED|OVERLAY|FORTRAN|ANALYZE|OPTIONS|ANALYSE|FOREIGN|ROUTINE|LOCATOR|DESTROY|SUBLIST|VERBOSE|EXTRACT|NOTNULL|EXPLAIN|VERSION|SQLCODE|EXECUTE|NOTHING|DYNAMIC|WITHOUT|SIMILAR|NATURAL|COMMENT|CLUSTER|PASCAL|SOURCE|EQUALS|CALLED|ESCAPE|EXCEPT|SELECT|ISNULL|DOMAIN|SEARCH|SCROLL|SIMPLE|BITVAR|MINUTE|EXISTS|SCHEMA|ATOMIC|METHOD|NOTIFY|ACCESS|UNIQUE|ROLLUP|NULLIF|OBJECT|STABLE|COLUMN|REVOKE|OFFSET|COMMIT|MODIFY|FREEZE|DELETE|RETURN|RESULT|UNNEST|OPTION|GLOBAL|VALUES|RENAME|SYSTEM|STATIC|UPDATE|OUTPUT|LISTEN|STDOUT|STRICT|PUBLIC|IGNORE|PREFIX|SECOND|CREATE|LENGTH|BEFORE|HAVING|INSERT|VACUUM|CURSOR|ELSIF|USING|ALTER|STYPE|CYCLE|LARGE|INPUT|CROSS|INOUT|INNER|INFIX|INDEX|LEVEL|USAGE|ILIKE|VALID|OWNER|GRANT|READS|UPPER|LIMIT|OUTER|STDIN|SYSID|GROUP|ALIAS|ORDER|UNTIL|LOCAL|RESET|START|COUNT|LOWER|TABLE| TEMP|PRIOR|AFTER|STATE|ADMIN|RIGHT|COBOL|FOUND|MATCH|FORCE|ABORT|FIRST|FINAL|CLOSE|DEREF|FETCH|WHERE|FALSE|SCALE|BEGIN|CLASS|TOAST|WRITE|NCLOB|NCHAR|CHECK|CHAIN|SPACE|NAMES|EVERY|MUMPS|CACHE|UNION|UNDER|SETOF|MONTH|SHARE|SCOPE|TREAT|SHOW|SIZE|SOME|SETS|SELF|ELSE|EACH|DROP|TYPE|FROM|RULE|DESC|ROWS|ZONE|ROLE|TRUE|FREE|FULL|GOTO|TRIM|HOLD|HOST|DATA|READ|INTO|USER|JOIN|CUBE|LAST|LEFT|LESS|LIKE|LOAD|LOCK|OPEN|COPY|ONLY|OIDS|VIEW|WHEN|THAN|THEN|NULL|NONE|WITH|WORK|NEXT|YEAR|MODE|CAST|CASE|MOVE|CALL|MORE|BOTH|EXEC|CLOB|OUT|MOD|ARE|SUM|DAY|GET|AVG|NEW|SQL|ABS|MIN|ASC|END|ROW|NOT|FOR|ANY|PLI|MAX|REF|MAP|ADA|KEY|AND|ADD|ALL|OLD|OFF|PAD|SET|OR|ON|TO|IS|OF|IN|IF|GO|AS|DO|AT|NO|BY|C|G)\b">
        <token type="Keyword"/>
      </rule>
      <rule pattern="(CHARACTER|SMALLINT|INTERVAL|DECIMAL|SERIAL8|VARYING|BOOLEAN|VARCHAR|INTEGER|NUMERIC|SERIAL|BINARY|BIGINT|NUMBER|FLOAT|ARRAY|TEXT|REAL|INT8|DATE|CHAR|BLOB|DEC|BIT|INT)\b">
        <token type="NameBuiltin"/>
      </rule>
      <rule pattern="[+*/&lt;&gt;=~!@#%^&amp;|`?-]">
        <token type="Operator"/>
      </rule>
      <rule pattern="[0-9]+">
        <token type="LiteralNumberInteger"/>
      </rule>
      <rule pattern="[a-z_][\w$]*">
        <token type="Name"/>
      </rule>
      <rule pattern="[;:()\[\],.]">
        <token type="Punctuation"/>
      </rule>
    </state>
    <state name="sql-multiline-comments">
      <rule pattern="/\*">
        <token type="CommentMultiline"/>
        <push state="sql-multiline-comments"/>
      </rule>
      <rule pattern="\*/">
        <token type="CommentMultiline"/>
        <pop depth="1"/>
      </rule>
      <rule pattern="[^/*]+">
        <token type="CommentMultiline"/>
      </rule>
      <rule pattern="[/*]">
        <token type="CommentMultiline"/>
      </rule>
    </state>
    <state name="sql-string">
      <rule pattern="[^&#39;]+">
        <token type="LiteralStringSingle"/>
      </rule>
      <rule pattern="&#39;&#39;">
        <token type="LiteralStringSingle"/>
      </rule>
      <rule pattern="&#39;">
        <token type="LiteralStringSingle"/>
        <pop depth="1"/>
      </rule>
    </state>
    <state name="sql-double-string">
      <rule pattern="[^&#34;]+">
        <token type="LiteralStringDouble"/>
      </rule>
      <rule pattern="&#34;&#34;">
        <token type="LiteralStringDouble"/>
      </rule>
      <rule pattern="&#34;">
        <token type="LiteralStringDouble"/>
        <pop depth="1"/>
      </rule>
    </state>
    <state name="compile-time-array">
      <rule pattern="[^\r\n]*(\r|\n|\r\n)?">
        <token type="CommentSpecial"/>
      </rule>
    </state>
  </rules>
</lexer>
