Update ABAP syntax (#1)

General update to ABAP 7.55 syntax, bug fixes, enhancements
This commit is contained in:
Marc Bernard 2021-10-04 09:59:08 -04:00 committed by GitHub
parent 1b8581c9aa
commit b39800cf5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1377 additions and 956 deletions

View file

@ -40,7 +40,7 @@ testTokenization('abap', [
{ startIndex: 2, type: '' },
{ startIndex: 3, type: 'number.abap' },
{ startIndex: 4, type: '' },
{ startIndex: 5, type: 'operator.abap' },
{ startIndex: 5, type: 'key.abap' },
{ startIndex: 6, type: '' },
{ startIndex: 7, type: 'number.abap' },
{ startIndex: 8, type: 'delimiter.abap' }
@ -121,7 +121,7 @@ testTokenization('abap', [
{ startIndex: 6, type: '' },
{ startIndex: 7, type: 'keyword.abap' },
{ startIndex: 9, type: '' },
{ startIndex: 10, type: 'operator.abap' },
{ startIndex: 10, type: 'keyword.abap' },
{ startIndex: 13, type: '' },
{ startIndex: 14, type: 'keyword.abap' },
{ startIndex: 21, type: 'delimiter.abap' }
@ -156,11 +156,11 @@ testTokenization('abap', [
tokens: [
{ startIndex: 0, type: 'identifier.abap' },
{ startIndex: 3, type: '' },
{ startIndex: 4, type: 'operator.abap' },
{ startIndex: 4, type: 'key.abap' },
{ startIndex: 5, type: '' },
{ startIndex: 6, type: 'keyword.abap' },
{ startIndex: 10, type: '' },
{ startIndex: 11, type: 'operator.abap' },
{ startIndex: 11, type: 'key.abap' },
{ startIndex: 12, type: 'delimiter.parenthesis.abap' },
{ startIndex: 13, type: '' },
{ startIndex: 14, type: 'number.abap' },
@ -178,7 +178,7 @@ testTokenization('abap', [
{ startIndex: 5, type: '' },
{ startIndex: 6, type: 'identifier.abap' },
{ startIndex: 9, type: '' },
{ startIndex: 12, type: 'identifier.abap' },
{ startIndex: 10, type: 'comment.abap' },
{ startIndex: 18, type: 'delimiter.abap' }
]
}
@ -189,7 +189,7 @@ testTokenization('abap', [
tokens: [
{ startIndex: 0, type: 'keyword.abap' },
{ startIndex: 6, type: '' },
{ startIndex: 7, type: 'operator.abap' },
{ startIndex: 7, type: 'key.abap' },
{ startIndex: 8, type: '' },
{ startIndex: 9, type: 'keyword.abap' },
{ startIndex: 13, type: '' },
@ -197,10 +197,164 @@ testTokenization('abap', [
{ startIndex: 19, type: '' },
{ startIndex: 20, type: 'keyword.abap' },
{ startIndex: 24, type: '' },
{ startIndex: 25, type: 'operator.abap' },
{ startIndex: 26, type: 'identifier.abap' },
{ startIndex: 25, type: 'identifier.abap' },
{ startIndex: 29, type: 'delimiter.abap' }
]
}
],
[
{
line: 'li = lines( itab ).',
tokens: [
{ startIndex: 0, type: 'identifier.abap' },
{ startIndex: 2, type: '' },
{ startIndex: 3, type: 'key.abap' },
{ startIndex: 4, type: '' },
{ startIndex: 5, type: 'keyword.abap' },
{ startIndex: 10, type: 'delimiter.parenthesis.abap' },
{ startIndex: 11, type: '' },
{ startIndex: 12, type: 'identifier.abap' },
{ startIndex: 16, type: '' },
{ startIndex: 17, type: 'delimiter.parenthesis.abap' },
{ startIndex: 18, type: 'delimiter.abap' }
]
}
],
[
{
line: "foo = 'bar' && 'baz'.",
tokens: [
{ startIndex: 0, type: 'identifier.abap' },
{ startIndex: 3, type: '' },
{ startIndex: 4, type: 'key.abap' },
{ startIndex: 5, type: '' },
{ startIndex: 6, type: 'string.abap' },
{ startIndex: 11, type: '' },
{ startIndex: 12, type: 'key.abap' },
{ startIndex: 14, type: '' },
{ startIndex: 15, type: 'string.abap' },
{ startIndex: 20, type: 'delimiter.abap' }
]
}
],
[
{
line: 'DATA num TYPE n.',
tokens: [
{ startIndex: 0, type: 'keyword.abap' },
{ startIndex: 4, type: '' },
{ startIndex: 5, type: 'identifier.abap' },
{ startIndex: 8, type: '' },
{ startIndex: 9, type: 'keyword.abap' },
{ startIndex: 13, type: '' },
{ startIndex: 14, type: 'type.abap' },
{ startIndex: 15, type: 'delimiter.abap' }
]
}
],
[
{
line: 'CLASS-METHODS class_constructor.',
tokens: [
{ startIndex: 0, type: 'keyword.abap' },
{ startIndex: 13, type: '' },
{ startIndex: 14, type: 'type.abap' },
{ startIndex: 31, type: 'delimiter.abap' }
]
}
],
[
{
line: 'super->constructor( ).',
tokens: [
{ startIndex: 0, type: 'type.abap' },
{ startIndex: 5, type: 'tag.abap' },
{ startIndex: 7, type: 'type.abap' },
{ startIndex: 18, type: 'delimiter.parenthesis.abap' },
{ startIndex: 19, type: '' },
{ startIndex: 20, type: 'delimiter.parenthesis.abap' },
{ startIndex: 21, type: 'delimiter.abap' }
]
}
],
[
{
line: 'foo->my_method( ).',
tokens: [
{ startIndex: 0, type: 'identifier.abap' },
{ startIndex: 3, type: 'tag.abap' },
{ startIndex: 5, type: 'identifier.abap' },
{ startIndex: 14, type: 'delimiter.parenthesis.abap' },
{ startIndex: 15, type: '' },
{ startIndex: 16, type: 'delimiter.parenthesis.abap' },
{ startIndex: 17, type: 'delimiter.abap' }
]
}
],
[
{
line: 'foo=>const_bar.',
tokens: [
{ startIndex: 0, type: 'identifier.abap' },
{ startIndex: 3, type: 'tag.abap' },
{ startIndex: 5, type: 'identifier.abap' },
{ startIndex: 14, type: 'delimiter.abap' }
]
}
],
[
{
line: 'foo-bar+42(42).',
tokens: [
{ startIndex: 0, type: 'identifier.abap' },
{ startIndex: 7, type: '' },
{ startIndex: 8, type: 'number.abap' },
{ startIndex: 10, type: 'delimiter.parenthesis.abap' },
{ startIndex: 11, type: 'number.abap' },
{ startIndex: 13, type: 'delimiter.parenthesis.abap' },
{ startIndex: 14, type: 'delimiter.abap' }
]
}
],
[
{
line: "@EndUserText.label: 'hallo'",
tokens: [
{ startIndex: 0, type: 'annotation.abap' },
{ startIndex: 12, type: 'delimiter.abap' },
{ startIndex: 13, type: 'identifier.abap' },
{ startIndex: 18, type: 'delimiter.abap' },
{ startIndex: 19, type: '' },
{ startIndex: 20, type: 'string.abap' }
]
}
],
[
{
line: 'IF foo = abap_true.',
tokens: [
{ startIndex: 0, type: 'keyword.abap' },
{ startIndex: 2, type: '' },
{ startIndex: 3, type: 'identifier.abap' },
{ startIndex: 6, type: '' },
{ startIndex: 7, type: 'key.abap' },
{ startIndex: 8, type: '' },
{ startIndex: 9, type: 'type.abap' },
{ startIndex: 18, type: 'delimiter.abap' }
]
}
],
[
{
line: 'LOOP AT screen.',
tokens: [
{ startIndex: 0, type: 'keyword.abap' },
{ startIndex: 4, type: '' },
{ startIndex: 5, type: 'keyword.abap' },
{ startIndex: 7, type: '' },
{ startIndex: 8, type: 'type.abap' },
{ startIndex: 14, type: 'delimiter.abap' }
]
}
]
]);

View file

@ -4,9 +4,22 @@
*--------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------
* Based on SAP ABAP Application Server 7.54
* ABAP Language
*
* Based on SAP ABAP Application Server 7.55
*
* Definition:
* https://github.com/microsoft/monaco-languages/blob/master/src/abap/abap.ts
*
* Reference:
* https://help.sap.com/doc/abapdocu_754_index_htm/7.54/en-US/index.htm?file=abenabap_words.htm
* https://help.sap.com/doc/abapdocu_755_index_htm/7.55/en-US/index.htm?file=abenabap_words.htm
* https://help.sap.com/doc/abapdocu_755_index_htm/7.55/en-US/index.htm?file=abenabap_index.htm
*
* Playground:
* https://microsoft.github.io/monaco-editor/monarch.html
*
* Themes:
* https://github.com/Microsoft/vscode/blob/master/src/vs/editor/standalone/common/themes.ts
*--------------------------------------------------------------------------------------------*/
import type { languages } from '../fillers/monaco-editor-core';
@ -21,8 +34,12 @@ export const conf: languages.LanguageConfiguration = {
]
};
const abapKeywords = [
// words
export const language = <languages.IMonarchLanguage>{
defaultToken: 'invalid',
ignoreCase: true,
tokenPostfix: '.abap',
keywords: [
'abap-source',
'abbreviated',
'abstract',
@ -43,6 +60,7 @@ const abapKeywords = [
'alpha',
'analysis',
'analyzer',
'and', // also an operator
'append',
'appendage',
'appending',
@ -72,6 +90,7 @@ const abapKeywords = [
'base',
'before',
'begin',
'between', // also an operator
'big',
'binary',
'bintohex',
@ -154,6 +173,7 @@ const abapKeywords = [
'concat_with_space',
'concatenate',
'cond',
'condense', // also a built-in
'condition',
'connect',
'connection',
@ -281,6 +301,7 @@ const abapKeywords = [
'entry',
'enum',
'environment',
'equiv', // also an operator
'errormessage',
'errors',
'escaping',
@ -321,6 +342,7 @@ const abapKeywords = [
'filters',
'filter-table',
'final',
'find', // also a built-in
'first',
'first-line',
'fixed-point',
@ -356,7 +378,7 @@ const abapKeywords = [
'handle',
'handler',
'harmless',
'hashed',
'hashed', // also a table type
'having',
'hdb',
'header',
@ -386,13 +408,14 @@ const abapKeywords = [
'implicit',
'import',
'importing',
'in', // also an operator
'inactive',
'incl',
'include',
'includes',
'including',
'increment',
'index',
'index', // also a table type
'index-line',
'infotypes',
'inheriting',
@ -402,6 +425,7 @@ const abapKeywords = [
'inner',
'inout',
'input',
'insert', // also a built-in
'instance',
'instances',
'instr',
@ -442,6 +466,7 @@ const abapKeywords = [
'levels',
'like',
'line',
'lines', // also a built-in
'line-count',
'linefeed',
'line-selection',
@ -474,6 +499,7 @@ const abapKeywords = [
'margin',
'mark',
'mask',
'match', // also a built-in
'matchcode',
'max',
'maximum',
@ -513,24 +539,25 @@ const abapKeywords = [
'new-section',
'next',
'no',
'node',
'nodes',
'no-display',
'no-extension',
'no-gap',
'no-gaps',
'no-grouping',
'no-heading',
'non-unicode',
'non-unique',
'no-scrolling',
'no-sign',
'no-title',
'no-topofpage',
'no-zero',
'node',
'nodes',
'non-unicode',
'non-unique',
'not', // also an operator
'null',
'number',
'object',
'object', // also a data type
'objects',
'obligatory',
'occurrence',
@ -546,6 +573,7 @@ const abapKeywords = [
'option',
'optional',
'options',
'or', // also an operator
'order',
'other',
'others',
@ -637,6 +665,7 @@ const abapKeywords = [
'reject',
'remote',
'renaming',
'replace', // also a built-in
'replacement',
'replacing',
'report',
@ -710,7 +739,7 @@ const abapKeywords = [
'some',
'sort',
'sortable',
'sorted',
'sorted', // also a table type
'source',
'specified',
'split',
@ -720,7 +749,7 @@ const abapKeywords = [
'sqlscript',
'stable',
'stamp',
'standard',
'standard', // also a table type
'starting',
'start-of-editing',
'start-of-selection',
@ -761,6 +790,7 @@ const abapKeywords = [
'system-exit',
'tab',
'tabbed',
'table',
'tables',
'tableview',
'tabstrip',
@ -794,6 +824,7 @@ const abapKeywords = [
'transaction',
'transfer',
'transformation',
'translate', // also a built-in
'transporting',
'trmac',
'truncate',
@ -860,7 +891,149 @@ const abapKeywords = [
'yymmdd',
'zero',
'zone',
// built-ins
// since 7.55:
'abap_system_timezone',
'abap_user_timezone',
'access',
'action',
'adabas',
'adjust_numbers',
'allow_precision_loss',
'allowed',
'amdp',
'applicationuser',
'as_geo_json',
'as400',
'associations',
'balance',
'behavior',
'breakup',
'bulk',
'cds',
'cds_client',
'check_before_save',
'child',
'clients',
'corr',
'corr_spearman',
'cross',
'cycles',
'datn_add_days',
'datn_add_months',
'datn_days_between',
'dats_from_datn',
'dats_tims_to_tstmp',
'dats_to_datn',
'db2',
'db6',
'ddl',
'dense_rank',
'depth',
'deterministic',
'discarding',
'entities',
'entity',
'error',
'failed',
'finalize',
'first_value',
'fltp_to_dec',
'following',
'fractional',
'full',
'graph',
'grouping',
'hierarchy',
'hierarchy_ancestors',
'hierarchy_ancestors_aggregate',
'hierarchy_descendants',
'hierarchy_descendants_aggregate',
'hierarchy_siblings',
'incremental',
'indicators',
'lag',
'last_value',
'lead',
'leaves',
'like_regexpr',
'link',
'locale_sap',
'lock',
'locks',
'many',
'mapped',
'matched',
'measures',
'median',
'mssqlnt',
'multiple',
'nodetype',
'ntile',
'nulls',
'occurrences_regexpr',
'one',
'operations',
'oracle',
'orphans',
'over',
'parent',
'parents',
'partition',
'pcre',
'period',
'pfcg_mapping',
'preceding',
'privileged',
'product',
'projection',
'rank',
'redirected',
'replace_regexpr',
'reported',
'response',
'responses',
'root',
'row',
'row_number',
'sap_system_date',
'save',
'schema',
'session',
'sets',
'shortdump',
'siblings',
'spantree',
'start',
'stddev',
'string_agg',
'subtotal',
'sybase',
'tims_from_timn',
'tims_to_timn',
'to_blob',
'to_clob',
'total',
'trace-entry',
'tstmp_to_dats',
'tstmp_to_dst',
'tstmp_to_tims',
'tstmpl_from_utcl',
'tstmpl_to_utcl',
'unbounded',
'utcl_add_seconds',
'utcl_current',
'utcl_seconds_between',
'uuid',
'var',
'verbatim'
],
//
// Built-in Functions
//
// Functions that are also statements have been moved to keywords
//
builtinFunctions: [
'abs',
'acos',
'asin',
@ -874,7 +1047,7 @@ const abapKeywords = [
'cmax',
'cmin',
'concat_lines_of',
'condense',
// 'condense', // moved to keywords
'contains',
'contains_any_not_of',
'contains_any_of',
@ -887,27 +1060,27 @@ const abapKeywords = [
'distance',
'escape',
'exp',
'find',
// 'find', // moved to keywords
'find_any_not_of',
'find_any_of',
'find_end',
'floor',
'frac',
'from_mixed',
'insert',
// 'insert', // moved to keywords
'ipow',
'line_exists',
'line_index',
'lines',
// 'lines', // moved to keywords
'log',
'log10',
'match',
// 'match', // moved to keywords
'matches',
'nmax',
'nmin',
'numofchar',
'repeat',
'replace',
// 'replace', // moved to keywords
'rescale',
'reverse',
'round',
@ -929,23 +1102,22 @@ const abapKeywords = [
'to_lower',
'to_mixed',
'to_upper',
'translate',
// 'translate', // moved to keywords
'trunc',
'utclong_add', // since 7.54
'utclong_current', // since 7.54
'utclong_diff', // since 7.54
'xsdbool',
'xstrlen'
];
export const language = <languages.IMonarchLanguage>{
defaultToken: 'invalid',
ignoreCase: true,
tokenPostfix: '.abap',
keywords: abapKeywords,
],
//
// Data Types
//
// Data types that are also part of statements have been moved to keywords
//
typeKeywords: [
// built-in data types
// built-in abap types
'b',
'c',
'd',
@ -967,33 +1139,34 @@ export const language = <languages.IMonarchLanguage>{
'clike',
'csequence',
'decfloat',
// 'object', // moved to keywords
'numeric',
'simple',
'xsequence',
// generic table types
'table',
// 'any table',
'hashed', // 'hashed table',
'index', // 'index table',
'sorted', // 'sorted table',
'standard', // 'standard table',
// ddic data types
// ddic/sql data types
'accp',
'char',
'clnt',
'cuky',
'curr',
'datn', // since 7.55
'dats',
'd16d', // since 7.55
'd16n', // since 7.55
'd16r', // since 7.55
'd34d', // since 7.55
'd34n', // since 7.55
'd34r', // since 7.55
'dec',
'df16_dec',
'df16_raw',
'df34_dec',
'df34_raw',
'fltp',
'geom_ewkb', // since 7.55
'int1',
'int2',
'int4',
// 'int8', built-in since 7.54
'lang',
'lchr',
'lraw',
@ -1002,22 +1175,87 @@ export const language = <languages.IMonarchLanguage>{
'raw',
'rawstring',
'sstring',
'timn', // since 7.55
'tims',
'unit',
'utcl', // since 7.55
// ddic data types (obsolete)
'df16_scl',
'df34_scl',
'prec',
'varc',
// special data types
// special data types and constants
'abap_bool',
'space',
'abap_false',
'abap_true',
'abap_undefined',
'me',
'syst',
'screen',
'space',
'super',
'sy',
'screen'
'syst',
'table_line',
// obsolete data object
'*sys*'
],
builtinMethods: [
'class_constructor',
'constructor'
],
derivedTypes: [
'%CID',
'%CID_REF',
'%CONTROL',
'%DATA',
'%ELEMENT',
'%FAIL',
'%KEY',
'%MSG',
'%PARAM',
'%PID',
'%PID_ASSOC',
'%PID_PARENT',
'%_HINTS'
],
cdsLanguage: [
'@AbapAnnotation',
'@AbapCatalog',
'@AccessControl',
'@API',
'@ClientDependent',
'@ClientHandling',
'@CompatibilityContract',
'@DataAging',
'@EndUserText',
'@Environment',
'@LanguageDependency',
'@MappingRole',
'@Metadata',
'@MetadataExtension',
'@ObjectModel',
'@Scope',
'@Semantics',
'$EXTENSION',
'$SELF'
],
selectors: [
'->',
'->*',
'=>',
'~',
'~*'
],
//
// Operators
//
// Operators that can be part of statements have been moved to keywords
//
operators: [
// arithmetic operators
' +',
@ -1031,6 +1269,14 @@ export const language = <languages.IMonarchLanguage>{
'=',
'#',
'@',
'+=',
'-=',
'*=',
'/=',
'**=',
'&&=',
// casting operator
'?=',
// concat operators
'&',
'&&',
@ -1043,20 +1289,20 @@ export const language = <languages.IMonarchLanguage>{
'o',
'z',
// boolean operators
'and',
'equiv',
'not',
'or',
// 'and', // moved to keywords
// 'equiv', // moved to keywords
// 'not', // moved to keywords
// 'or', // moved to keywords
// comparison operators
'<',
' > ',
' >', // todo: separate from -> and =>
'<=',
'>=',
'<>',
'><', // obsolete
'=<', // obsolete
'=>', // obsolete
'between',
// 'between', // moved to keywords
'bt',
'byte-ca',
'byte-cn',
@ -1072,14 +1318,20 @@ export const language = <languages.IMonarchLanguage>{
'eq', // obsolete
'ge', // obsolete
'gt', // obsolete
'in',
// 'in', // moved to keywords
'le', // obsolete
'lt', // obsolete
'na',
'nb',
'ne', // obsolete
'np',
'ns'
'ns',
// cds
'*/',
'*:',
'--',
'/*',
'//'
],
symbols: /[=><!~?&+\-*\/\^%#@]+/,
@ -1087,12 +1339,16 @@ export const language = <languages.IMonarchLanguage>{
tokenizer: {
root: [
[
/[a-z_$][\w-$]*/,
/[a-z_\/$%@]([\w\/$%]|-(?!>))*/, // exclude '->' selector
{
cases: {
'@typeKeywords': 'keyword',
'@typeKeywords': 'type',
'@keywords': 'keyword',
'@operators': 'operator',
'@cdsLanguage': 'annotation',
'@derivedTypes': 'type',
'@builtinFunctions': 'type',
'@builtinMethods': 'type',
'@operators': 'key',
'@default': 'identifier'
}
}
@ -1100,13 +1356,24 @@ export const language = <languages.IMonarchLanguage>{
[/<[\w]+>/, 'identifier'], // field symbols
[/##[\w|_]+/, 'comment'], // pragmas
{ include: '@whitespace' },
[/[:,.]/, 'delimiter'],
[/[{}()\[\]]/, '@brackets'],
[/@symbols/, { cases: { '@operators': 'operator', '@default': '' } }],
[
/@symbols/,
{
cases: {
'@selectors': 'tag',
'@operators': 'key',
'@default': ''
}
}
],
[/'/, { token: 'string', bracket: '@open', next: '@stringquote' }],
[/`/, { token: 'string', bracket: '@open', next: '@stringping' }],