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

Support for more languages #6

Merged
merged 8 commits into from
Jan 2, 2018
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ Todo | `.txt` | [@simurai](https://github.com/simurai)
Language | Extension | Maintainer
--- | --- | ---
CoffeeScript | `.coffee` | :wave: Maintainer wanted
C# | `.cs` | :wave: Maintainer wanted
Go | `.go` | :wave: Maintainer wanted
Java | `.java` | :wave: Maintainer wanted
JavaScript | `.js` | :wave: Maintainer wanted
PHP | `.php` | :wave: Maintainer wanted
Python | `.py` | :wave: Maintainer wanted
Ruby | `.rb` | :wave: Maintainer wanted
Typescript | `.ts` | :wave: Maintainer wanted
??? | ??? | :wave: Maintainer wanted


Expand Down
37 changes: 37 additions & 0 deletions spec/csharp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

// 1. Example ----------------------------------

public class Hello1
{
public static void Main()
{
System.Console.WriteLine("Hello, World!");
}
}


// 2. Tests ----------------------------------

public class Trio : IEnumerable
{
public string Name1 { get; set; }
public string Name2 { get; set; }
public string Name3 { get; set; }
public IEnumerator GetEnumerator() { return new TrioEnumerator(this); }
}
public class TrioEnumerator : IEnumerator
{
public TrioEnumerator(Trio trio) { _trio = trio; }
private Trio _trio;
private int _index = 0;
public void Reset() { _index = 0; Current = null; }
public object Current { get; private set; }
public bool MoveNext()
{
_index++;
/**/ if (_index == 1) { Current = _trio.Name1; return true; }
else if (_index == 2) { Current = _trio.Name2; return true; }
else if (_index == 3) { Current = _trio.Name3; return true; }
else return false;
}
}
56 changes: 56 additions & 0 deletions spec/go.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

// 1. Example ----------------------------------

package main

import "fmt"
func main() {
fmt.Println("hello world")
}


// 2. Tests ----------------------------------

// Values
fmt.Println("go" + "lang")
fmt.Println("1+1 =", 1+1)
fmt.Println("7.0/3.0 =", 7.0/3.0)
fmt.Println(true && false)
fmt.Println(true || false)
fmt.Println(!true)

// Variables
var a string = "initial"
var b, c int = 1, 2
var d = true
var e int
f := "short"

// Constants
const n = 500000000
const d = 3e20 / n

// For
for j := 7; j <= 9; j++ {
fmt.Println(j)
}

// If/Else
if 7%2 == 0 {
fmt.Println("7 is even")
} else {
fmt.Println("7 is odd")
}

// Array
b := [5]int{1, 2, 3, 4, 5}
fmt.Println("dcl:", b)

// Function
func main() {
res := plus(1, 2)
fmt.Println("1+2 =", res)

res = plusPlus(1, 2, 3)
fmt.Println("1+2+3 =", res)
}
37 changes: 37 additions & 0 deletions spec/java.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

// 1. Example ----------------------------

public class ReverseNumber {

public static void main(String[] args) {

//original number
int number = 1234;
int reversedNumber = 0;
int temp = 0;

while(number > 0){
//use modulus operator to strip off the last digit
temp = number%10;

//create the reversed number
reversedNumber = reversedNumber * 10 + temp;
number = number/10;
}

//output the reversed number
System.out.println("Reversed Number is: " + reversedNumber);
}
}


// 2. Tests ----------------------------

public class Test {
public void test(Object a) {
System.out.println("hello");
if(a instanceof String) {
System.out.println("it's me");
}
}
}
23 changes: 23 additions & 0 deletions spec/php.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

<!-- 1. Example -->

<?php
function getAdder($x) {
return function($y) use ($x) {
return $x + $y;
};
}

$adder = getAdder(8);
echo $adder(2); // prints "10"
?>

<!-- 2. Tests -->

<?php
class getAdder {
return function($y) use ($x) {
return $x + $y;
};
}
?>
40 changes: 40 additions & 0 deletions spec/python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

# 1. Example ------------------------

import unittest
def median(pool):
copy = sorted(pool)
size = len(copy)
if size % 2 == 1:
return copy[(size - 1) / 2]
else:
return (copy[size/2 - 1] + copy[size/2]) / 2
class TestMedian(unittest.TestCase):
def testMedian(self):
self.failUnlessEqual(median([2, 9, 9, 7, 9, 2, 4, 5, 8]), 7)
if __name__ == '__main__':
unittest.main()


# 2. Tests ------------------------


# Function definition is here
def printme( str ):
"This prints a passed string into this function"
print str
return;

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.error = MDText()
self.add_widget(self.error, canvas='after')

class FloatingAction(Factory.IconButton):
action = ObjectProperty(allownone=True)

def _show(self, *args):
Animation.cancel_all(self)
Animation(font_size=self.target_font_size),
d=0.1,
t='linear').start(self)
32 changes: 32 additions & 0 deletions spec/ruby.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

# 1. Example -----------------------------

class Person
attr_reader :name, :age
def initialize(name, age)
@name, @age = name, age
end
def <=>(person) # the comparison operator for sorting
age <=> person.age
end
def to_s
"#{name} (#{age})"
end
end

group = [
Person.new("Bob", 33),
Person.new("Chris", 16),
Person.new("Ash", 23)
]

puts group.sort.reverse


# 2. Tests -----------------------------

def initialize(rbconfig)

begin
File.foreeach(safefile()) do |line|
k, v = *line.split(/=/, 2)
25 changes: 25 additions & 0 deletions spec/typescript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

// Example

const myGreeter = new Greeter("hello, world");
myGreeter.greeting = "howdy";
myGreeter.showGreeting();

class SpecialGreeter extends Greeter {
constructor() {
super("Very special greetings");
}
}

// Tests

declare namespace GreetingLib {
interface LogOptions {
verbose?: boolean;
}
interface AlertOptions {
modal: boolean;
title?: string;
color?: string;
}
}
7 changes: 7 additions & 0 deletions styles/languages/_index.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@

// Supported languages
@import 'coffee';
@import 'csharp';
@import 'css';
@import 'gfm';
@import 'git-commit';
@import 'go';
@import 'html';
@import 'java';
@import 'javascript';
@import 'json';
@import 'less';
@import 'php';
@import 'python';
@import 'ruby';
@import 'scss';
@import 'text';
@import 'todo';
@import 'typescript';
9 changes: 9 additions & 0 deletions styles/languages/csharp.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// C#

.@{s}cs {

&.@{s}punctuation.@{s}punctuation {
.fg-1();
}

}
25 changes: 25 additions & 0 deletions styles/languages/go.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Go

.@{s}go {

// func
&.@{s}keyword.@{s}function {
.uno-2();
}

// import
&.@{s}keyword.@{s}import {
.uno-2();
}

// var + const
&.@{s}keyword.@{s}var,
&.@{s}keyword.@{s}const {
.tri-2();
}

&.@{s}string {
.duo-1();
}

}
10 changes: 10 additions & 0 deletions styles/languages/java.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Java

.@{s}java {

// self
&.@{s}storage.@{s}modifier {
.uno-2();
}

}
15 changes: 15 additions & 0 deletions styles/languages/php.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// PHP

.@{s}php {

// function
&.@{s}storage.@{s}type.@{s}function {
.uno-2();
}

// class
&.@{s}storage.@{s}type.@{s}class {
.tri-2();
}

}
20 changes: 20 additions & 0 deletions styles/languages/python.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Python

.@{s}python {

// def
&.@{s}storage.@{s}type.@{s}function {
.uno-2();
}

// class
&.@{s}storage.@{s}type.@{s}class {
.tri-2();
}

// self
&.@{s}self {
.duo-2();
}

}
15 changes: 15 additions & 0 deletions styles/languages/ruby.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Ruby

.@{s}ruby {

// def + end
&.@{s}keyword.@{s}control {
.uno-2();
}

// class
&.@{s}keyword.@{s}control.@{s}class {
.tri-2();
}

}
Loading