diff --git a/grammars.yml b/grammars.yml index 10361eef..35dedbe9 100644 --- a/grammars.yml +++ b/grammars.yml @@ -63,6 +63,8 @@ https://github.com/Varriount/NimLime: - source.nimrodcfg https://github.com/angryant0007/VBDotNetSyntax: - source.vbnet +https://github.com/anunayk/cool-tmbundle: +- source.cool https://github.com/aroben/ada.tmbundle/raw/c45eed4d5f98fe3bcbbffbb9e436601ab5bbde4b/Syntaxes/Ada.plist: - source.ada https://github.com/aroben/ruby.tmbundle@4636a3023153c3034eb6ffc613899ba9cf33b41f: diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 8fa52c57..a6d241d9 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -94,9 +94,11 @@ module Linguist end end - disambiguate "Common Lisp", "OpenCL" do |data| + disambiguate "Common Lisp", "OpenCL", "Cool" do |data| if data.include?("(defun ") Language["Common Lisp"] + elsif /^class/x.match(data) + Language["Cool"] elsif /\/\* |\/\/ |^\}/.match(data) Language["OpenCL"] end diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 82ce55ec..3eb6cabb 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -527,6 +527,12 @@ Component Pascal: - delphi - objectpascal +Cool: + type: programming + extensions: + - .cl + tm_scope: source.cool + Coq: type: programming extensions: diff --git a/samples/Cool/list.cl b/samples/Cool/list.cl new file mode 100644 index 00000000..3d44813e --- /dev/null +++ b/samples/Cool/list.cl @@ -0,0 +1,26 @@ +(* This simple example of a list class is adapted from an example in the + Cool distribution. *) + +class List { + isNil() : Bool { true }; + head() : Int { { abort(); 0; } }; + tail() : List { { abort(); self; } }; + cons(i : Int) : List { + (new Cons).init(i, self) + }; +}; + +class Cons inherits List { + car : Int; -- The element in this list cell + cdr : List; -- The rest of the list + isNil() : Bool { false }; + head() : Int { car }; + tail() : List { cdr }; + init(i : Int, rest : List) : List { + { + car <- i; + cdr <- rest; + self; + } + }; +}; diff --git a/samples/Cool/sample.cl b/samples/Cool/sample.cl new file mode 100644 index 00000000..e8884990 --- /dev/null +++ b/samples/Cool/sample.cl @@ -0,0 +1,71 @@ +(* Refer to Alex Aiken, "The Cool Reference Manual": + http://theory.stanford.edu/~aiken/software/cool/cool-manual.pdf + for language specification. +*) + +-- Exhibit various language constructs +class Sample { + testCondition(x: Int): Bool { + if x = 0 + then false + else + if x < (1 + 2) * 3 + then true + else false + fi + fi + }; + + testLoop(y: Int): Bool { + while y > 0 loop + { + if not condition(y) + then y <- y / 2 + else y <- y - 1; + } + pool + }; + + testAssign(z: Int): Bool { + i : Int; + i <- ~z; + }; + + testCase(var: Sample): SELF_TYPE { + io : IO <- new IO; + case var of + a : A => io.out_string("Class type is A\n"); + b : B => io.out_string("Class type is B\n"); + s : Sample => io.out_string("Class type is Sample\n"); + o : Object => io.out_string("Class type is object\n"); + esac + }; + + testLet(i: Int): Int { + let (a: Int in + let(b: Int <- 3, c: Int <- 4 in + { + a <- 2; + a * b * 2 / c; + } + ) + ) + }; +}; + +-- Used to test subclasses +class A inherits Sample {}; +class B inherits A {}; + +class C { + main() : Int { + (new Sample).testLet(1) + }; +}; + +-- "Hello, world" example +class Main inherits IO { + main(): SELF_TYPE { + out_string("Hello, World.\n") + }; +};