Skip to content

Transform languages#3948

Merged
DmitrySharabin merged 51 commits intosimplifyfrom
transform-languages
May 31, 2025
Merged

Transform languages#3948
DmitrySharabin merged 51 commits intosimplifyfrom
transform-languages

Conversation

@DmitrySharabin
Copy link
Member

I’m gonna add transformed languages here on the go.

@github-actions
Copy link

github-actions bot commented May 28, 2025

No JS Changes

Generated by 🚫 dangerJS against 3c8263d

@DmitrySharabin DmitrySharabin force-pushed the transform-languages branch 2 times, most recently from 0d3f303 to 4cd6fc1 Compare May 28, 2025 16:01
@DmitrySharabin
Copy link
Member Author

DmitrySharabin commented May 28, 2025

There are four languages (cshtml, jsx, tsx, typescript) left that use extend(), but I don't know how to transform them. Probably, they illustrate cases we haven't covered yet? 🤔

For example, in tsx, we have:

const typescript = extend('typescript', {});
const tsx = extend('jsx', typescript);

Other languages have something similar (i.e., they extend more than one language via extend()).

In typescript, we add properties from TS to an object we later use to define the grammar:

const typeInside: Grammar = {};

Object.assign(typeInside, typescript);

inside: typeInside,

@LeaVerou, HEEEEELP! 😅

Copy link
Member

@LeaVerou LeaVerou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too large to review, do you want to flag any parts that were not straightforward so I can focus on those?

@LeaVerou
Copy link
Member

There are four languages (cshtml, jsx, tsx, typescript) left that use extend(), but I don't know how to transform them. Probably, they illustrate cases we haven't covered yet? 🤔

Possibly. Let’s focus on getting the other ones merged, and I’ll take a look after.

import { toArray } from '../util/iterables';
import javascript from './javascript';
import type { GrammarToken, LanguageProto } from '../types';
import type { Grammar, LanguageProto } from '../types';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me point you to the languages I'd love you to review.

The first in this one—Flow. The reason: I used base and $merge here.

// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-reserved-words
'class-name': [
...toArray(c['class-name']),
...toArray(base!['class-name']),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this part

grammar ({ extend, getLanguage }) {
const java = getLanguage('java');
const { tag, entity } = getLanguage('markup');
base: javadoclike,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This language: javadoc

},
},
},
$tokenize: embeddedIn('markup'),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part (the latte language).

pattern:
/\b(?:(?:[01]?\d\d?|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d\d?|2[0-4]\d|25[0-5])\b/,
greedy: true,
$merge: {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This language (mongodb): because of $merge.

Comment on lines +56 to +59
'keyword': base!.keyword,
'variable': base!.variable,
'function': base!.function,
'boolean': /\b(?:false|true)\b/,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parser language: I used base inside the language definition.

'punctuation': /:/,
'variable': variable,
'operator': operator,
'important': base!.important,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part (the sass language)

pattern: /#[a-z]+\b/i,
alias: 'keyword',
},
'comment': base!.comment,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part (the sqf language)

/<\/?(?!\d)[a-z0-9]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+))?)*\s*\/?>/i;

return textile;
$merge: {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The textile language (because of $merge)

inside: {
'punctuation': /^#\[\[|\]\]#$/,
return {
$merge: {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The velocity language (because of $merge)

const tag = markup['tag'] as GrammarToken;
base: markup,
grammar ({ base }) {
const tag = base!['tag'] as GrammarToken;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part (the wiki language)

base: markup,
grammar () {
return {
$merge: {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The xquery language (because of $merge)

'tag': {
// Prevent highlighting inside <nowiki>, <source> and <pre> tags
'nowiki': {
pattern: /<(nowiki|pre|source)\b[^>]*>[\s\S]*?<\/\1>/i,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you're only inserting one token before another, $before: 'tag' in the nowiki token could help reduce the levels of indentation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is much simpler. Thank you!

Copy link
Member

@LeaVerou LeaVerou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't review in a ton of depth, but at a glance everything LGTM!

@DmitrySharabin DmitrySharabin merged commit 5660d05 into simplify May 31, 2025
2 checks passed
@DmitrySharabin DmitrySharabin deleted the transform-languages branch May 31, 2025 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants