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

Carbon language support #7011

Merged
merged 8 commits into from
Aug 29, 2024
Merged

Carbon language support #7011

merged 8 commits into from
Aug 29, 2024

Conversation

jambo-posready-embedded-7
Copy link
Contributor

@jambo-posready-embedded-7 jambo-posready-embedded-7 commented Aug 23, 2024

Adds support for the Carbon language. Carbon is an experimental language developed by Google.

Checklist

Closes #6013

@jambo-posready-embedded-7 jambo-posready-embedded-7 requested a review from a team as a code owner August 23, 2024 22:42
Copy link
Member

@lildude lildude left a comment

Choose a reason for hiding this comment

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

Please follow the CONTRIBUTING.md instructions. We will also need a search result for each extension.

@jambo-posready-embedded-7
Copy link
Contributor Author

jambo-posready-embedded-7 commented Aug 24, 2024

A basic sample in /samples/Carbon, and fixed the multiple extensions problem (.carbon is the most accepted extension, so I excluded .cb)

@lildude
Copy link
Member

lildude commented Aug 25, 2024

Do you really want to add support without syntax highlighting? Normally the only reason people add support for a language is to get syntax highlighting on GitHub.

@jambo-posready-embedded-7
Copy link
Contributor Author

@Alhadis
Copy link
Collaborator

Alhadis commented Aug 25, 2024

@btdw Usually when we add support for a language that doesn't have a syntax highlighting grammar (or one released under a permissive license), we sometimes use another language's grammar as a fallback that happens to produce "good enough" highlighting. For example, here's one of your Carbon samples highlighted using Rust:

(Click to toggle)
package Shapes api;
import Math;

// Circle

class Circle {
    var Radius: f32 = 1;
    const var Diameter: f32 = self.Radius * 2;

    const var Pi: f32 = Math.Pi;

    fn Area() -> self;
    fn Circumference() -> self;
}

fn Circle.Area() -> self {
    return Math.Pi * .Radius ^ 2
}

fn Circle.Circumference() -> self {
    return 2 * Math.Pi * .Radius
}

// Rectangle

class Rectangle {
    var Width: f32 = 3;
    var Height: f32 = 1;

    fn Area() -> self;
}

fn Rectangle.Area() -> self {
    return .Width * .Height;
}

// Square (Note: Provides same functions as "Rectangle" class.)

class Square {
    var Width: f32 = 3;
    var Height: f32 = 1;

    fn Area() -> self;
}

fn Square.Area() -> self {
    return .Width * .Height;
}

// Triangle

class Triangle {
    var Width: f32 = 3;
    var Height: f32 = 3;

    fn Area() -> self;
}

fn Triangle.Area() -> self {
    return (.Width * .Height) / 2;
}

// Hexagon

class Hexagon {
    var Side: f32 = 5;

    fn Area() -> self;
}

fn Hexagon.Area() -> self {
    return ((3 * 1.732) / 2) * .Side ^ 2
}

@jambo-posready-embedded-7
Copy link
Contributor Author

@btdw Usually when we add support for a language that doesn't have a syntax highlighting grammar (or one released under a permissive license), we sometimes use another language's grammar as a fallback that happens to produce "good enough" highlighting. For example, here's one of your Carbon samples highlighted using Rust:

I've experimented with a couple and found the syntax for V works the best:

package Shapes api;
import Math;

// Circle

class Circle {
    var Radius: f32 = 1;
    const var Diameter: f32 = self.Radius * 2;

    const var Pi: f32 = Math.Pi;

    fn Area() -> self;
    fn Circumference() -> self;
}

fn Circle.Area() -> self {
    return Math.Pi * .Radius ^ 2
}

fn Circle.Circumference() -> self {
    return 2 * Math.Pi * .Radius
}

// Rectangle

class Rectangle {
    var Width: f32 = 3;
    var Height: f32 = 1;

    fn Area() -> self;
}

fn Rectangle.Area() -> self {
    return .Width * .Height;
}

// Square (Note: Provides same functions as "Rectangle" class.)

class Square {
    var Width: f32 = 3;
    var Height: f32 = 1;

    fn Area() -> self;
}

fn Square.Area() -> self {
    return .Width * .Height;
}

// Triangle

class Triangle {
    var Width: f32 = 3;
    var Height: f32 = 3;

    fn Area() -> self;
}

fn Triangle.Area() -> self {
    return (.Width * .Height) / 2;
}

// Hexagon

class Hexagon {
    var Side: f32 = 5;

    fn Area() -> self;
}

fn Hexagon.Area() -> self {
    return ((3 * 1.732) / 2) * .Side ^ 2
}

@jambo-posready-embedded-7
Copy link
Contributor Author

I've experimented with a couple and found the syntax for V works the best:

9bdc91c adds V syntax highlighting to Carbon files

lib/linguist/languages.yml Show resolved Hide resolved
Co-authored-by: John Gardner <[email protected]>
@jambo-posready-embedded-7
Copy link
Contributor Author

Thanks for the suggestion, it was committed

Alhadis
Alhadis previously approved these changes Aug 26, 2024
@Alhadis
Copy link
Collaborator

Alhadis commented Aug 26, 2024

@btdw You'll need to fix the failed test reported here. It simply involves updating vendor/README.md to include Carbon in the list. Just add this to the file on line 75:

--- expected
+++ actual
@@ -83,6 +83,7 @@
 - **Cairo:** [xshitaka/atom-language-cairo](https://github.com/xshitaka/atom-language-cairo)
 - **CameLIGO:** [pewulfman/Ligo-grammar](https://github.com/pewulfman/Ligo-grammar)
 - **Cap'n Proto:** [textmate/capnproto.tmbundle](https://github.com/textmate/capnproto.tmbundle)
+- **Carbon:** [0x9ef/vscode-vlang](https://github.com/0x9ef/vscode-vlang)

Copy link
Member

@lildude lildude left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

Note: this PR will not be merged until close to when the next release is made. See here for more details.

@lildude lildude added this pull request to the merge queue Aug 29, 2024
Merged via the queue into github-linguist:master with commit d378ac3 Aug 29, 2024
5 checks passed
@github-linguist github-linguist locked as resolved and limited conversation to collaborators Dec 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Language: Carbon
3 participants