Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GameMaker Language support #1551

Merged
merged 31 commits into from Sep 15, 2018
Merged

Add GameMaker Language support #1551

merged 31 commits into from Sep 15, 2018

Conversation

LiarOnce
Copy link
Contributor

@LiarOnce LiarOnce commented Sep 9, 2018

GameMaker is a cross-platform game engine developed by YoYo Games.
GameMaker Language is a language built into the GameMaker series (such as GameMaker 8, GameMaker: Studio, GameMaker Studio 2).
The syntax is from the official documentation, example from GMU_Anim

Copy link
Member

@RunDevelopment RunDevelopment left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!

There are however a few things we will have to fix before we can merge this:

  1. Please don't edit components.js as it is a generated file.
    Add GML to components.json add gulp will generate the .js for you.
    Also, you don't need to add the minified file yourself. gulp will also do that the next time you execute the npx gulp command.
  2. Prism uses tabs for indentation.
  3. Please wrap all your token names (e.g. keyword, function, constant, etc.) in single quotes.
    This makes your language definition easier to read plus it's what the other languages do too.
  4. Please use non-capturing groups.
  5. Aren't enum and var keywords?
  6. Consider extending c-like.
    I don't see a lot of differences between the two languages and it would make comment, function, string, and boolean obsolete.

I also left you a few comments on things that I found.

examples/prism-gml.html Outdated Show resolved Hide resolved
components/prism-gml.js Outdated Show resolved Hide resolved
components/prism-gml.js Outdated Show resolved Hide resolved
components/prism-gml.js Outdated Show resolved Hide resolved
components/prism-gml.js Outdated Show resolved Hide resolved
components/prism-gml.js Outdated Show resolved Hide resolved
@RunDevelopment
Copy link
Member

@LiarOnce

Please do not modify the README.md in this PR. I will make a separate one for this change.

@LiarOnce
Copy link
Contributor Author

LiarOnce commented Sep 9, 2018

Currently completed 1, 3, 5, 6 and I will modify it completely later.

@LiarOnce
Copy link
Contributor Author

LiarOnce commented Sep 10, 2018

@RunDevelopment
4 is completed (I am not sure if this is the case).
But I don't know how to add tabs for indentation because I don't understand it very well.

@RunDevelopment
Copy link
Member

@LiarOnce
What IDE (or text editor) are you using?

@LiarOnce
Copy link
Contributor Author

@RunDevelopment Visual Studio Code

@LiarOnce
Copy link
Contributor Author

LiarOnce commented Sep 10, 2018

@RunDevelopment Is it indent (Tab key)?

@RunDevelopment
Copy link
Member

@LiarOnce
Yes, but you will have to tell VS Code that you want to use tabs, otherwise, it will insert spaces.

To change the indentation, select the prism-gml.js. On the bottom right you will see a button Spaces: 4. Click on it and select Indent using tabs and select 4.
Press Alt + Shift + F and done.

@RunDevelopment
Copy link
Member

You can also enable the Render Whitespace preference in VS Code to see different white spaces. (I recommend the boundary option.)

@RunDevelopment
Copy link
Member

RunDevelopment commented Sep 10, 2018

@LiarOnce
You said that point 6 (extending clike) was completed and also added the dependency, but you did not actually extend clike. You have to use Prism.languages.extend to do that.

I just noticed that there is no documentation for that function, so here is a quick explanation for our example:
extend('clike', { /* your gml language */ } will create a new language based on clike.
Tokens that do not occur in clike will be appended at the end (all in order).
Tokens in clike that also exist in GML will be overwritten, so that our your new GML tokens will be used. (The clike token order will be kept.)

So our new language extending clike could look like this:

Prism.languages.gml = Prism.languages.extend('clike', {
	'keyword': ...,
	'number': ...,
	'operator': ...,
	'constant': ...,
	'variable': ...,
});

Copy link
Member

@RunDevelopment RunDevelopment left a comment

Choose a reason for hiding this comment

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

@LiarOnce
Why did you choose to keep comment, function, and string? All of them have definitions in C-like.
Or are there some cases the C-Like definition does not cover which I just don't see?

components/prism-gml.js Outdated Show resolved Hide resolved
components/prism-gml.js Outdated Show resolved Hide resolved
@LiarOnce
Copy link
Contributor Author

LiarOnce commented Sep 11, 2018

@RunDevelopment
I canceled to extend c-like because it got an unexpected error:

Uncaught TypeError: Cannot set property 'keyword' of undefined

It worked fine when I removed c-like

@RunDevelopment
Copy link
Member

@LiarOnce
Yes, that was my bad. It has to be 'clike', not 'c-like'. I fixed that in the original example.

@LiarOnce
Copy link
Contributor Author

@RunDevelopment
Now it works well.

@RunDevelopment
Copy link
Member

@LiarOnce
Works like a charm!

Now, I have a few questions and suggestions:

  1. Didn't you already move var and enum into the keyword pattern?
  2. I noticed numpad(?:0|1|2|3|4|5|6|7|8|9) in constant which is the same as numpad\d
  3. Also in the constant pattern: Can [0-9]+\.[0-9]+|[0-9]+ really match anything? All numbers are matched by number already.

@RunDevelopment
Copy link
Member

@LiarOnce
Nice!

I noticed that you accidentally reverted the alias you added. Also you will have to rebuild Prism by running gulp.

After that is done @mAAdhaTTah or @Golmote can merge it.

@LiarOnce
Copy link
Contributor Author

@RunDevelopment The alias has been restored.

components/prism-gml.js Outdated Show resolved Hide resolved
@mAAdhaTTah
Copy link
Member

Oops, I wrote this comment but never posted it:

One suuuuuuuuuuuuuuuuuuuper minor adjustment, and you need to run gulp and commit the minified version of gml.

@mAAdhaTTah
Copy link
Member

Still need to commit the minified file, then we're all set!

@LiarOnce
Copy link
Contributor Author

LiarOnce commented Sep 15, 2018

@mAAdhaTTah
The minified file is uploaded.

@mAAdhaTTah mAAdhaTTah merged commit e529edd into PrismJS:master Sep 15, 2018
@mAAdhaTTah
Copy link
Member

Thanks for the contribution!

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.

None yet

3 participants