Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #72 from larshp/abap
Browse files Browse the repository at this point in the history
[ABAP] Add ABAP language support
  • Loading branch information
alexdima committed Sep 19, 2019
2 parents 1cea151 + a73e4de commit f67f33d
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -4,6 +4,7 @@ Colorization and configuration supports for multiple languages for the Monaco Ed

![monaco-languages](https://cloud.githubusercontent.com/assets/5047891/15938606/1fd4bac6-2e74-11e6-8839-d455da8bc8a7.gif)

* abap
* apex
* azcli
* bat
Expand Down
1 change: 1 addition & 0 deletions scripts/bundle.js
Expand Up @@ -21,6 +21,7 @@ const BUNDLED_FILE_HEADER = [
].join('\n');

bundleOne('monaco.contribution');
bundleOne('abap/abap');
bundleOne('bat/bat');
bundleOne('css/css');
bundleOne('coffee/coffee');
Expand Down
14 changes: 14 additions & 0 deletions src/abap/abap.contribution.ts
@@ -0,0 +1,14 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { registerLanguage } from '../_.contribution';

registerLanguage({
id: 'abap',
extensions: ['.abap'],
aliases: ['abap', 'ABAP'],
loader: () => import('./abap')
});
95 changes: 95 additions & 0 deletions src/abap/abap.test.ts
@@ -0,0 +1,95 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

'use strict';

import { testTokenization } from '../test/testRunner';

testTokenization('abap', [
[{
line: '* comment',
tokens: [
{ startIndex: 0, type: 'comment.abap' }
]
}],
[{
line: ' " comment',
tokens: [
{ startIndex: 0, type: '' },
{ startIndex: 1, type: 'comment.abap' }
]
}],
[{
line: 'write hello.',
tokens: [
{ startIndex: 0, type: 'keyword.abap' },
{ startIndex: 5, type: '' },
{ startIndex: 6, type: 'identifier.abap' },
{ startIndex: 11, type: 'delimiter.abap' }
]
}],
[{
line: 'IF 2 = 3.',
tokens: [
{ startIndex: 0, type: 'keyword.abap' },
{ startIndex: 2, type: '' },
{ startIndex: 3, type: 'number.abap' },
{ startIndex: 4, type: '' },
{ startIndex: 5, type: 'operator.abap' },
{ startIndex: 6, type: '' },
{ startIndex: 7, type: 'number.abap' },
{ startIndex: 8, type: 'delimiter.abap' }
]
}],
[{
line: '\'hello\'',
tokens: [
{ startIndex: 0, type: 'string.abap' },
]
}],
[{
line: '|hello|',
tokens: [
{ startIndex: 0, type: 'string.abap' },
]
}],
[{
line: 'write: hello, world.',
tokens: [
{ startIndex: 0, type: 'keyword.abap' },
{ startIndex: 5, type: 'delimiter.abap' },
{ startIndex: 6, type: '' },
{ startIndex: 7, type: 'identifier.abap' },
{ startIndex: 12, type: 'delimiter.abap' },
{ startIndex: 13, type: '' },
{ startIndex: 14, type: 'identifier.abap' },
{ startIndex: 19, type: 'delimiter.abap' },
]
}],
[{
line: 'method_call( param ).',
tokens: [
{ startIndex: 0, type: 'identifier.abap' },
{ startIndex: 11, type: 'delimiter.parenthesis.abap' },
{ startIndex: 12, type: '' },
{ startIndex: 13, type: 'identifier.abap' },
{ startIndex: 18, type: '' },
{ startIndex: 19, type: 'delimiter.parenthesis.abap' },
{ startIndex: 20, type: 'delimiter.abap' },
]
}],
[{
line: '\'he\'\' llo\'',
tokens: [
{ startIndex: 0, type: 'string.abap' },
]
}],
[{
line: '|hel\\|lo|',
tokens: [
{ startIndex: 0, type: 'string.abap' },
]
}],
]);
113 changes: 113 additions & 0 deletions src/abap/abap.ts
@@ -0,0 +1,113 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

'use strict';

import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration;
import ILanguage = monaco.languages.IMonarchLanguage;

export const conf: IRichLanguageConfiguration = {
comments: {
lineComment: '*',
},
brackets: [
['[', ']'],
['(', ')']
],
};

const abapKeywords = [
'abstract','add','add-corresponding','adjacent','alias','aliases','all','append','appending','ascending','as','assert','assign','assigned','assigning','association','authority-check',
'back','begin','binary','block','bound','break-point','by','byte',
'class', 'call','cast','changing','check','class-data','class-method','class-methods','clear','close','cnt','collect','commit','cond','character',
'corresponding','communication','component','compute','concatenate','condense','constants','conv','count',
'controls','convert','create','currency',
'data','descending','default','define','deferred','delete','describe','detail','display','divide','divide-corresponding','display-mode','duplicates',
'deleting',
'editor-call','end','endexec','endfunction','ending','endmodule','end-of-definition','end-of-page','end-of-selection','end-test-injection','end-test-seam','exit-command','endclass','endmethod','endform','endinterface',
'endprovide','endselect','endtry','endwhile','enum','event','events','exec','exit','export',
'exporting','extract','exception','exceptions',
'field-symbols','field-groups','field','first','fetch','fields','format','frame','free','from','function','find','for','found','function-pool',
'generate','get',
'handle','hide','hashed',
'include','import','importing','index','infotypes','initial','initialization',
'id','is','in','interface','interfaces','init','input','insert','instance','into',
'key',
'left-justified','leave','like','line','line-count','line-size','load','local','log-point','length','left','leading','lower',
'matchcode','method','mesh','message','message-id','methods','modify','module','move','move-corresponding','multiply','multiply-corresponding','match',
'new','new-line','new-page','new-section','next','no','no-gap','no-gaps','no-sign','no-zero','non-unique','number',
'occurrence','object','obligatory','of','output','overlay','optional','others','occurrences','occurs','offset','options',
'pack','parameters','perform','places','position','print-control','private','program','protected','provide','public','put',
'radiobutton','raising','ranges','receive','receiving','redefinition','reduce','reference','refresh','regex','reject','results','requested',
'ref','replace','report','reserve','restore','result','return','returning','right-justified','rollback','read','read-only','rp-provide-from-last','run',
'scan','screen','scroll','search','select','select-options','selection-screen','stamp','source','subkey',
'separated','set','shift','single','skip','sort','sorted','split','standard','stamp','starting','start-of-selection','sum','subtract-corresponding','statics','step','stop','structure','submatches','submit','subtract','summary','supplied','suppress','section','syntax-check','syntax-trace','system-call','switch',
'tables','table','task','testing','test-seam','test-injection','then','time','times','title','titlebar','to','top-of-page','trailing','transfer','transformation','translate','transporting','types','type','type-pool','type-pools',
'unassign','unique','uline','unpack','update','upper','using',
'value',
'when','while','window','write','where','with','work',
'at','case','catch','continue','do','elseif','else','endat','endcase','enddo','endif','endloop','endon','if','loop','on','raise','try',
'abs','sign','ceil','floor','trunc','frac','acos','asin','atan','cos','sin','tan','cosh','sinh','tanh','exp','log','log10','sqrt','strlen','xstrlen','charlen','lines','numofchar','dbmaxlen','round','rescale','nmax','nmin','cmax','cmin','boolc','boolx','xsdbool','contains','contains_any_of','contains_any_not_of','matches','line_exists','ipow','char_off','count','count_any_of','count_any_not_of','distance','condense','concat_lines_of','escape','find','find_end','find_any_of','find_any_not_of','insert','match','repeat','replace','reverse','segment','shift_left','shift_right','substring','substring_after','substring_from','substring_before','substring_to','to_upper','to_lower','to_mixed','from_mixed','translate','bit-set','line_index',
'definition','implementation','public','inheriting','final'
];

export const language = <ILanguage> {
defaultToken: 'invalid',
ignoreCase: true,
tokenPostfix: '.abap',
keywords: abapKeywords,

typeKeywords: [
'abap_bool','string','xstring','any','clike','csequence','numeric',
'xsequence','c','n','i','p','f','d','t','x'
],

operators: [
'+', '-', '/', '*',
'=', '<', '>', '<=', '>=', '<>', '><', '=<', '=>',
'EQ', 'NE', 'GE', 'LE',
'CS', 'CN', 'CA', 'CO', 'CP', 'NS', 'NA', 'NP',
],

symbols: /[=><!~?&+\-*\/\^%]+/,

tokenizer: {
root: [
[/[a-z_$][\w$]*/, { cases: { '@typeKeywords': 'keyword',
'@keywords': 'keyword',
'@default': 'identifier' } }],

{ include: '@whitespace' },

[/[:,.]/, 'delimiter'],

[/[{}()\[\]]/, '@brackets'],
[/@symbols/, { cases: { '@operators': 'operator',
'@default' : '' } } ],

[/'/, { token: 'string', bracket: '@open', next: '@stringquote' } ],
[/\|/, { token: 'string', bracket: '@open', next: '@stringtemplate' } ],

[/\d+/, 'number'],
],

stringtemplate: [
[/[^\\\|]+/, 'string'],
[/\\\|/, 'string'],
[/\|/, { token: 'string', bracket: '@close', next: '@pop' } ]
],

stringquote: [
[/[^\\']+/, 'string'],
[/'/, { token: 'string', bracket: '@close', next: '@pop' } ]
],

whitespace: [
[/[ \t\r\n]+/, ''],
[/^\*.*$/, 'comment'],
[/\".*$/, 'comment'],
],
},
};
1 change: 1 addition & 0 deletions src/monaco.contribution.ts
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import './abap/abap.contribution';
import './bat/bat.contribution';
import './coffee/coffee.contribution';
import './cpp/cpp.contribution';
Expand Down
1 change: 1 addition & 0 deletions test/setup.js
Expand Up @@ -25,6 +25,7 @@ define(['require'], function () {
'vs/editor/editor.main'
], function () {
requirejs([
'release/dev/abap/abap.test',
'release/dev/apex/apex.test',
'release/dev/azcli/azcli.test',
'release/dev/bat/bat.test',
Expand Down

0 comments on commit f67f33d

Please sign in to comment.