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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,16 @@ Cap'n Proto:
- ".capnp"
ace_mode: text
language_id: 52
Carbon:
type: programming
color: "#222222"
extensions:
- ".carbon"
ace_mode: golang
codemirror_mode: go
codemirror_mime_type: text/x-go
jambo-posready-embedded-7 marked this conversation as resolved.
Show resolved Hide resolved
tm_scope: source.v
language_id: 55627273
CartoCSS:
type: programming
aliases:
Expand Down
73 changes: 73 additions & 0 deletions samples/Carbon/Shapes.carbon
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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
}
16 changes: 16 additions & 0 deletions samples/Carbon/main.carbon
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Part of linguist/samples

import Shapes;
import "some/graphics/library"; // This does not exist (read below)

fn main() -> i32 {
// This sample does not show the usage of a real graphics library since there is no major usable graphics library for Carbon.
// As the language grows, some UI library will emerge for it and this sample can be updated.

var newGraphicRectangle: Shapes.Rectangle = {Width = 500, Height = 1250 };

var graphicsWindow: auto = Graphics.Window(newGraphicRectangle, "Window Name");
graphicsWindow.Show(true);

return 0;
}
1 change: 1 addition & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **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)
- **CartoCSS:** [yohanboniface/carto-atom](https://github.com/yohanboniface/carto-atom)
- **Ceylon:** [jeancharles-roger/ceylon-sublimetext](https://github.com/jeancharles-roger/ceylon-sublimetext)
- **Chapel:** [chapel-lang/chapel-tmbundle](https://github.com/chapel-lang/chapel-tmbundle)
Expand Down
Loading