From f4ec5bd1f7a6676f87dac47cac9dec8b9c92f948 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 24 Mar 2023 12:03:34 +0100 Subject: [PATCH] Add support for aliases when linguist renames scopes --- lang/source.brightscript.js | 118 +---------- lang/source.vtt.js | 409 +----------------------------------- script/build.js | 78 +++++-- script/list.js | 4 +- 4 files changed, 67 insertions(+), 542 deletions(-) diff --git a/lang/source.brightscript.js b/lang/source.brightscript.js index 8c81ea0..c2cc360 100644 --- a/lang/source.brightscript.js +++ b/lang/source.brightscript.js @@ -1,116 +1,2 @@ -// This is a TextMate grammar distributed by `starry-night`. -// This grammar is licensed `mit`. -// See for more info. -/** @type {import('../lib/index.js').Grammar} */ -const grammar = { - extensions: ['.brs'], - names: ['brightscript'], - patterns: [ - {include: '#functions'}, - {include: '#program_statements'}, - {include: '#operators'}, - {include: '#support_functions'}, - {include: '#storage_types'}, - {include: '#literals'}, - {include: '#constant_numeric'}, - { - captures: {1: {name: 'punctuation.definition.comment.brightscript'}}, - match: "(').*$\\n?", - name: 'comment.line.apostrophe.brightscript' - }, - { - captures: {1: {name: 'punctuation.definition.comment.brightscript'}}, - match: '^\\s*?(?i:rem\\s).*$\\n?', - name: 'comment.line.rem.brightscript' - }, - { - begin: '"', - end: '"', - name: 'string.quoted.double.brightscript', - patterns: [ - {match: '\\\\.', name: 'constant.character.escape.brightscript'}, - {include: '#class_roku_builtin'} - ] - } - ], - repository: { - class: {name: 'meta.class.brightscript'}, - class_roku_builtin: { - match: - '(?i:\\bro(R(ss(Parser|Article)|e(sourceManager|ctangle|ad(File|WriteFile)|gistry(Section)?))|G(pio(Button|ControlPort)|lobal)|XML(Element|List)|MessagePort|B(yteArray|oolean|r(Sub|ightPackage))|S(ystemTime|t(orageInfo|ring( )?)|erialPort( )?)|NetworkConfiguration|C(ontrol(Down( )?|Up|Port)|ecInterface|lockWidget|reateFile)|T(imer|ouchScreen( )?|ext(Field|Widget))|I(RRemote( )?|n(t|valid)|mage(Player|Widget))|D(eviceInfo( )?|at(eTime|agram(Receiver|Sender)))|Url(Transfer|Event)|Video(Mode|Input|Player|Event)|Keyboard(Press( )?| )?|Quadravox(Button( )?|SNS5( )?)|Float|List|A(ssociativeArray|udio(Player|Event)|ppendFile|rray))\\b)', - name: 'support.class.brightscript' - }, - constant_numeric: { - match: - '\\b((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)?\\b', - name: 'constant.numeric.brightscript' - }, - functions: { - captures: { - 1: {name: 'storage.type.function.brightscript'}, - 2: {name: 'entity.name.function.brightscript'}, - 3: {name: 'punctuation.definition.parameters.brightscript'}, - 4: {name: 'variable.parameter.function.brightscript'}, - 5: {name: 'punctuation.definition.parameters.brightscript'} - }, - match: - '^\\s*((?i:function|sub))\\s*([a-zA-Z_]\\w*)\\s*(\\()([^)]*)(\\)).*\\n?', - name: 'meta.function.brightscript' - }, - literals: { - match: '(?i:\\b(N(othing|ull)|True|Invalid|Empty|False)\\b)', - name: 'constant.language.brightscript' - }, - operators: { - match: '=|>=||<|<>|\\+|-|\\*|\\/|\\^|&|\\b(?i:(And|Not|Or))\\b', - name: 'keyword.operator.brightscript' - }, - program_statements: { - match: - '(?i:\\b(s(t(op|ep)|ub)|i(n|f)|t(hen|o)|dim|print|e(nd(if| (sub|f(or|unction)|while))?|lse(if)?|xit (for|while))|f(or( each)?|unction)|as|while|re(turn|m)|goto)?\\b)', - name: 'keyword.control.brightscript' - }, - storage_types: { - match: - '(?i:\\b(string|in(te(rface|ger)|valid)|object|double|float|b(oolean|rsub))\\b)', - name: 'storage.type.brightscript' - }, - support_builtin_functions: { - match: - '(?i:\\b(GetLastRun(RuntimeError|CompileError)|R(nd|un)|Box|Type)\\b)', - name: 'support.function.brightscript' - }, - support_component_functions: { - match: - '(?i:\\b(R(ight|e(set(Index)?|ad(B(yte(IfAvailable)?|lock)|File|Line)?|move(Head|Tail|Index)))|Ge(nXML(Header)?|t(Res(ource|ponse(Headers|Code))|X|M(i(nute|llisecond)|o(nth|de(l)?)|essage)|B(yte(sPerBlock|Array)|o(o(tVersion(Number)?|lean)|dy))|S(t(orageCardInfo|a(ndards|tusByte)|ring(Count)?)|i(zeInMegabytes|gnedByte)|ource(Host|Identity|Port)|ub|ec(tionList|ond)|afe(X|Height|Y|Width))|H(o(stName|ur)|e(ight|ad))|Y(ear)?|N(extArticle|ame(dElements)?)|C(hildElements|ontrols|urrent(Standard|Con(trolValue|fig)|Input))|T(i(tle|me(Server|Zone))|o(String|File)|ext|ail)|I(n(t|dex|puts)|dentity)|ZoneDateTime|D(e(scription|vice(BootCount|Name|U(niqueId|ptime)))|a(y(OfWeek)?|ta))|U(se(dInMegabytes|rData)|tcDateTime)|Ent(ityEncode|ry)|V(ersion(Number)?|alue)|KeyList|F(ileSystemType|loat|a(ilureReason|mily)|reeInMegabytes)|W(holeState|idth)|LocalDateTime|Attributes))|M(id|D5|ap(StereoOutput(Aux)?|DigitalOutput))|Boolean|S(h(ift|ow)|canWiFi|t(op(Clear|Display)?|art|r(i(ng)?)?)|implify|ubtract(Milliseconds|Seconds)|e(nd(RawMessage|B(yte|lock)|Line)?|t(R(ollOverRegion|e(s(ize|olution)|c(tangle|eiveEol)))|X|M(i(n(imumTransferRate|ute)|llisecond)|o(nth|de(CaseSensitive)?)|ultiscreenBezel)|B(yteEventPort|o(olean|dy)|a(ckground(Bitmap|Color)|udRate))|S(t(andard|ring)|ub|e(ndEol|cond)|afeTextRegion)|H(o(stName|ur)|eight)|Y(ear)?|Name|C(hannelVolumes(Aux)?|ontrolValue|ursor(Bitmap|Pos(ition)?))|Time(Server|Zone)?|I(n(t|put)|P4(Gateway|Broadcast|Netmask|Address))|OutputState|D(HCP|omain|e(stination|fault(Mode|Transistion))|a(y(OfWeek)?|te(Time)?))|U(ser(Data|AndPassword)|tcDateTime|rl)|P(o(werSaveMode|rt)|assword|roxy)|E(ntry|cho|ol)|V(iewMode|olume(Aux)?)|F(o(nt|r(egroundColor|groundColor))|l(oat|ashRate))|W(holeState|i(dth|Fi(Passphrase|ESSID)))|L(ineEventPort|o(calDateTime|opMode)|auguage)|Audio(Mode(Aux)?|Stream(Aux)?|Output(Aux)?))|ek(Relative|ToEnd|Absolute)))|H(ide|ead|asAttribute)|N(ormalize|ext)|C(hr|ount|urrentPosition|l(s|ear(Region|Events)?))|T(o(Base64String|HexString|kenize|AsciiString)|estInter(netConnectivity|face)|rim)|I(s(MousePresent|N(ext|ame)|InputActive|Empty|Valid|LittleEndianCPU)|n(str|te(rface|ger)|valid))|Object|D(ynamic|isplay(Preload|File(Ex)?)|o(uble|esExist)|elete)|U(n(shift|pack)|Case)|P(o(st(Message|From(String|File))|p(String(s)?)?)|ush(String)?|eek|lay(StaticImage|File)?|arse(String|File)?|reloadFile(Ex)?)|E(nable(R(ollover|egion)|Cursor|Input|Output)|xists)|Void|F(indIndex|unction|l(oat|ush)|rom(Base64String|HexString|AsciiString))|W(hile|aitMessage|rite(File)?)|L(ookup|e(n|ft))|A(s(ync(GetTo(String|File)|Head|PostFrom(String|File)|Flush)|c)?|tEof|dd(Re(ctangle(Region|_region)|place)|Milliseconds|BodyElement|Seconds|Head(er)?|CircleRegion|Tail|DNSServer|E(vent|lement(WithBody)?)|Attribute)|pp(end(String|File)?|ly)))\\b)', - name: 'support.function.component.brightscript' - }, - support_functions: { - patterns: [ - {include: '#support_builtin_functions'}, - {include: '#support_global_functions'}, - {include: '#support_global_string_functions'}, - {include: '#support_global_math_functions'}, - {include: '#support_component_functions'} - ] - }, - support_global_functions: { - match: - '(?i:\\b(Re(adAsciiFile|bootSystem)|GetInterface|MatchFiles|Sleep|C(opyFile|reate(Directory|Object))|Delete(Directory|File)|UpTime|FormatDrive|ListDir|W(ait|riteAsciiFile))\\b)', - name: 'support.function.brightscript' - }, - support_global_math_functions: { - match: - '(?i:\\b(S(in|qr|gn)|C(sng|dbl|os)|Tan|Int|Exp|Fix|Log|A(tn|bs))\\b)', - name: 'support.function.brightscript' - }, - support_global_string_functions: { - match: - '(?i:\\b(Right|Mid|Str(i(ng(i)?)?)?|Chr|Instr|UCase|Val|Asc|L(Case|e(n|ft)))\\b)', - name: 'support.function.brightscript' - } - }, - scopeName: 'source.brightscript' -} - -export default grammar +// This is an alias, please use `source.brs.js` instead. +export {default} from './source.brs.js' diff --git a/lang/source.vtt.js b/lang/source.vtt.js index ceba434..4e4f0e8 100644 --- a/lang/source.vtt.js +++ b/lang/source.vtt.js @@ -1,407 +1,2 @@ -// This is a TextMate grammar distributed by `starry-night`. -// This grammar is licensed `mit`. -// See for more info. -/** @type {import('../lib/index.js').Grammar} */ -const grammar = { - extensions: ['.vtt'], - names: ['webvtt'], - patterns: [{include: '#file_body'}], - repository: { - _cue_timings_and_settings_list: { - captures: { - 1: {patterns: [{include: '#cue_timings'}]}, - 2: {patterns: [{include: '#cue_settings_list'}]} - }, - match: '^(.+?\\s+-->\\s+.+?)(?:\\s+(.+))?$' - }, - alignment_cue_setting: { - captures: { - 1: {name: 'support.type.alignment-cue-setting.vtt'}, - 2: {name: 'punctuation.definition.colon.vtt'}, - 3: { - patterns: [ - { - match: '(?:^|\\G)(?:start|center|end|left|right)(?=$)', - name: 'support.constant.alignment-cue-setting.vtt' - }, - {match: '.+', name: 'invalid.illegal.vtt'} - ] - } - }, - match: '(align)(:)([^\\s]+)', - name: 'meta.alignment-cue-setting.vtt' - }, - comment_block: { - begin: '^(NOTE)(?:\\s(.*))?$', - beginCaptures: { - 1: {name: 'entity.name.section.comment.vtt'}, - 2: {name: 'comment.line.character.vtt'} - }, - end: '^$', - name: 'meta.comment-block.vtt', - patterns: [{match: '.+', name: 'comment.line.character.vtt'}] - }, - cue_block: { - begin: '^.+$', - beginCaptures: { - 0: { - patterns: [ - {include: '#cue_identifier'}, - {include: '#_cue_timings_and_settings_list'}, - {match: '.+', name: 'invalid.illegal.vtt'} - ] - } - }, - end: '^$', - name: 'meta.cue-block.vtt', - patterns: [ - {include: '#_cue_timings_and_settings_list'}, - {include: '#cue_text'} - ] - }, - cue_bold_span: {name: 'meta.cue-bold-span.vtt'}, - cue_class_span: {name: 'meta.cue-class-span.vtt'}, - cue_components: { - name: 'meta.cue-components.vtt', - patterns: [ - {include: '#cue_class_span'}, - {include: '#cue_italics_span'}, - {include: '#cue_bold_span'}, - {include: '#cue_underline_span'}, - {include: '#cue_ruby_span'}, - {include: '#cue_voice_span'}, - {include: '#cue_language_span'}, - {include: '#cue_timestamp'}, - {include: '#cue_text_span'}, - {include: '#html_character_reference'} - ] - }, - cue_identifier: { - captures: {0: {name: 'variable.other.cue-identifier.vtt'}}, - match: '(?:^|\\G)(?!.*-->).*$', - name: 'meta.cue-identifier.vtt' - }, - cue_italics_span: {name: 'meta.cue-italics-span.vtt'}, - cue_language_span: {name: 'meta.cue-language-span.vtt'}, - cue_ruby_span: {name: 'meta.cue-ruby-span.vtt'}, - cue_settings_list: { - name: 'meta.cue-settings-list.vtt', - patterns: [ - {include: '#vertical_text_cue_setting'}, - {include: '#line_cue_setting'}, - {include: '#position_cue_setting'}, - {include: '#size_cue_setting'}, - {include: '#alignment_cue_setting'}, - {include: '#region_cue_setting'} - ] - }, - cue_text: { - name: 'meta.cue-text.vtt', - patterns: [{include: '#cue_components'}, {include: 'text.html.basic'}] - }, - cue_text_span: {name: 'meta.cue-text-span.vtt'}, - cue_timestamp: {name: 'meta.cue-timestamp.vtt'}, - cue_timings: { - captures: { - 1: { - patterns: [ - {include: '#timestamp'}, - {match: '.+', name: 'invalid.illegal.vtt'} - ] - }, - 2: {name: 'punctuation.separator.vtt'}, - 3: { - patterns: [ - {include: '#timestamp'}, - {match: '.+', name: 'invalid.illegal.vtt'} - ] - } - }, - match: '(?:^|\\G)(.+?)\\s+(-->)\\s+(.+?)(?=$)', - name: 'meta.cue-timings.vtt' - }, - cue_underline_span: {name: 'meta.cue-underline-span.vtt'}, - cue_voice_span: {name: 'meta.cue-voice-span.vtt'}, - file_body: { - begin: '^(WEBVTT)(?:\\s+(.*))?$', - beginCaptures: { - 1: {name: 'entity.name.section.webvtt.vtt'}, - 2: {name: 'comment.line.character.vtt'} - }, - name: 'meta.file-body.vtt', - patterns: [ - {include: '#region_definition_block'}, - {include: '#style_block'}, - {include: '#comment_block'}, - {include: '#cue_block'} - ] - }, - html_character_reference: {name: 'meta.html-character-reference.vtt'}, - line_cue_setting: { - captures: { - 1: {name: 'support.type.line-cue-setting.vtt'}, - 2: {name: 'punctuation.definition.colon.vtt'}, - 3: { - patterns: [ - { - captures: { - 1: { - patterns: [ - { - match: '(?:^|\\G)-?\\d+(?=$)', - name: 'constant.numeric.line-cue-setting.vtt' - }, - {include: '#percentage'}, - {match: '.+', name: 'invalid.illegal.vtt'} - ] - }, - 2: {name: 'punctuation.separator.comma.vtt'}, - 3: { - patterns: [ - { - match: '(?:^|\\G)(?:start|center|end)(?=$)', - name: 'support.constant.line-cue-setting.vtt' - }, - {match: '.+', name: 'invalid.illegal.vtt'} - ] - } - }, - match: '(?:^|\\G)(.+?)(?:(,)(.+))?(?=$)' - } - ] - } - }, - match: '(line)(:)([^\\s]+)', - name: 'meta.line-cue-setting.vtt' - }, - percentage: { - captures: {0: {name: 'constant.numeric.percentage.vtt'}}, - match: '(?:^|\\G)\\d+(?:\\.\\d+)?%(?=$)', - name: 'meta.percentage.vtt' - }, - position_cue_setting: { - captures: { - 1: {name: 'support.type.position-cue-setting.vtt'}, - 2: {name: 'punctuation.definition.colon.vtt'}, - 3: { - patterns: [ - { - captures: { - 1: { - patterns: [ - {include: '#percentage'}, - {match: '.+', name: 'invalid.illegal.vtt'} - ] - }, - 2: {name: 'punctuation.separator.comma.vtt'}, - 3: { - patterns: [ - { - match: '(?:^|\\G)(?:line-left|center|line-right)(?=$)', - name: 'support.constant.position-cue-setting.vtt' - }, - {match: '.+', name: 'invalid.illegal.vtt'} - ] - } - }, - match: '(?:^|\\G)(.+?)(?:(,)(.+))?(?=$)' - } - ] - } - }, - match: '(position)(:)([^\\s]+)', - name: 'meta.position-cue-setting.vtt' - }, - region_anchor_setting: { - captures: { - 1: {name: 'support.type.region-anchor-setting.vtt'}, - 2: {name: 'punctuation.definition.colon.vtt'}, - 3: { - patterns: [ - { - captures: { - 1: {patterns: [{include: '#percentage'}]}, - 2: {name: 'punctuation.separator.comma.vtt'}, - 3: {patterns: [{include: '#percentage'}]} - }, - match: '(.+)(,)(.+)' - }, - {match: '.+', name: 'invalid.illegal.vtt'} - ] - } - }, - match: '(regionanchor)(:)([^\\s]+)', - name: 'meta.region-anchor-setting.vtt' - }, - region_cue_setting: { - captures: { - 1: {name: 'support.type.region-cue-setting.vtt'}, - 2: {name: 'punctuation.definition.colon.vtt'}, - 3: { - patterns: [ - {match: '.*-->.*', name: 'invalid.illegal.vtt'}, - {match: '[^\\s]+', name: 'string.unquoted.region-cue-setting.vtt'} - ] - } - }, - match: '(region)(:)([^\\s]+)', - name: 'meta.region-cue-setting.vtt' - }, - region_definition_block: { - begin: '^(REGION)\\s*', - beginCaptures: {1: {name: 'entity.name.section.region.vtt'}}, - end: '^$', - name: 'meta.region-definition-block.vtt', - patterns: [{include: '#region_settings_list'}] - }, - region_identifier_setting: { - captures: { - 1: {name: 'support.type.region-identifier-setting.vtt'}, - 2: {name: 'punctuation.definition.colon.vtt'}, - 3: { - patterns: [ - {match: '.*-->.*', name: 'invalid.illegal.vtt'}, - { - match: '[^\\s]+', - name: 'string.unquoted.region-identifier-setting.vtt' - } - ] - } - }, - match: '(id)(:)([^\\s]+)', - name: 'meta.region-identifier-setting.vtt' - }, - region_lines_setting: { - captures: { - 1: {name: 'support.type.region-lines-setting.vtt'}, - 2: {name: 'punctuation.definition.colon.vtt'}, - 3: { - patterns: [ - {match: '\\d+', name: 'constant.numeric.region-lines-setting.vtt'}, - {match: '.+', name: 'invalid.illegal.vtt'} - ] - } - }, - match: '(lines)(:)([^\\s]+)', - name: 'meta.region-lines-setting.vtt' - }, - region_scroll_setting: { - captures: { - 1: {name: 'support.type.region-scroll-setting.vtt'}, - 2: {name: 'punctuation.definition.colon.vtt'}, - 3: { - patterns: [ - { - match: '(?:^|\\G)up(?=$)', - name: 'support.constant.region-scroll-setting.vtt' - }, - {match: '.+', name: 'invalid.illegal.vtt'} - ] - } - }, - match: '(scroll)(:)([^\\s]+)', - name: 'meta.region-scroll-setting.vtt' - }, - region_settings_list: { - name: 'meta.region-settings-list.vtt', - patterns: [ - {include: '#region_identifier_setting'}, - {include: '#region_width_setting'}, - {include: '#region_lines_setting'}, - {include: '#region_anchor_setting'}, - {include: '#region_viewport_anchor_setting'}, - {include: '#region_scroll_setting'} - ] - }, - region_viewport_anchor_setting: { - captures: { - 1: {name: 'support.type.region-viewport-anchor-setting.vtt'}, - 2: {name: 'punctuation.definition.colon.vtt'}, - 3: { - patterns: [ - { - captures: { - 1: {patterns: [{include: '#percentage'}]}, - 2: {name: 'punctuation.separator.comma.vtt'}, - 3: {patterns: [{include: '#percentage'}]} - }, - match: '(.*)(,)(.*)' - }, - {match: '.+', name: 'invalid.illegal.vtt'} - ] - } - }, - match: '(viewportanchor)(:)([^\\s]+)', - name: 'meta.region-viewport-anchor-setting.vtt' - }, - region_width_setting: { - captures: { - 1: {name: 'support.type.region-width-setting.vtt'}, - 2: {name: 'punctuation.definition.colon.vtt'}, - 3: { - patterns: [ - {include: '#percentage'}, - {match: '.+', name: 'invalid.illegal.vtt'} - ] - } - }, - match: '(width)(:)([^\\s]+)', - name: 'meta.region-width-setting.vtt' - }, - size_cue_setting: { - captures: { - 1: {name: 'support.type.size-cue-setting.vtt'}, - 2: {name: 'punctuation.definition.colon.vtt'}, - 3: { - patterns: [ - {include: '#percentage'}, - {match: '.+', name: 'invalid.illegal.vtt'} - ] - } - }, - match: '(size)(:)([^\\s]+)', - name: 'meta.size-cue-setting.vtt' - }, - style_block: { - begin: '^(STYLE)\\s*', - beginCaptures: {1: {name: 'entity.name.section.style.vtt'}}, - end: '^$', - name: 'meta.style-block.vtt', - patterns: [ - {match: '.*-->.*', name: 'invalid.illegal.vtt'}, - {include: 'source.css'} - ] - }, - timestamp: { - captures: { - 1: {name: 'constant.numeric.time.hour.vtt'}, - 2: {name: 'punctuation.separator.colon.vtt'}, - 3: {name: 'constant.numeric.time.minute.vtt'}, - 4: {name: 'punctuation.separator.colon.vtt'}, - 5: {name: 'constant.numeric.time.second.vtt'} - }, - match: '(?:^|\\G)(?:(\\d{2,})(:))?([0-5]\\d)(:)([0-5]\\d\\.\\d{3})(?=$)', - name: 'meta.timestamp.vtt' - }, - vertical_text_cue_setting: { - captures: { - 1: {name: 'support.type.vertical-text-cue-setting.vtt'}, - 2: {name: 'punctuation.definition.colon.vtt'}, - 3: { - patterns: [ - { - match: '(?:^|\\G)(?:rl|lr)(?=$)', - name: 'support.constant.vertical-text-cue-setting.vtt' - }, - {match: '.+', name: 'invalid.illegal.vtt'} - ] - } - }, - match: '(vertical)(:)([^\\s]+)', - name: 'meta.vertical-text-cue-setting.vtt' - } - }, - scopeName: 'source.vtt' -} - -export default grammar +// This is an alias, please use `text.vtt.js` instead. +export {default} from './text.vtt.js' diff --git a/script/build.js b/script/build.js index 9ca6a8d..b9969d9 100644 --- a/script/build.js +++ b/script/build.js @@ -18,6 +18,22 @@ import prettier from 'prettier' import jsonStableStringify from 'json-stable-stringify' import {common} from './common.js' +/** + * List of scopes renamed in `github/linguist`. + * + * Occasionally, delete all files in `lang/`, see what’s removed, + * see if there’s a new scope, and add them here. + * + * This prevents having to introduce breaking changes in `starry-night` + * + * @type {Record} + */ +const aliases = { + // Old names to new names. + 'source.brightscript': 'source.brs', + 'source.vtt': 'text.vtt' +} + const own = {}.hasOwnProperty const gemsBase = new URL('../gems/gems/', import.meta.url) const languagesBase = new URL('../lang/', import.meta.url) @@ -59,11 +75,6 @@ const prettierConfig = await prettier.resolveConfig( const gemBase = new URL(linguistBasename + '/', gemsBase) const languagesUrl = new URL('lib/linguist/languages.json', gemBase) -const ignore = new Set( - // This one actually turns into two classes on GH, which must be a bug. - ['source.pov-ray sdl'] -) - /** @type {Record, extensions?: Array, tm_scope: string}>} */ // @ts-expect-error: TS is wrong, `JSON.parse` accepts buffers. const languages = JSON.parse(await fs.readFile(languagesUrl)) @@ -138,7 +149,11 @@ for (name in languages) { const rawInfo = languages[name] const scope = rawInfo.tm_scope - assert(ignore.has(scope) || /^[-a-z\d+_.]+$/.test(scope), scope) + assert( + // This one actually turns into two classes on GH, which must be a bug. + scope === 'source.pov-ray sdl' || /^[-a-z\d+_.]+$/.test(scope), + scope + ) if (scope === 'none') { continue @@ -195,7 +210,13 @@ const grammarBasenames = await fs.readdir(grammarsBase) const scopes = grammarBasenames .flatMap((d) => { const ext = path.extname(d) - return ext === '.json' ? path.basename(d, ext) : [] + + if (ext === '.json') { + return path.basename(d, ext) + } + + assert(d === 'version', d) + return [] }) .filter((d) => linguistInfo.has(d)) @@ -287,9 +308,11 @@ await Promise.all( console.log('generated %s grammars', scopes.length) +const indices = ['common', 'all'] + // Write index files. await Promise.all( - ['common', 'all'].map(async (d) => { + indices.map(async (d) => { const list = (d === 'common' ? common : [...linguistInfo.keys()]).sort() await fs.writeFile( @@ -316,7 +339,28 @@ await Promise.all( }) ) -console.log('generated indices') +console.log('generated %s indices', indices.length) + +// Write grammars. +await Promise.all( + Object.keys(aliases).map(async (from) => { + const to = aliases[from] + + await fs.writeFile( + new URL('../lang/' + from + '.js', import.meta.url), + prettier.format( + [ + '// This is an alias, please use `' + to + '.js` instead.', + 'export {default} from "./' + to + '.js"', + '' + ].join('\n'), + {...prettierConfig, parser: 'babel'} + ) + ) + }) +) + +console.log('generated %s aliases', Object.keys(aliases).length) /** * @param {Grammar} d @@ -463,14 +507,14 @@ function clean(value, schema, path) { * @returns {string} */ function scopeToId(value) { - return ( - value - // For `c++` - .replace(/\+/g, 'p') - .replace(/[. -_]([a-z\d])/g, (_, /** @type {string} */ $1) => - $1.toUpperCase() - ) - ) + const id = value + // For `c++` + .replace(/\+/g, 'p') + .replace(/[. -_]([a-z\d])/g, (_, /** @type {string} */ $1) => + $1.toUpperCase() + ) + assert(/^[A-Za-z\d.]+$/.test(id), value) + return id } /** diff --git a/script/list.js b/script/list.js index f218fb8..fefd524 100644 --- a/script/list.js +++ b/script/list.js @@ -1,13 +1,13 @@ /** * @typedef License - * @property {string|undefined} sources + * @property {string | undefined} sources * @property {string} text * * @typedef Dep * @property {string} name * @property {string} version * @property {'git_submodule'} type - * @property {string|undefined} homepage + * @property {string | undefined} homepage * @property {string} license * @property {Array} licenses * @property {Array} notices