diff --git a/README.md b/README.md index 9e68a909..660ac00c 100644 --- a/README.md +++ b/README.md @@ -143,8 +143,8 @@ If you are the current maintainer of this gem: 0. Make sure your local dependencies are up to date: `bundle install` 0. Ensure that samples are updated: `bundle exec rake samples` 0. Ensure that tests are green: `bundle exec rake test` - 0. Bump gem version in github-linguist.gemspec. For example, [like this](https://github.com/github/linguist/commit/97908204a385940e47251af9ecb689e8f6515c48). - 0. Make a PR to github/linguist. For example, [#1075](https://github.com/github/linguist/pull/1075). + 0. Bump gem version in `lib/linguist/version.rb`. For example, [like this](https://github.com/github/linguist/commit/8d2ea90a5ba3b2fe6e1508b7155aa4632eea2985). + 0. Make a PR to github/linguist. For example, [#1238](https://github.com/github/linguist/pull/1238). 0. Build a local gem: `gem build github-linguist.gemspec` 0. Testing: 0. Bump the Gemfile and Gemfile.lock versions for an app which relies on this gem diff --git a/github-linguist.gemspec b/github-linguist.gemspec index b38abb6f..d4c2337a 100644 --- a/github-linguist.gemspec +++ b/github-linguist.gemspec @@ -13,10 +13,10 @@ Gem::Specification.new do |s| s.files = Dir['lib/**/*'] s.executables << 'linguist' - s.add_dependency 'charlock_holmes', '~> 0.7.1' + s.add_dependency 'charlock_holmes', '~> 0.7.3' s.add_dependency 'escape_utils', '~> 1.0.1' s.add_dependency 'mime-types', '~> 1.19' - s.add_dependency 'pygments.rb', '~> 0.5.4' + s.add_dependency 'pygments.rb', '~> 0.6.0' s.add_development_dependency 'json' s.add_development_dependency 'mocha' diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index 76eab7ea..15ab2d9f 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -112,6 +112,12 @@ module Linguist end end + def ruby_encoding + if hash = detect_encoding + hash[:ruby_encoding] + end + end + # Try to guess the encoding # # Returns: a Hash, with :encoding, :confidence, :type @@ -256,10 +262,16 @@ module Linguist # without changing the encoding of `data`, and # also--importantly--without having to duplicate many (potentially # large) strings. - encoded_newlines = ["\r\n", "\r", "\n"]. - map { |nl| nl.encode(encoding).force_encoding(data.encoding) } + begin + encoded_newlines = ["\r\n", "\r", "\n"]. + map { |nl| nl.encode(ruby_encoding, "ASCII-8BIT").force_encoding(data.encoding) } - data.split(Regexp.union(encoded_newlines), -1) + data.split(Regexp.union(encoded_newlines), -1) + rescue Encoding::ConverterNotFoundError + # The data is not splittable in the detected encoding. Assume it's + # one big line. + [data] + end else [] end diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 24e27408..d9c3f4f2 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -430,6 +430,14 @@ Common Lisp: - clisp - ecl +Component Pascal: + type: programming + lexer: Delphi + color: "#b0ce4e" + extensions: + - .cp + - .cps + Coq: type: programming extensions: @@ -1895,6 +1903,13 @@ SQL: - .udf - .viw +STON: + type: data + group: Smalltalk + lexer: JSON + extensions: + - .ston + Sage: type: programming lexer: Python @@ -1987,6 +2002,14 @@ Slash: extensions: - .sl +Slim: + group: HTML + type: markup + lexer: Slim + color: "#ff8877" + extensions: + - .slim + Smalltalk: type: programming color: "#596706" @@ -2017,8 +2040,9 @@ Standard ML: aliases: - sml extensions: - - .sml + - .ML - .fun + - .sml Stata: type: programming @@ -2046,6 +2070,13 @@ SuperCollider: extensions: - .scd +Swift: + type: programming + lexer: Swift + color: "#ffac45" + extensions: + - .swift + SystemVerilog: type: programming color: "#343761" @@ -2154,6 +2185,14 @@ UnrealScript: extensions: - .uc +VCL: + type: programming + lexer: Perl + ace_mode: perl + color: "#0298c3" + extensions: + - .vcl + VHDL: type: programming lexer: vhdl @@ -2342,6 +2381,14 @@ Zephir: extensions: - .zep +Zimpl: + type: programming + lexer: Text only + extensions: + - .zimpl + - .zmpl + - .zpl + eC: type: programming search_term: ec @@ -2372,6 +2419,7 @@ mupad: nesC: type: programming color: "#ffce3b" + lexer: nesC extensions: - .nc diff --git a/lib/linguist/samples.json b/lib/linguist/samples.json index de75ef9a..a2bda8c1 100644 --- a/lib/linguist/samples.json +++ b/lib/linguist/samples.json @@ -235,6 +235,10 @@ "UnrealScript": [ ".uc" ], + "Component Pascal": [ + ".cp", + ".cps" + ], "PogoScript": [ ".pogo" ], @@ -312,6 +316,9 @@ "XSLT": [ ".xslt" ], + "Zimpl": [ + ".zmpl" + ], "Groovy": [ ".gradle", ".grt", @@ -416,6 +423,9 @@ ".oxh", ".oxo" ], + "STON": [ + ".ston" + ], "Scilab": [ ".sce", ".sci", @@ -479,6 +489,9 @@ "Haskell": [ ".hs" ], + "Slim": [ + ".slim" + ], "Zephir": [ ".zep" ], @@ -486,6 +499,9 @@ ".eliom", ".ml" ], + "VCL": [ + ".vcl" + ], "Smalltalk": [ ".st" ], @@ -508,6 +524,9 @@ "Bluespec": [ ".bsv" ], + "Swift": [ + ".swift" + ], "SourcePawn": [ ".sp" ], @@ -635,6 +654,7 @@ ".h" ], "Standard ML": [ + ".ML", ".fun", ".sig", ".sml" @@ -722,8 +742,8 @@ "Rakefile" ] }, - "tokens_total": 611474, - "languages_total": 755, + "tokens_total": 614434, + "languages_total": 812, "tokens": { "Stylus": { "border": 6, @@ -29184,6 +29204,181 @@ "log": 1, "defaultproperties": 1 }, + "Component Pascal": { + "MODULE": 2, + "ObxControls": 1, + ";": 123, + "IMPORT": 2, + "Dialog": 1, + "Ports": 1, + "Properties": 1, + "Views": 1, + "CONST": 1, + "beginner": 5, + "advanced": 3, + "expert": 1, + "guru": 2, + "TYPE": 1, + "View": 6, + "POINTER": 2, + "TO": 2, + "RECORD": 2, + "(": 91, + "Views.View": 2, + ")": 94, + "size": 1, + "INTEGER": 10, + "END": 31, + "VAR": 9, + "data*": 1, + "class*": 1, + "list*": 1, + "Dialog.List": 1, + "width*": 1, + "predef": 12, + "ARRAY": 2, + "OF": 2, + "PROCEDURE": 12, + "SetList": 4, + "BEGIN": 13, + "IF": 11, + "data.class": 5, + "THEN": 12, + "data.list.SetLen": 3, + "data.list.SetItem": 11, + "ELSIF": 1, + "ELSE": 3, + "v": 6, + "CopyFromSimpleView": 2, + "source": 2, + "v.size": 10, + ".size": 1, + "Restore": 2, + "f": 1, + "Views.Frame": 1, + "l": 1, + "t": 1, + "r": 7, + "b": 1, + "[": 13, + "]": 13, + "f.DrawRect": 1, + "Ports.fill": 1, + "Ports.red": 1, + "HandlePropMsg": 2, + "msg": 2, + "Views.PropMessage": 1, + "WITH": 1, + "Properties.SizePref": 1, + "DO": 4, + "msg.w": 1, + "msg.h": 1, + "ClassNotify*": 1, + "op": 4, + "from": 2, + "to": 5, + "Dialog.changed": 2, + "OR": 4, + "&": 8, + "data.list.index": 3, + "data.width": 4, + "Dialog.Update": 2, + "data": 2, + "Dialog.UpdateList": 1, + "data.list": 1, + "ClassNotify": 1, + "ListNotify*": 1, + "ListNotify": 1, + "ListGuard*": 1, + "par": 2, + "Dialog.Par": 2, + "par.disabled": 1, + "ListGuard": 1, + "WidthGuard*": 1, + "par.readOnly": 1, + "#": 3, + "WidthGuard": 1, + "Open*": 1, + "NEW": 2, + "*": 1, + "Ports.mm": 1, + "Views.OpenAux": 1, + "Open": 1, + "ObxControls.": 1, + "ObxFact": 1, + "Stores": 1, + "Models": 1, + "TextModels": 1, + "TextControllers": 1, + "Integers": 1, + "Read": 3, + "TextModels.Reader": 2, + "x": 15, + "Integers.Integer": 3, + "i": 17, + "len": 5, + "beg": 11, + "ch": 14, + "CHAR": 3, + "buf": 5, + "r.ReadChar": 5, + "WHILE": 3, + "r.eot": 4, + "<=>": 1, + "ReadChar": 1, + "ASSERT": 1, + "eot": 1, + "<": 8, + "r.Pos": 2, + "-": 1, + "REPEAT": 3, + "INC": 4, + "UNTIL": 3, + "+": 1, + "r.SetPos": 2, + "X": 1, + "Integers.ConvertFromString": 1, + "Write": 3, + "w": 4, + "TextModels.Writer": 2, + "Integers.Sign": 2, + "w.WriteChar": 3, + "Integers.Digits10Of": 1, + "DEC": 1, + "Integers.ThisDigit10": 1, + "Compute*": 1, + "end": 6, + "n": 3, + "s": 3, + "Stores.Operation": 1, + "attr": 3, + "TextModels.Attributes": 1, + "c": 3, + "TextControllers.Controller": 1, + "TextControllers.Focus": 1, + "NIL": 3, + "c.HasSelection": 1, + "c.GetSelection": 1, + "c.text.NewReader": 1, + "r.ReadPrev": 2, + "r.attr": 1, + "Integers.Compare": 1, + "Integers.Long": 3, + "MAX": 1, + "LONGINT": 1, + "SHORT": 1, + "Integers.Short": 1, + "Integers.Product": 1, + "Models.BeginScript": 1, + "c.text": 2, + "c.text.Delete": 1, + "c.text.NewWriter": 1, + "w.SetPos": 1, + "w.SetAttr": 1, + "Models.EndScript": 1, + "Compute": 1, + "ObxFact.": 1 + }, "PogoScript": { "httpism": 1, "require": 3, @@ -33285,6 +33480,47 @@ "": 1, "": 1 }, + "Zimpl": { + "#": 2, + "param": 1, + "columns": 2, + ";": 7, + "set": 3, + "I": 3, + "{": 2, + "..": 1, + "}": 2, + "IxI": 6, + "*": 2, + "TABU": 4, + "[": 8, + "": 3, + "in": 5, + "]": 8, + "": 2, + "with": 1, + "(": 6, + "m": 4, + "i": 8, + "or": 3, + "n": 4, + "j": 8, + ")": 6, + "and": 1, + "abs": 2, + "-": 3, + "var": 1, + "x": 4, + "binary": 1, + "maximize": 1, + "queens": 1, + "sum": 2, + "subto": 1, + "c1": 1, + "forall": 1, + "do": 1, + "card": 2 + }, "Groovy": { "SHEBANG#!groovy": 2, "println": 3, @@ -41438,6 +41674,56 @@ "*AV": 1, "|": 1 }, + "STON": { + "{": 15, + "[": 11, + "]": 11, + "}": 15, + "#a": 1, + "#b": 1, + "TestDomainObject": 1, + "#created": 1, + "DateAndTime": 2, + "#modified": 1, + "#integer": 1, + "#float": 1, + "#description": 1, + "#color": 1, + "#green": 1, + "#tags": 1, + "#two": 1, + "#beta": 1, + "#medium": 1, + "#bytes": 1, + "ByteArray": 1, + "#boolean": 1, + "false": 1, + "Rectangle": 1, + "#origin": 1, + "Point": 2, + "-": 2, + "#corner": 1, + "ZnResponse": 1, + "#headers": 2, + "ZnHeaders": 1, + "ZnMultiValueDictionary": 1, + "#entity": 1, + "ZnStringEntity": 1, + "#contentType": 1, + "ZnMimeType": 1, + "#main": 1, + "#sub": 1, + "#parameters": 1, + "#contentLength": 1, + "#string": 1, + "#encoder": 1, + "ZnUTF8Encoder": 1, + "#statusLine": 1, + "ZnStatusLine": 1, + "#version": 1, + "#code": 1, + "#reason": 1 + }, "Scilab": { "disp": 1, "(": 7, @@ -44292,6 +44578,70 @@ "+": 2, "fromMaybe": 1 }, + "Slim": { + "doctype": 1, + "html": 2, + "head": 1, + "title": 1, + "Slim": 2, + "Examples": 1, + "meta": 2, + "name": 2, + "content": 2, + "author": 2, + "javascript": 1, + "alert": 1, + "(": 1, + ")": 1, + "body": 1, + "h1": 1, + "Markup": 1, + "examples": 1, + "#content": 1, + "p": 2, + "This": 1, + "example": 1, + "shows": 1, + "you": 2, + "how": 1, + "a": 1, + "basic": 1, + "file": 1, + "looks": 1, + "like.": 1, + "yield": 1, + "-": 3, + "unless": 1, + "items.empty": 1, + "table": 1, + "for": 1, + "item": 1, + "in": 1, + "items": 2, + "do": 1, + "tr": 1, + "td.name": 1, + "item.name": 1, + "td.price": 1, + "item.price": 1, + "else": 1, + "|": 2, + "No": 1, + "found.": 1, + "Please": 1, + "add": 1, + "some": 1, + "inventory.": 1, + "Thank": 1, + "div": 1, + "id": 1, + "render": 1, + "Copyright": 1, + "#": 2, + "{": 2, + "year": 1, + "}": 2 + }, "Zephir": { "namespace": 3, "Test": 2, @@ -44555,6 +44905,87 @@ "get_state": 1, "lazy_from_val": 1 }, + "VCL": { + "sub": 23, + "vcl_recv": 2, + "{": 50, + "if": 14, + "(": 50, + "req.request": 18, + "&&": 14, + ")": 50, + "return": 33, + "pipe": 4, + ";": 48, + "}": 50, + "pass": 9, + "req.http.Authorization": 2, + "||": 4, + "req.http.Cookie": 2, + "lookup": 2, + "vcl_pipe": 2, + "vcl_pass": 2, + "vcl_hash": 2, + "set": 10, + "req.hash": 3, + "+": 17, + "req.url": 2, + "req.http.host": 4, + "else": 3, + "server.ip": 2, + "hash": 2, + "vcl_hit": 2, + "obj.cacheable": 2, + "deliver": 8, + "vcl_miss": 2, + "fetch": 3, + "vcl_fetch": 2, + "obj.http.Set": 1, + "-": 21, + "Cookie": 2, + "obj.prefetch": 1, + "s": 3, + "vcl_deliver": 2, + "vcl_discard": 1, + "discard": 2, + "vcl_prefetch": 1, + "vcl_timeout": 1, + "vcl_error": 2, + "obj.http.Content": 2, + "Type": 2, + "synthetic": 2, + "utf": 2, + "//W3C//DTD": 2, + "XHTML": 2, + "Strict//EN": 2, + "http": 3, + "//www.w3.org/TR/xhtml1/DTD/xhtml1": 2, + "strict.dtd": 2, + "obj.status": 4, + "obj.response": 6, + "req.xid": 2, + "//www.varnish": 1, + "cache.org/": 1, + "req.restarts": 1, + "req.http.x": 1, + "forwarded": 1, + "for": 1, + "req.http.X": 3, + "Forwarded": 3, + "For": 3, + "client.ip": 2, + "hash_data": 3, + "beresp.ttl": 2, + "<": 1, + "beresp.http.Set": 1, + "beresp.http.Vary": 1, + "hit_for_pass": 1, + "obj.http.Retry": 1, + "After": 1, + "vcl_init": 1, + "ok": 2, + "vcl_fini": 1 + }, "Smalltalk": { "tests": 2, "testSimpleChainMatches": 1, @@ -45093,6 +45524,260 @@ "show": 1, "time": 1 }, + "Swift": { + "var": 42, + "n": 5, + "while": 2, + "<": 4, + "{": 77, + "*": 7, + "}": 77, + "m": 5, + "do": 1, + "let": 43, + "optionalSquare": 2, + "Square": 7, + "(": 89, + "sideLength": 17, + "name": 21, + ")": 89, + ".sideLength": 1, + "enum": 4, + "Suit": 2, + "case": 21, + "Spades": 1, + "Hearts": 1, + "Diamonds": 1, + "Clubs": 1, + "func": 24, + "simpleDescription": 14, + "-": 21, + "String": 27, + "switch": 4, + "self": 3, + ".Spades": 2, + "return": 30, + ".Hearts": 1, + ".Diamonds": 1, + ".Clubs": 1, + "hearts": 1, + "Suit.Hearts": 1, + "heartsDescription": 1, + "hearts.simpleDescription": 1, + "interestingNumbers": 2, + "[": 18, + "]": 18, + "largest": 4, + "for": 10, + "kind": 1, + "numbers": 6, + "in": 11, + "number": 13, + "if": 6, + "greet": 2, + "day": 1, + "apples": 1, + "oranges": 1, + "appleSummary": 1, + "fruitSummary": 1, + "struct": 2, + "Card": 2, + "rank": 2, + "Rank": 2, + "suit": 2, + "threeOfSpades": 1, + ".Three": 1, + "threeOfSpadesDescription": 1, + "threeOfSpades.simpleDescription": 1, + "anyCommonElements": 2, + "": 1, + "U": 4, + "where": 2, + "T": 5, + "Sequence": 2, + "GeneratorType": 3, + "Element": 3, + "Equatable": 1, + "lhs": 2, + "rhs": 2, + "Bool": 4, + "lhsItem": 2, + "rhsItem": 2, + "true": 2, + "false": 2, + "Int": 19, + "Ace": 1, + "Two": 1, + "Three": 1, + "Four": 1, + "Five": 1, + "Six": 1, + "Seven": 1, + "Eight": 1, + "Nine": 1, + "Ten": 1, + "Jack": 1, + "Queen": 1, + "King": 1, + ".Ace": 1, + ".Jack": 1, + ".Queen": 1, + ".King": 1, + "default": 2, + "self.toRaw": 1, + "ace": 1, + "Rank.Ace": 1, + "aceRawValue": 1, + "ace.toRaw": 1, + "sort": 1, + "returnFifteen": 2, + "y": 3, + "add": 2, + "+": 15, + "class": 7, + "Shape": 2, + "numberOfSides": 4, + "emptyArray": 1, + "emptyDictionary": 1, + "Dictionary": 1, + "": 1, + "Float": 1, + "println": 1, + "extension": 1, + "ExampleProtocol": 5, + "mutating": 3, + "adjust": 4, + "EquilateralTriangle": 4, + "NamedShape": 3, + "Double": 11, + "init": 4, + "self.sideLength": 2, + "super.init": 2, + "perimeter": 1, + "get": 2, + "set": 1, + "newValue": 1, + "/": 1, + "override": 2, + "triangle": 3, + "triangle.perimeter": 2, + "triangle.sideLength": 2, + "OptionalValue": 2, + "": 1, + "None": 1, + "Some": 1, + "possibleInteger": 2, + "": 1, + ".None": 1, + ".Some": 1, + "SimpleClass": 2, + "anotherProperty": 1, + "a": 2, + "a.adjust": 1, + "aDescription": 1, + "a.simpleDescription": 1, + "SimpleStructure": 2, + "b": 1, + "b.adjust": 1, + "bDescription": 1, + "b.simpleDescription": 1, + "Counter": 2, + "count": 2, + "incrementBy": 1, + "amount": 2, + "numberOfTimes": 2, + "times": 4, + "counter": 1, + "counter.incrementBy": 1, + "getGasPrices": 2, + "myVariable": 2, + "myConstant": 1, + "convertedRank": 1, + "Rank.fromRaw": 1, + "threeDescription": 1, + "convertedRank.simpleDescription": 1, + "protocolValue": 1, + "protocolValue.simpleDescription": 1, + "sumOf": 3, + "Int...": 1, + "sum": 3, + "individualScores": 2, + "teamScore": 4, + "score": 2, + "else": 1, + "vegetable": 2, + "vegetableComment": 4, + "x": 1, + "x.hasSuffix": 1, + "optionalString": 2, + "nil": 1, + "optionalName": 2, + "greeting": 2, + "label": 2, + "width": 2, + "widthLabel": 1, + "shape": 1, + "shape.numberOfSides": 1, + "shapeDescription": 1, + "shape.simpleDescription": 1, + "self.name": 1, + "shoppingList": 3, + "occupations": 2, + "numbers.map": 2, + "result": 5, + "area": 1, + "test": 1, + "test.area": 1, + "test.simpleDescription": 1, + "makeIncrementer": 2, + "addOne": 2, + "increment": 2, + "repeat": 2, + "": 1, + "item": 4, + "ItemType": 3, + "i": 6, + "ServerResponse": 1, + "Result": 1, + "Error": 1, + "success": 2, + "ServerResponse.Result": 1, + "failure": 1, + "ServerResponse.Error": 1, + ".Result": 1, + "sunrise": 1, + "sunset": 1, + "serverResponse": 2, + ".Error": 1, + "error": 1, + "//": 1, + "Went": 1, + "shopping": 1, + "and": 1, + "bought": 1, + "everything.": 1, + "TriangleAndSquare": 2, + "willSet": 2, + "square.sideLength": 1, + "newValue.sideLength": 2, + "square": 2, + "size": 4, + "triangleAndSquare": 1, + "triangleAndSquare.square.sideLength": 1, + "triangleAndSquare.triangle.sideLength": 2, + "triangleAndSquare.square": 1, + "protocol": 1, + "firstForLoop": 3, + "secondForLoop": 3, + ";": 2, + "implicitInteger": 1, + "implicitDouble": 1, + "explicitDouble": 1, + "hasAnyMatches": 2, + "list": 2, + "condition": 2, + "lessThanTen": 2 + }, "SourcePawn": { "//#define": 1, "DEBUG": 2, @@ -64610,59 +65295,59 @@ "git_pool_swap": 1 }, "Standard ML": { - "structure": 10, - "LazyBase": 2, - "LAZY_BASE": 3, - "struct": 9, - "type": 5, - "a": 74, - "exception": 1, - "Undefined": 3, - "fun": 51, - "delay": 3, - "f": 37, - "force": 9, - "(": 822, - ")": 826, - "val": 143, - "undefined": 1, - "fn": 124, - "raise": 5, - "end": 52, - "LazyMemoBase": 2, - "datatype": 28, - "|": 225, - "Done": 1, - "of": 90, - "lazy": 12, - "unit": 6, - "-": 19, - "let": 43, - "open": 8, - "B": 1, - "inject": 3, - "x": 59, - "isUndefined": 2, - "ignore": 2, - ";": 20, - "false": 31, - "handle": 3, - "true": 35, - "toString": 3, - "if": 50, - "then": 50, - "else": 50, - "eqBy": 3, - "p": 6, - "y": 44, - "eq": 2, - "op": 1, - "compare": 7, - "Ops": 2, - "map": 2, - "Lazy": 1, - "LazyFn": 2, - "LazyMemo": 1, + "structure": 15, + "LazyBase": 4, + "LAZY_BASE": 5, + "struct": 13, + "type": 6, + "a": 78, + "exception": 2, + "Undefined": 6, + "fun": 60, + "delay": 6, + "f": 46, + "force": 18, + "(": 840, + ")": 845, + "val": 147, + "undefined": 2, + "fn": 127, + "raise": 6, + "end": 55, + "LazyMemoBase": 4, + "datatype": 29, + "|": 226, + "Done": 2, + "of": 91, + "lazy": 13, + "unit": 7, + "-": 20, + "let": 44, + "open": 9, + "B": 2, + "inject": 5, + "x": 74, + "isUndefined": 4, + "ignore": 3, + ";": 21, + "false": 32, + "handle": 4, + "true": 36, + "toString": 4, + "if": 51, + "then": 51, + "else": 51, + "eqBy": 5, + "p": 10, + "y": 50, + "eq": 3, + "op": 2, + "compare": 8, + "Ops": 3, + "map": 3, + "Lazy": 2, + "LazyFn": 4, + "LazyMemo": 2, "functor": 2, "Main": 1, "S": 2, @@ -66377,6 +67062,7 @@ "Org": 358, "Liquid": 633, "UnrealScript": 2873, + "Component Pascal": 825, "PogoScript": 250, "Creole": 134, "Processing": 74, @@ -66398,6 +67084,7 @@ "Literate Agda": 478, "Lua": 724, "XSLT": 44, + "Zimpl": 123, "Groovy": 93, "Ioke": 2, "Jade": 3, @@ -66426,6 +67113,7 @@ "RDoc": 279, "AppleScript": 1862, "Ox": 1006, + "STON": 100, "Scilab": 69, "Dart": 74, "Nu": 116, @@ -66446,15 +67134,18 @@ "ECL": 281, "Makefile": 50, "Haskell": 302, + "Slim": 77, "Zephir": 1026, "INI": 27, "OCaml": 382, + "VCL": 545, "Smalltalk": 423, "Parrot Assembly": 6, "Protocol Buffer": 63, "SQL": 1485, "Nemerle": 17, "Bluespec": 1298, + "Swift": 1128, "SourcePawn": 2080, "Propeller Spin": 13519, "Cirru": 244, @@ -66493,7 +67184,7 @@ "PAWN": 3263, "Ruby": 3862, "C": 59053, - "Standard ML": 6405, + "Standard ML": 6567, "Logos": 93, "Omgrofl": 57, "Opa": 28, @@ -66562,6 +67253,7 @@ "Org": 1, "Liquid": 2, "UnrealScript": 2, + "Component Pascal": 2, "PogoScript": 1, "Creole": 1, "Processing": 1, @@ -66583,6 +67275,7 @@ "Literate Agda": 1, "Lua": 3, "XSLT": 1, + "Zimpl": 1, "Groovy": 5, "Ioke": 1, "Jade": 1, @@ -66611,6 +67304,7 @@ "RDoc": 1, "AppleScript": 7, "Ox": 3, + "STON": 7, "Scilab": 3, "Dart": 1, "Nu": 2, @@ -66631,15 +67325,18 @@ "ECL": 1, "Makefile": 2, "Haskell": 3, + "Slim": 1, "Zephir": 2, "INI": 2, "OCaml": 2, + "VCL": 2, "Smalltalk": 3, "Parrot Assembly": 1, "Protocol Buffer": 1, "SQL": 5, "Nemerle": 1, "Bluespec": 2, + "Swift": 43, "SourcePawn": 1, "Propeller Spin": 10, "Cirru": 9, @@ -66678,12 +67375,12 @@ "PAWN": 1, "Ruby": 17, "C": 29, - "Standard ML": 4, + "Standard ML": 5, "Logos": 1, "Omgrofl": 1, "Opa": 2, "Python": 9, "Handlebars": 2 }, - "md5": "85749fdea0f92c3c66d8ba4a1ae8f2fe" + "md5": "3fc25c40c0a47403ae658430346b2559" } \ No newline at end of file diff --git a/lib/linguist/vendor.yml b/lib/linguist/vendor.yml index 51383984..a77fa417 100644 --- a/lib/linguist/vendor.yml +++ b/lib/linguist/vendor.yml @@ -168,6 +168,9 @@ - (^|/)extjs/src/ - (^|/)extjs/welcome/ +# Html5shiv +- (^|/)html5shiv(\.min)?\.js$ + # Samples folders - ^[Ss]amples/ @@ -196,3 +199,8 @@ # Mercury --use-subdirs - Mercury/ + +# R packages +- ^vignettes/ +- ^inst/extdata/ + diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index d7627292..6704b3fb 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "2.11.1" + VERSION = "2.12.0" end diff --git a/samples/Component Pascal/Example.cp b/samples/Component Pascal/Example.cp new file mode 100644 index 00000000..5bace2c4 --- /dev/null +++ b/samples/Component Pascal/Example.cp @@ -0,0 +1,130 @@ +MODULE ObxControls; +(** + project = "BlackBox" + organization = "www.oberon.ch" + contributors = "Oberon microsystems" + version = "System/Rsrc/About" + copyright = "System/Rsrc/About" + license = "Docu/BB-License" + changes = "" + issues = "" + +**) + +IMPORT Dialog, Ports, Properties, Views; + +CONST beginner = 0; advanced = 1; expert = 2; guru = 3; (* user classes *) + +TYPE + View = POINTER TO RECORD (Views.View) + size: INTEGER (* border size in mm *) + END; + +VAR + data*: RECORD + class*: INTEGER; (* current user class *) + list*: Dialog.List; (* list of currently available sizes, derived from class *) + width*: INTEGER (* width of next view to be opened. Derived from + class, or entered through a text entry field *) + END; + + predef: ARRAY 6 OF INTEGER; (* table of predefined sizes *) + + +PROCEDURE SetList; +BEGIN + IF data.class = beginner THEN + data.list.SetLen(1); + data.list.SetItem(0, "default") + ELSIF data.class = advanced THEN + data.list.SetLen(4); + data.list.SetItem(0, "default"); + data.list.SetItem(1, "small"); + data.list.SetItem(2, "medium"); + data.list.SetItem(3, "large"); + ELSE + data.list.SetLen(6); + data.list.SetItem(0, "default"); + data.list.SetItem(1, "small"); + data.list.SetItem(2, "medium"); + data.list.SetItem(3, "large"); + data.list.SetItem(4, "tiny"); + data.list.SetItem(5, "huge"); + END +END SetList; + +(* View *) + +PROCEDURE (v: View) CopyFromSimpleView (source: Views.View); +BEGIN + v.size := source(View).size +END CopyFromSimpleView; + +PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER); +BEGIN (* fill view with a red square of size v.size *) + IF v.size = 0 THEN v.size := predef[0] END; (* lazy initialization of size *) + f.DrawRect(0, 0, v.size, v.size, Ports.fill, Ports.red) +END Restore; + +PROCEDURE (v: View) HandlePropMsg (VAR msg: Views.PropMessage); +BEGIN + WITH msg: Properties.SizePref DO + IF v.size = 0 THEN v.size := predef[0] END; (* lazy initialization of size *) + msg.w := v.size; msg.h := v.size (* tell environment about desired width and height *) + ELSE (* ignore other messages *) + END +END HandlePropMsg; + +(* notifiers *) + +PROCEDURE ClassNotify* (op, from, to: INTEGER); +BEGIN (* react to change in data.class *) + IF op = Dialog.changed THEN + IF (to = beginner) OR (to = advanced) & (data.list.index > 3) THEN + (* if class is reduced, make sure that selection contains legal elements *) + data.list.index := 0; data.width := predef[0]; (* modify interactor *) + Dialog.Update(data) (* redraw controls where necessary *) + END; + SetList; + Dialog.UpdateList(data.list) (* reconstruct list box contents *) + END +END ClassNotify; + +PROCEDURE ListNotify* (op, from, to: INTEGER); +BEGIN (* reacto to change in data.list (index to was selected) *) + IF op = Dialog.changed THEN + data.width := predef[to]; (* modify interactor *) + Dialog.Update(data) (* redraw controls where necessary *) + END +END ListNotify; + +(* guards *) + +PROCEDURE ListGuard* (VAR par: Dialog.Par); +BEGIN (* disable list box for a beginner *) + par.disabled := data.class = beginner +END ListGuard; + +PROCEDURE WidthGuard* (VAR par: Dialog.Par); +BEGIN (* make text entry field read-only if user is not guru *) + par.readOnly := data.class # guru +END WidthGuard; + +(* commands *) + +PROCEDURE Open*; + VAR v: View; +BEGIN + NEW(v); (* create and initialize a new view *) + v.size := data.width * Ports.mm; (* define view's size in function of class *) + Views.OpenAux(v, "Example") (* open the view in a window *) +END Open; + +BEGIN (* initialization of global variables *) + predef[0] := 40; predef[1] := 30; predef[2] := 50; (* predefined sizes *) + predef[3] := 70; predef[4] := 20; predef[5] := 100; + data.class := beginner; (* default values *) + data.list.index := 0; + data.width := predef[0]; + SetList +END ObxControls. diff --git a/samples/Component Pascal/Example2.cps b/samples/Component Pascal/Example2.cps new file mode 100644 index 00000000..4c4b3930 --- /dev/null +++ b/samples/Component Pascal/Example2.cps @@ -0,0 +1,71 @@ +MODULE ObxFact; +(** + project = "BlackBox" + organization = "www.oberon.ch" + contributors = "Oberon microsystems" + version = "System/Rsrc/About" + copyright = "System/Rsrc/About" + license = "Docu/BB-License" + changes = "" + issues = "" + +**) + +IMPORT + Stores, Models, TextModels, TextControllers, Integers; + +PROCEDURE Read(r: TextModels.Reader; VAR x: Integers.Integer); + VAR i, len, beg: INTEGER; ch: CHAR; buf: POINTER TO ARRAY OF CHAR; +BEGIN + r.ReadChar(ch); + WHILE ~r.eot & (ch <= " ") DO r.ReadChar(ch) END; + ASSERT(~r.eot & (((ch >= "0") & (ch <= "9")) OR (ch = "-"))); + beg := r.Pos() - 1; len := 0; + REPEAT INC(len); r.ReadChar(ch) UNTIL r.eot OR (ch < "0") OR (ch > "9"); + NEW(buf, len + 1); + i := 0; r.SetPos(beg); + REPEAT r.ReadChar(buf[i]); INC(i) UNTIL i = len; + buf[i] := 0X; + Integers.ConvertFromString(buf^, x) +END Read; + +PROCEDURE Write(w: TextModels.Writer; x: Integers.Integer); + VAR i: INTEGER; +BEGIN + IF Integers.Sign(x) < 0 THEN w.WriteChar("-") END; + i := Integers.Digits10Of(x); + IF i # 0 THEN + REPEAT DEC(i); w.WriteChar(Integers.ThisDigit10(x, i)) UNTIL i = 0 + ELSE w.WriteChar("0") + END +END Write; + +PROCEDURE Compute*; + VAR beg, end, i, n: INTEGER; ch: CHAR; + s: Stores.Operation; + r: TextModels.Reader; w: TextModels.Writer; attr: TextModels.Attributes; + c: TextControllers.Controller; + x: Integers.Integer; +BEGIN + c := TextControllers.Focus(); + IF (c # NIL) & c.HasSelection() THEN + c.GetSelection(beg, end); + r := c.text.NewReader(NIL); r.SetPos(beg); r.ReadChar(ch); + WHILE ~r.eot & (beg < end) & (ch <= " ") DO r.ReadChar(ch); INC(beg) END; + IF ~r.eot & (beg < end) THEN + r.ReadPrev; Read(r, x); + end := r.Pos(); r.ReadPrev; attr :=r.attr; + IF (Integers.Sign(x) > 0) & (Integers.Compare(x, Integers.Long(MAX(LONGINT))) <= 0) THEN + n := SHORT(Integers.Short(x)); i := 2; x := Integers.Long(1); + WHILE i <= n DO x := Integers.Product(x, Integers.Long(i)); INC(i) END; + Models.BeginScript(c.text, "computation", s); + c.text.Delete(beg, end); + w := c.text.NewWriter(NIL); w.SetPos(beg); w.SetAttr(attr); + Write(w, x); + Models.EndScript(c.text, s) + END + END + END +END Compute; + +END ObxFact. \ No newline at end of file diff --git a/samples/STON/Array.ston b/samples/STON/Array.ston new file mode 100644 index 00000000..b5d8bb58 --- /dev/null +++ b/samples/STON/Array.ston @@ -0,0 +1 @@ +[1, 2, 3] diff --git a/samples/STON/Dictionary.ston b/samples/STON/Dictionary.ston new file mode 100644 index 00000000..ae4e2731 --- /dev/null +++ b/samples/STON/Dictionary.ston @@ -0,0 +1 @@ +{#a : 1, #b : 2} diff --git a/samples/STON/Rectangle.ston b/samples/STON/Rectangle.ston new file mode 100644 index 00000000..f9c81b33 --- /dev/null +++ b/samples/STON/Rectangle.ston @@ -0,0 +1,4 @@ +Rectangle { + #origin : Point [ -40, -15 ], + #corner : Point [ 60, 35 ] + } diff --git a/samples/STON/TestDomainObject.ston b/samples/STON/TestDomainObject.ston new file mode 100644 index 00000000..d054f4c5 --- /dev/null +++ b/samples/STON/TestDomainObject.ston @@ -0,0 +1,15 @@ +TestDomainObject { + #created : DateAndTime [ '2012-02-14T16:40:15+01:00' ], + #modified : DateAndTime [ '2012-02-14T16:40:18+01:00' ], + #integer : 39581, + #float : 73.84789359463944, + #description : 'This is a test', + #color : #green, + #tags : [ + #two, + #beta, + #medium + ], + #bytes : ByteArray [ 'afabfdf61d030f43eb67960c0ae9f39f' ], + #boolean : false +} diff --git a/samples/STON/ZNResponse.ston b/samples/STON/ZNResponse.ston new file mode 100644 index 00000000..66378370 --- /dev/null +++ b/samples/STON/ZNResponse.ston @@ -0,0 +1,30 @@ +ZnResponse { + #headers : ZnHeaders { + #headers : ZnMultiValueDictionary { + 'Date' : 'Fri, 04 May 2012 20:09:23 GMT', + 'Modification-Date' : 'Thu, 10 Feb 2011 08:32:30 GMT', + 'Content-Length' : '113', + 'Server' : 'Zinc HTTP Components 1.0', + 'Vary' : 'Accept-Encoding', + 'Connection' : 'close', + 'Content-Type' : 'text/html;charset=utf-8' + } + }, + #entity : ZnStringEntity { + #contentType : ZnMimeType { + #main : 'text', + #sub : 'html', + #parameters : { + 'charset' : 'utf-8' + } + }, + #contentLength : 113, + #string : '\nSmall\n

Small

This is a small HTML document

\n\n', + #encoder : ZnUTF8Encoder { } + }, + #statusLine : ZnStatusLine { + #version : 'HTTP/1.1', + #code : 200, + #reason : 'OK' + } + } diff --git a/samples/STON/methodProperties.ston b/samples/STON/methodProperties.ston new file mode 100644 index 00000000..40a1a0fe --- /dev/null +++ b/samples/STON/methodProperties.ston @@ -0,0 +1,24 @@ +{ + "class" : { + }, + "instance" : { + "clientList:listElement:" : "dkh 03/20/2014 16:27", + "copyObjectMenuAction:selectionIndex:" : "dkh 10/13/2013 10:20", + "definitionForSelection:" : "dkh 10/13/2013 10:15", + "editMenuActionSpec" : "dkh 10/13/2013 10:19", + "itemSelected:listElement:selectedIndex:shiftPressed:" : "dkh 10/20/2013 11:06", + "menuActionSpec:" : "dkh 10/19/2013 17:12", + "repository:" : "dkh 10/19/2013 17:36", + "theList" : "dkh 10/12/2013 15:51", + "versionInfoBlock:" : "dkh 10/19/2013 17:08", + "versionInfoDiffVsSelection:selectedIndex:" : "dkh 10/19/2013 17:48", + "versionInfoDiffVsWorkingCopy:selectedIndex:" : "dkh 10/20/2013 12:36", + "versionInfoSelect:selectedIndex:" : "dkh 10/12/2013 17:04", + "versionInfos" : "dkh 10/19/2013 17:13", + "versionSummaryIsClosing" : "dkh 10/20/2013 10:19", + "windowIsClosing:" : "dkh 10/20/2013 10:39", + "windowLabel" : "dkh 05/20/2014 11:00", + "windowLocation" : "dkh 05/23/2014 10:17", + "windowName" : "dkh 10/12/2013 16:00", + "workingCopy" : "dkh 10/12/2013 16:16", + "workingCopy:" : "dkh 10/12/2013 16:17" } } diff --git a/samples/STON/properties.ston b/samples/STON/properties.ston new file mode 100644 index 00000000..b4aa0206 --- /dev/null +++ b/samples/STON/properties.ston @@ -0,0 +1,19 @@ +{ + "category" : "Topez-Server-Core", + "classinstvars" : [ + ], + "classvars" : [ + ], + "commentStamp" : "", + "instvars" : [ + "workingCopy", + "repository", + "versionInfos", + "versionInfoBlock", + "selectedVersionInfo", + "versionInfoSummaryWindowId" ], + "name" : "TDVersionInfoBrowser", + "pools" : [ + ], + "super" : "TDAbstractMonticelloToolBuilder", + "type" : "normal" } diff --git a/samples/Slim/sample.slim b/samples/Slim/sample.slim new file mode 100644 index 00000000..9480a9ff --- /dev/null +++ b/samples/Slim/sample.slim @@ -0,0 +1,31 @@ +doctype html +html + head + title Slim Examples + meta name="keywords" content="template language" + meta name="author" content=author + javascript: + alert('Slim supports embedded javascript!') + + body + h1 Markup examples + + #content + p This example shows you how a basic Slim file looks like. + + == yield + + - unless items.empty? + table + - for item in items do + tr + td.name = item.name + td.price = item.price + - else + p + | No items found. Please add some inventory. + Thank you! + + div id="footer" + = render 'footer' + | Copyright Β© #{year} #{author} diff --git a/samples/Standard ML/Foo.ML b/samples/Standard ML/Foo.ML new file mode 100644 index 00000000..2bbb789e --- /dev/null +++ b/samples/Standard ML/Foo.ML @@ -0,0 +1,75 @@ + +structure LazyBase:> LAZY_BASE = + struct + type 'a lazy = unit -> 'a + + exception Undefined + + fun delay f = f + + fun force f = f() + + val undefined = fn () => raise Undefined + end + +structure LazyMemoBase:> LAZY_BASE = + struct + + datatype 'a susp = NotYet of unit -> 'a + | Done of 'a + + type 'a lazy = unit -> 'a susp ref + + exception Undefined + + fun delay f = + let + val r = ref (NotYet f) + in + fn () => r + end + + fun force f = + case f() of + ref (Done x) => x + | r as ref (NotYet f') => + let + val a = f'() + in + r := Done a + ; a + end + + val undefined = fn () => raise Undefined + end + +functor LazyFn(B: LAZY_BASE): LAZY' = + struct + + open B + + fun inject x = delay (fn () => x) + + fun isUndefined x = + (ignore (force x) + ; false) + handle Undefined => true + + fun toString f x = if isUndefined x then "_|_" else f (force x) + + fun eqBy p (x,y) = p(force x,force y) + fun eq (x,y) = eqBy op= (x,y) + fun compare p (x,y) = p(force x,force y) + + structure Ops = + struct + val ! = force + val ? = inject + end + + fun map f x = delay (fn () => f (force x)) + + end + +structure Lazy' = LazyFn(LazyBase) +structure LazyMemo = LazyFn(LazyMemoBase) diff --git a/samples/Swift/section-11.swift b/samples/Swift/section-11.swift new file mode 100644 index 00000000..3be056ab --- /dev/null +++ b/samples/Swift/section-11.swift @@ -0,0 +1,4 @@ +let apples = 3 +let oranges = 5 +let appleSummary = "I have \(apples) apples." +let fruitSummary = "I have \(apples + oranges) pieces of fruit." diff --git a/samples/Swift/section-13.swift b/samples/Swift/section-13.swift new file mode 100644 index 00000000..06589fd7 --- /dev/null +++ b/samples/Swift/section-13.swift @@ -0,0 +1,8 @@ +var shoppingList = ["catfish", "water", "tulips", "blue paint"] +shoppingList[1] = "bottle of water" + +var occupations = [ + "Malcolm": "Captain", + "Kaylee": "Mechanic", + ] +occupations["Jayne"] = "Public Relations" diff --git a/samples/Swift/section-15.swift b/samples/Swift/section-15.swift new file mode 100644 index 00000000..3641de25 --- /dev/null +++ b/samples/Swift/section-15.swift @@ -0,0 +1,2 @@ +let emptyArray = String[]() +let emptyDictionary = Dictionary() diff --git a/samples/Swift/section-17.swift b/samples/Swift/section-17.swift new file mode 100644 index 00000000..e079c3b2 --- /dev/null +++ b/samples/Swift/section-17.swift @@ -0,0 +1 @@ +shoppingList = [] // Went shopping and bought everything. diff --git a/samples/Swift/section-19.swift b/samples/Swift/section-19.swift new file mode 100644 index 00000000..262512fc --- /dev/null +++ b/samples/Swift/section-19.swift @@ -0,0 +1,10 @@ +let individualScores = [75, 43, 103, 87, 12] +var teamScore = 0 +for score in individualScores { + if score > 50 { + teamScore += 3 + } else { + teamScore += 1 + } +} +teamScore diff --git a/samples/Swift/section-21.swift b/samples/Swift/section-21.swift new file mode 100644 index 00000000..fb06bd77 --- /dev/null +++ b/samples/Swift/section-21.swift @@ -0,0 +1,8 @@ +var optionalString: String? = "Hello" +optionalString == nil + +var optionalName: String? = "John Appleseed" +var greeting = "Hello!" +if let name = optionalName { + greeting = "Hello, \(name)" +} diff --git a/samples/Swift/section-23.swift b/samples/Swift/section-23.swift new file mode 100644 index 00000000..09f4747c --- /dev/null +++ b/samples/Swift/section-23.swift @@ -0,0 +1,11 @@ +let vegetable = "red pepper" +switch vegetable { + case "celery": + let vegetableComment = "Add some raisins and make ants on a log." + case "cucumber", "watercress": + let vegetableComment = "That would make a good tea sandwich." + case let x where x.hasSuffix("pepper"): + let vegetableComment = "Is it a spicy \(x)?" + default: + let vegetableComment = "Everything tastes good in soup." +} diff --git a/samples/Swift/section-25.swift b/samples/Swift/section-25.swift new file mode 100644 index 00000000..80e19f9c --- /dev/null +++ b/samples/Swift/section-25.swift @@ -0,0 +1,14 @@ +let interestingNumbers = [ + "Prime": [2, 3, 5, 7, 11, 13], + "Fibonacci": [1, 1, 2, 3, 5, 8], + "Square": [1, 4, 9, 16, 25], +] +var largest = 0 +for (kind, numbers) in interestingNumbers { + for number in numbers { + if number > largest { + largest = number + } + } +} +largest diff --git a/samples/Swift/section-27.swift b/samples/Swift/section-27.swift new file mode 100644 index 00000000..e2feda12 --- /dev/null +++ b/samples/Swift/section-27.swift @@ -0,0 +1,11 @@ +var n = 2 +while n < 100 { + n = n * 2 +} +n + +var m = 2 +do { + m = m * 2 +} while m < 100 +m diff --git a/samples/Swift/section-29.swift b/samples/Swift/section-29.swift new file mode 100644 index 00000000..b269cf97 --- /dev/null +++ b/samples/Swift/section-29.swift @@ -0,0 +1,11 @@ +var firstForLoop = 0 +for i in 0..3 { + firstForLoop += i +} +firstForLoop + +var secondForLoop = 0 +for var i = 0; i < 3; ++i { + secondForLoop += 1 +} +secondForLoop diff --git a/samples/Swift/section-3.swift b/samples/Swift/section-3.swift new file mode 100644 index 00000000..47ea7d53 --- /dev/null +++ b/samples/Swift/section-3.swift @@ -0,0 +1 @@ +println("Hello, world") diff --git a/samples/Swift/section-31.swift b/samples/Swift/section-31.swift new file mode 100644 index 00000000..9b77ea62 --- /dev/null +++ b/samples/Swift/section-31.swift @@ -0,0 +1,4 @@ +func greet(name: String, day: String) -> String { + return "Hello \(name), today is \(day)." +} +greet("Bob", "Tuesday") diff --git a/samples/Swift/section-33.swift b/samples/Swift/section-33.swift new file mode 100644 index 00000000..89361a75 --- /dev/null +++ b/samples/Swift/section-33.swift @@ -0,0 +1,4 @@ +func getGasPrices() -> (Double, Double, Double) { + return (3.59, 3.69, 3.79) +} +getGasPrices() diff --git a/samples/Swift/section-35.swift b/samples/Swift/section-35.swift new file mode 100644 index 00000000..c724746f --- /dev/null +++ b/samples/Swift/section-35.swift @@ -0,0 +1,9 @@ +func sumOf(numbers: Int...) -> Int { + var sum = 0 + for number in numbers { + sum += number + } + return sum +} +sumOf() +sumOf(42, 597, 12) diff --git a/samples/Swift/section-37.swift b/samples/Swift/section-37.swift new file mode 100644 index 00000000..f78fdbe9 --- /dev/null +++ b/samples/Swift/section-37.swift @@ -0,0 +1,9 @@ +func returnFifteen() -> Int { + var y = 10 + func add() { + y += 5 + } + add() + return y +} +returnFifteen() diff --git a/samples/Swift/section-39.swift b/samples/Swift/section-39.swift new file mode 100644 index 00000000..d2fa5fe3 --- /dev/null +++ b/samples/Swift/section-39.swift @@ -0,0 +1,8 @@ +func makeIncrementer() -> (Int -> Int) { + func addOne(number: Int) -> Int { + return 1 + number + } + return addOne +} +var increment = makeIncrementer() +increment(7) diff --git a/samples/Swift/section-41.swift b/samples/Swift/section-41.swift new file mode 100644 index 00000000..e72d410a --- /dev/null +++ b/samples/Swift/section-41.swift @@ -0,0 +1,13 @@ +func hasAnyMatches(list: Int[], condition: Int -> Bool) -> Bool { + for item in list { + if condition(item) { + return true + } + } + return false +} +func lessThanTen(number: Int) -> Bool { + return number < 10 +} +var numbers = [20, 19, 7, 12] +hasAnyMatches(numbers, lessThanTen) diff --git a/samples/Swift/section-43.swift b/samples/Swift/section-43.swift new file mode 100644 index 00000000..5dee10f7 --- /dev/null +++ b/samples/Swift/section-43.swift @@ -0,0 +1,5 @@ +numbers.map({ + (number: Int) -> Int in + let result = 3 * number + return result +}) diff --git a/samples/Swift/section-45.swift b/samples/Swift/section-45.swift new file mode 100644 index 00000000..dbf29eed --- /dev/null +++ b/samples/Swift/section-45.swift @@ -0,0 +1 @@ +numbers.map({ number in 3 * number }) diff --git a/samples/Swift/section-47.swift b/samples/Swift/section-47.swift new file mode 100644 index 00000000..73defb77 --- /dev/null +++ b/samples/Swift/section-47.swift @@ -0,0 +1 @@ +sort([1, 5, 3, 12, 2]) { $0 > $1 } diff --git a/samples/Swift/section-49.swift b/samples/Swift/section-49.swift new file mode 100644 index 00000000..69739b8d --- /dev/null +++ b/samples/Swift/section-49.swift @@ -0,0 +1,6 @@ +class Shape { + var numberOfSides = 0 + func simpleDescription() -> String { + return "A shape with \(numberOfSides) sides." + } +} diff --git a/samples/Swift/section-5.swift b/samples/Swift/section-5.swift new file mode 100644 index 00000000..885d5812 --- /dev/null +++ b/samples/Swift/section-5.swift @@ -0,0 +1,3 @@ +var myVariable = 42 +myVariable = 50 +let myConstant = 42 diff --git a/samples/Swift/section-51.swift b/samples/Swift/section-51.swift new file mode 100644 index 00000000..a84750c8 --- /dev/null +++ b/samples/Swift/section-51.swift @@ -0,0 +1,3 @@ +var shape = Shape() +shape.numberOfSides = 7 +var shapeDescription = shape.simpleDescription() diff --git a/samples/Swift/section-53.swift b/samples/Swift/section-53.swift new file mode 100644 index 00000000..74aac461 --- /dev/null +++ b/samples/Swift/section-53.swift @@ -0,0 +1,12 @@ +class NamedShape { + var numberOfSides: Int = 0 + var name: String + + init(name: String) { + self.name = name + } + + func simpleDescription() -> String { + return "A shape with \(numberOfSides) sides." + } +} diff --git a/samples/Swift/section-55.swift b/samples/Swift/section-55.swift new file mode 100644 index 00000000..6e489078 --- /dev/null +++ b/samples/Swift/section-55.swift @@ -0,0 +1,20 @@ +class Square: NamedShape { + var sideLength: Double + + init(sideLength: Double, name: String) { + self.sideLength = sideLength + super.init(name: name) + numberOfSides = 4 + } + + func area() -> Double { + return sideLength * sideLength + } + + override func simpleDescription() -> String { + return "A square with sides of length \(sideLength)." + } +} +let test = Square(sideLength: 5.2, name: "my test square") +test.area() +test.simpleDescription() diff --git a/samples/Swift/section-57.swift b/samples/Swift/section-57.swift new file mode 100644 index 00000000..90d2e03c --- /dev/null +++ b/samples/Swift/section-57.swift @@ -0,0 +1,26 @@ +class EquilateralTriangle: NamedShape { + var sideLength: Double = 0.0 + + init(sideLength: Double, name: String) { + self.sideLength = sideLength + super.init(name: name) + numberOfSides = 3 + } + + var perimeter: Double { + get { + return 3.0 * sideLength + } + set { + sideLength = newValue / 3.0 + } + } + + override func simpleDescription() -> String { + return "An equilateral triagle with sides of length \(sideLength)." + } +} +var triangle = EquilateralTriangle(sideLength: 3.1, name: "a triangle") +triangle.perimeter +triangle.perimeter = 9.9 +triangle.sideLength diff --git a/samples/Swift/section-59.swift b/samples/Swift/section-59.swift new file mode 100644 index 00000000..21e3b09d --- /dev/null +++ b/samples/Swift/section-59.swift @@ -0,0 +1,21 @@ +class TriangleAndSquare { + var triangle: EquilateralTriangle { + willSet { + square.sideLength = newValue.sideLength + } + } + var square: Square { + willSet { + triangle.sideLength = newValue.sideLength + } + } + init(size: Double, name: String) { + square = Square(sideLength: size, name: name) + triangle = EquilateralTriangle(sideLength: size, name: name) + } +} +var triangleAndSquare = TriangleAndSquare(size: 10, name: "another test shape") +triangleAndSquare.square.sideLength +triangleAndSquare.triangle.sideLength +triangleAndSquare.square = Square(sideLength: 50, name: "larger square") +triangleAndSquare.triangle.sideLength diff --git a/samples/Swift/section-61.swift b/samples/Swift/section-61.swift new file mode 100644 index 00000000..013ded74 --- /dev/null +++ b/samples/Swift/section-61.swift @@ -0,0 +1,8 @@ +class Counter { + var count: Int = 0 + func incrementBy(amount: Int, numberOfTimes times: Int) { + count += amount * times + } +} +var counter = Counter() +counter.incrementBy(2, numberOfTimes: 7) diff --git a/samples/Swift/section-63.swift b/samples/Swift/section-63.swift new file mode 100644 index 00000000..9305cfc7 --- /dev/null +++ b/samples/Swift/section-63.swift @@ -0,0 +1,2 @@ +let optionalSquare: Square? = Square(sideLength: 2.5, name: "optional square") +let sideLength = optionalSquare?.sideLength diff --git a/samples/Swift/section-65.swift b/samples/Swift/section-65.swift new file mode 100644 index 00000000..809c71ce --- /dev/null +++ b/samples/Swift/section-65.swift @@ -0,0 +1,21 @@ +enum Rank: Int { + case Ace = 1 + case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten + case Jack, Queen, King + func simpleDescription() -> String { + switch self { + case .Ace: + return "ace" + case .Jack: + return "jack" + case .Queen: + return "queen" + case .King: + return "king" + default: + return String(self.toRaw()) + } + } +} +let ace = Rank.Ace +let aceRawValue = ace.toRaw() diff --git a/samples/Swift/section-67.swift b/samples/Swift/section-67.swift new file mode 100644 index 00000000..d5be66c2 --- /dev/null +++ b/samples/Swift/section-67.swift @@ -0,0 +1,3 @@ +if let convertedRank = Rank.fromRaw(3) { + let threeDescription = convertedRank.simpleDescription() +} diff --git a/samples/Swift/section-69.swift b/samples/Swift/section-69.swift new file mode 100644 index 00000000..fc6d7a4c --- /dev/null +++ b/samples/Swift/section-69.swift @@ -0,0 +1,17 @@ +enum Suit { + case Spades, Hearts, Diamonds, Clubs + func simpleDescription() -> String { + switch self { + case .Spades: + return "spades" + case .Hearts: + return "hearts" + case .Diamonds: + return "diamonds" + case .Clubs: + return "clubs" + } + } +} +let hearts = Suit.Hearts +let heartsDescription = hearts.simpleDescription() diff --git a/samples/Swift/section-7.swift b/samples/Swift/section-7.swift new file mode 100644 index 00000000..7d55c034 --- /dev/null +++ b/samples/Swift/section-7.swift @@ -0,0 +1,3 @@ +let implicitInteger = 70 +let implicitDouble = 70.0 +let explicitDouble: Double = 70 diff --git a/samples/Swift/section-71.swift b/samples/Swift/section-71.swift new file mode 100644 index 00000000..f006d0f9 --- /dev/null +++ b/samples/Swift/section-71.swift @@ -0,0 +1,9 @@ +struct Card { + var rank: Rank + var suit: Suit + func simpleDescription() -> String { + return "The \(rank.simpleDescription()) of \(suit.simpleDescription())" + } +} +let threeOfSpades = Card(rank: .Three, suit: .Spades) +let threeOfSpadesDescription = threeOfSpades.simpleDescription() diff --git a/samples/Swift/section-73.swift b/samples/Swift/section-73.swift new file mode 100644 index 00000000..be0cf35f --- /dev/null +++ b/samples/Swift/section-73.swift @@ -0,0 +1,14 @@ +enum ServerResponse { + case Result(String, String) + case Error(String) +} + +let success = ServerResponse.Result("6:00 am", "8:09 pm") +let failure = ServerResponse.Error("Out of cheese.") + +switch success { + case let .Result(sunrise, sunset): + let serverResponse = "Sunrise is at \(sunrise) and sunset is at \(sunset)." + case let .Error(error): + let serverResponse = "Failure... \(error)" +} diff --git a/samples/Swift/section-75.swift b/samples/Swift/section-75.swift new file mode 100644 index 00000000..46dd36da --- /dev/null +++ b/samples/Swift/section-75.swift @@ -0,0 +1,4 @@ +protocol ExampleProtocol { + var simpleDescription: String { get } + mutating func adjust() +} diff --git a/samples/Swift/section-77.swift b/samples/Swift/section-77.swift new file mode 100644 index 00000000..bc052d20 --- /dev/null +++ b/samples/Swift/section-77.swift @@ -0,0 +1,20 @@ +class SimpleClass: ExampleProtocol { + var simpleDescription: String = "A very simple class." + var anotherProperty: Int = 69105 + func adjust() { + simpleDescription += " Now 100% adjusted." + } +} +var a = SimpleClass() +a.adjust() +let aDescription = a.simpleDescription + +struct SimpleStructure: ExampleProtocol { + var simpleDescription: String = "A simple structure" + mutating func adjust() { + simpleDescription += " (adjusted)" + } +} +var b = SimpleStructure() +b.adjust() +let bDescription = b.simpleDescription diff --git a/samples/Swift/section-79.swift b/samples/Swift/section-79.swift new file mode 100644 index 00000000..0e7b831b --- /dev/null +++ b/samples/Swift/section-79.swift @@ -0,0 +1,9 @@ +extension Int: ExampleProtocol { + var simpleDescription: String { + return "The number \(self)" + } + mutating func adjust() { + self += 42 + } + } +7.simpleDescription diff --git a/samples/Swift/section-81.swift b/samples/Swift/section-81.swift new file mode 100644 index 00000000..74e0a000 --- /dev/null +++ b/samples/Swift/section-81.swift @@ -0,0 +1,3 @@ +let protocolValue: ExampleProtocol = a +protocolValue.simpleDescription +// protocolValue.anotherProperty // Uncomment to see the error diff --git a/samples/Swift/section-83.swift b/samples/Swift/section-83.swift new file mode 100644 index 00000000..aa2e6d75 --- /dev/null +++ b/samples/Swift/section-83.swift @@ -0,0 +1,8 @@ +func repeat(item: ItemType, times: Int) -> ItemType[] { + var result = ItemType[]() + for i in 0..times { + result += item + } + return result +} +repeat("knock", 4) diff --git a/samples/Swift/section-85.swift b/samples/Swift/section-85.swift new file mode 100644 index 00000000..b2f52840 --- /dev/null +++ b/samples/Swift/section-85.swift @@ -0,0 +1,7 @@ +// Reimplement the Swift standard library's optional type +enum OptionalValue { + case None + case Some(T) +} +var possibleInteger: OptionalValue = .None +possibleInteger = .Some(100) diff --git a/samples/Swift/section-87.swift b/samples/Swift/section-87.swift new file mode 100644 index 00000000..f9dc7f33 --- /dev/null +++ b/samples/Swift/section-87.swift @@ -0,0 +1,11 @@ +func anyCommonElements (lhs: T, rhs: U) -> Bool { + for lhsItem in lhs { + for rhsItem in rhs { + if lhsItem == rhsItem { + return true + } + } + } + return false +} +anyCommonElements([1, 2, 3], [3]) diff --git a/samples/Swift/section-9.swift b/samples/Swift/section-9.swift new file mode 100644 index 00000000..2e83efa1 --- /dev/null +++ b/samples/Swift/section-9.swift @@ -0,0 +1,3 @@ +let label = "The width is " +let width = 94 +let widthLabel = label + String(width) diff --git a/samples/Text/ISO-2022-KR.txt b/samples/Text/ISO-2022-KR.txt new file mode 100644 index 00000000..721d7051 --- /dev/null +++ b/samples/Text/ISO-2022-KR.txt @@ -0,0 +1,43 @@ +$)C# +# Out-AnsiGraph.psm1 +# Author: xcud +# History: +# v0.1 September 21, 2009 initial version +# +# PS Example> ps | select -first 5 | sort -property VM | +# Out-AnsiGraph ProcessName, VM +# AEADISRV  14508032 +# audiodg  50757632 +# conhost  73740288 +# AppleMobileDeviceService  92061696 +# btdna  126443520 +# +function Out-AnsiGraph($Parameter1=$null) { + BEGIN { + $q = new-object Collections.queue + $max = 0; $namewidth = 0; + } + + PROCESS { + if($_) { + $name = $_.($Parameter1[0]); + $val = $_.($Parameter1[1]) + if($max -lt $val) { $max = $val} + if($namewidth -lt $name.length) { + $namewidth = $name.length } + $q.enqueue(@($name, $val)) + } + } + + END { + $q | %{ + $graph = ""; 0..($_[1]/$max*20) | + %{ $graph += "" } + $name = "{0,$namewidth}" -f $_[0] + "$name $graph " + $_[1] + } + + } +} + +Export-ModuleMember Out-AnsiGraph \ No newline at end of file diff --git a/samples/Text/Visual_Battlers.rb b/samples/Text/Visual_Battlers.rb new file mode 100644 index 00000000..74bb0f2c --- /dev/null +++ b/samples/Text/Visual_Battlers.rb @@ -0,0 +1,703 @@ +#============================================================================== +# +# ₯ Yanfly Engine Ace - Visual Battlers v1.01 +# -- Last Updated: 2012.07.24 +# -- Level: Easy +# -- Requires: n/a +# +# ₯ Modified by: +# -- Yami +# -- Kread-Ex +# -- Archeia_Nessiah +#============================================================================== + +$imported = {} if $imported.nil? +$imported["YEA-VisualBattlers"] = true + +#============================================================================== +# ₯ Updates +# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +# 2012.12.18 - Added preset views and able to change direction in-game. +# 2012.07.24 - Finished Script. +# 2012.01.05 - Started Script. +# +#============================================================================== +# ₯ Introduction +# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +# This script provides a visual for all actors by default charsets. The actions +# and movements are alike Final Fantasy 1, only move forward and backward when +# start and finish actions. +# +#============================================================================== +# ₯ Instructions +# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +# To change the player direction in-game, use the snippet below in a script +# call: +# +# $game_system.party_direction = n +# +# To install this script, open up your script editor and copy/paste this script +# to an open slot below ₯ Materials but above ₯ Main. Remember to save. +# +#============================================================================== +# ₯ Compatibility +# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that +# it will run with RPG Maker VX without adjusting. +# +#============================================================================== + +module YEA + module VISUAL_BATTLERS + + #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- + # - Party Location Setting - + #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- + # These settings are adjusted for Party Location. Each Actor will have + # coordinates calculated by below formula. There are two samples coordinates + # below, change PARTY_DIRECTION to the base index you want to use. + #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- + PARTY_DIRECTION = 6 # This direction is opposite from actual direction. + + PARTY_LOCATION_BASE_COORDINATES ={ + # Index => [base_x, base_y, mod_x, mod_y], + 2 => [ 250, 290, 40, 0], #UP + 4 => [ 150, 280, 20, -20], #LEFT + 3 => [ 460, 280, 30, -10], #RIGHT + 6 => [ 460, 230, 20, 20], #DEFAULT RIGHT + 8 => [ 260, 230, 40, 0], #DOWN + } # Do not remove this. + + PARTY_LOCATION_FORMULA_X = "base_x + index * mod_x" + PARTY_LOCATION_FORMULA_Y = "base_y + index * mod_y" + + end # VISUAL_BATTLERS +end # YEA + +#============================================================================== +# ₯ Editting anything past this point may potentially result in causing +# computer damage, incontinence, explosion of user's head, coma, death, and/or +# halitosis so edit at your own risk. +#============================================================================== + +#============================================================================== +# ? ₯ Direction +#============================================================================== + +module Direction + + #-------------------------------------------------------------------------- + # self.correct + #-------------------------------------------------------------------------- + def self.correct(direction) + case direction + when 1; return 4 + when 3; return 6 + when 7; return 4 + when 9; return 6 + else; return direction + end + end + + #-------------------------------------------------------------------------- + # self.opposite + #-------------------------------------------------------------------------- + def self.opposite(direction) + case direction + when 1; return 6 + when 2; return 8 + when 3; return 4 + when 4; return 6 + when 6; return 4 + when 7; return 6 + when 8; return 2 + when 9; return 4 + else; return direction + end + end + +end # Direction + +#============================================================================== +# ? ₯ Game_System +#============================================================================== + +class Game_System; attr_accessor :party_direction; end + +#============================================================================== +# ? ₯ Game_BattleCharacter +#============================================================================== + +class Game_BattleCharacter < Game_Character + + #-------------------------------------------------------------------------- + # initialize + #-------------------------------------------------------------------------- + def initialize(actor) + super() + setup_actor(actor) + @move_x_rate = 0 + @move_y_rate = 0 + end + + #-------------------------------------------------------------------------- + # setup_actor + #-------------------------------------------------------------------------- + def setup_actor(actor) + @actor = actor + @step_anime = true + set_graphic(@actor.character_name, @actor.character_index) + setup_coordinates + dr = $game_system.party_direction || YEA::VISUAL_BATTLERS::PARTY_DIRECTION + direction = Direction.opposite(dr) + set_direction(Direction.correct(direction)) + end + + #-------------------------------------------------------------------------- + # sprite= + #-------------------------------------------------------------------------- + def sprite=(sprite) + @sprite = sprite + end + + #-------------------------------------------------------------------------- + # setup_coordinates + #-------------------------------------------------------------------------- + def setup_coordinates + location = ($game_system.party_direction || + YEA::VISUAL_BATTLERS::PARTY_DIRECTION) + base_x = YEA::VISUAL_BATTLERS::PARTY_LOCATION_BASE_COORDINATES[location][0] + base_y = YEA::VISUAL_BATTLERS::PARTY_LOCATION_BASE_COORDINATES[location][1] + mod_x = YEA::VISUAL_BATTLERS::PARTY_LOCATION_BASE_COORDINATES[location][2] + mod_y = YEA::VISUAL_BATTLERS::PARTY_LOCATION_BASE_COORDINATES[location][3] + @actor.screen_x = eval(YEA::VISUAL_BATTLERS::PARTY_LOCATION_FORMULA_X) + @actor.screen_y = eval(YEA::VISUAL_BATTLERS::PARTY_LOCATION_FORMULA_Y) + @actor.origin_x = @actor.screen_x + @actor.origin_y = @actor.screen_y + @actor.create_move_to(screen_x, screen_y, 1) + end + + #-------------------------------------------------------------------------- + # index + #-------------------------------------------------------------------------- + def index + return @actor.index + end + + #-------------------------------------------------------------------------- + # screen_x + #-------------------------------------------------------------------------- + def screen_x + return @actor.screen_x + end + + #-------------------------------------------------------------------------- + # screen_y + #-------------------------------------------------------------------------- + def screen_y + return @actor.screen_y + end + + #-------------------------------------------------------------------------- + # screen_z + #-------------------------------------------------------------------------- + def screen_z + return @actor.screen_z + end + +end # Game_BattleCharacter + +#============================================================================== +# ? ₯ Game_Battler +#============================================================================== + +class Game_Battler < Game_BattlerBase + + #-------------------------------------------------------------------------- + # public instance variables + #-------------------------------------------------------------------------- + attr_accessor :moved_back + attr_accessor :origin_x + attr_accessor :origin_y + attr_accessor :screen_x + attr_accessor :screen_y + attr_accessor :started_turn + + #-------------------------------------------------------------------------- + # alias method: execute_damage + #-------------------------------------------------------------------------- + alias game_battler_execute_damage_vb execute_damage + def execute_damage(user) + game_battler_execute_damage_vb(user) + if @result.hp_damage > 0 + move_backward(24, 6) unless @moved_back + @moved_back = true + end + end + + #-------------------------------------------------------------------------- + # face_opposing_party + #-------------------------------------------------------------------------- + def face_opposing_party + direction = ($game_system.party_direction || + YEA::VISUAL_BATTLERS::PARTY_DIRECTION) + character.set_direction(Direction.correct(direction)) rescue 0 + end + + #-------------------------------------------------------------------------- + # new method: face_coordinate + #-------------------------------------------------------------------------- + def face_coordinate(destination_x, destination_y) + x1 = Integer(@screen_x) + x2 = Integer(destination_x) + y1 = Graphics.height - Integer(@screen_y) + y2 = Graphics.height - Integer(destination_y) + return if x1 == x2 and y1 == y2 + #--- + angle = Integer(Math.atan2((y2-y1),(x2-x1)) * 1800 / Math::PI) + if (0..225) === angle or (-225..0) === angle + direction = 6 + elsif (226..675) === angle + direction = 9 + elsif (676..1125) === angle + direction = 8 + elsif (1126..1575) === angle + direction = 7 + elsif (1576..1800) === angle or (-1800..-1576) === angle + direction = 4 + elsif (-1575..-1126) === angle + direction = 1 + elsif (-1125..-676) === angle + direction = 2 + elsif (-675..-226) === angle + direction = 3 + end + #--- + character.set_direction(Direction.correct(direction)) rescue 0 + end + + #-------------------------------------------------------------------------- + # create_move_to + #-------------------------------------------------------------------------- + def create_move_to(destination_x, destination_y, frames = 12) + @destination_x = destination_x + @destination_y = destination_y + frames = [frames, 1].max + @move_x_rate = [(@screen_x - @destination_x).abs / frames, 2].max + @move_y_rate = [(@screen_y - @destination_y).abs / frames, 2].max + end + + #-------------------------------------------------------------------------- + # update_move_to + #-------------------------------------------------------------------------- + def update_move_to + @move_x_rate = 0 if @screen_x == @destination_x || @move_x_rate.nil? + @move_y_rate = 0 if @screen_y == @destination_y || @move_y_rate.nil? + value = [(@screen_x - @destination_x).abs, @move_x_rate].min + @screen_x += (@destination_x > @screen_x) ? value : -value + value = [(@screen_y - @destination_y).abs, @move_y_rate].min + @screen_y += (@destination_y > @screen_y) ? value : -value + end + + #-------------------------------------------------------------------------- + # move_forward + #-------------------------------------------------------------------------- + def move_forward(distance = 24, frames = 12) + direction = forward_direction + move_direction(direction, distance, frames) + end + + #-------------------------------------------------------------------------- + # move_backward + #-------------------------------------------------------------------------- + def move_backward(distance = 24, frames = 12) + direction = Direction.opposite(forward_direction) + move_direction(direction, distance, frames) + end + + #-------------------------------------------------------------------------- + # move_direction + #-------------------------------------------------------------------------- + def move_direction(direction, distance = 24, frames = 12) + case direction + when 1; move_x = distance / -2; move_y = distance / 2 + when 2; move_x = distance * 0; move_y = distance * 1 + when 3; move_x = distance / -2; move_y = distance / 2 + when 4; move_x = distance * -1; move_y = distance * 0 + when 6; move_x = distance * 1; move_y = distance * 0 + when 7; move_x = distance / -2; move_y = distance / -2 + when 8; move_x = distance * 0; move_y = distance * -1 + when 9; move_x = distance / 2; move_y = distance / -2 + else; return + end + destination_x = @screen_x + move_x + destination_y = @screen_y + move_y + create_move_to(destination_x, destination_y, frames) + end + + #-------------------------------------------------------------------------- + # forward_direction + #-------------------------------------------------------------------------- + def forward_direction + return ($game_system.party_direction || + YEA::VISUAL_BATTLERS::PARTY_DIRECTION) + end + + #-------------------------------------------------------------------------- + # move_origin + #-------------------------------------------------------------------------- + def move_origin + create_move_to(@origin_x, @origin_y) + face_coordinate(@origin_x, @origin_y) + @moved_back = false + end + + #-------------------------------------------------------------------------- + # moving? + #-------------------------------------------------------------------------- + def moving? + return false if dead? || !exist? + return @move_x_rate != 0 || @move_y_rate != 0 + end + +end # Game_Battler + +#============================================================================== +# ? ₯ Game_Actor +#============================================================================== + +class Game_Actor < Game_Battler + + #-------------------------------------------------------------------------- + # overwrite method: use_sprite? + #-------------------------------------------------------------------------- + def use_sprite? + return true + end + + #-------------------------------------------------------------------------- + # new method: screen_x + #-------------------------------------------------------------------------- + def screen_x + return @screen_x rescue 0 + end + + #-------------------------------------------------------------------------- + # new method: screen_y + #-------------------------------------------------------------------------- + def screen_y + return @screen_y rescue 0 + end + + #-------------------------------------------------------------------------- + # new method: screen_z + #-------------------------------------------------------------------------- + def screen_z + return 100 + end + + #-------------------------------------------------------------------------- + # new method: sprite + #-------------------------------------------------------------------------- + def sprite + index = $game_party.battle_members.index(self) + return SceneManager.scene.spriteset.actor_sprites[index] + end + + #-------------------------------------------------------------------------- + # new method: character + #-------------------------------------------------------------------------- + def character + return sprite.character_base + end + + #-------------------------------------------------------------------------- + # face_opposing_party + #-------------------------------------------------------------------------- + def face_opposing_party + dr = $game_system.party_direction || YEA::VISUAL_BATTLERS::PARTY_DIRECTION + direction = Direction.opposite(dr) + character.set_direction(Direction.correct(direction)) rescue 0 + end + + #-------------------------------------------------------------------------- + # forward_direction + #-------------------------------------------------------------------------- + def forward_direction + return Direction.opposite(($game_system.party_direction || + YEA::VISUAL_BATTLERS::PARTY_DIRECTION)) + end + +end # Game_Actor + +#============================================================================== +# ? ₯ Game_Enemy +#============================================================================== + +class Game_Enemy < Game_Battler + + #-------------------------------------------------------------------------- + # new method: sprite + #-------------------------------------------------------------------------- + def sprite + return SceneManager.scene.spriteset.enemy_sprites.reverse[self.index] + end + + #-------------------------------------------------------------------------- + # new method: character + #-------------------------------------------------------------------------- + def character + return sprite + end + +end # Game_Enemy + +#============================================================================== +# ? ₯ Game_Troop +#============================================================================== + +class Game_Troop < Game_Unit + + #-------------------------------------------------------------------------- + # alias method: setup + #-------------------------------------------------------------------------- + alias game_troop_setup_vb setup + def setup(troop_id) + game_troop_setup_vb(troop_id) + set_coordinates + end + + #-------------------------------------------------------------------------- + # new method: set_coordinates + #-------------------------------------------------------------------------- + def set_coordinates + for member in members + member.origin_x = member.screen_x + member.origin_y = member.screen_y + member.create_move_to(member.screen_x, member.screen_y, 1) + end + end + +end # Game_Troop + +#============================================================================== +# ? ₯ Sprite_Battler +#============================================================================== + +class Sprite_Battler < Sprite_Base + + #-------------------------------------------------------------------------- + # public instance_variable + #-------------------------------------------------------------------------- + attr_accessor :character_base + attr_accessor :character_sprite + + #-------------------------------------------------------------------------- + # alias method: dispose + #-------------------------------------------------------------------------- + alias sprite_battler_dispose_vb dispose + def dispose + dispose_character_sprite + sprite_battler_dispose_vb + end + + #-------------------------------------------------------------------------- + # new method: dispose_character_sprite + #-------------------------------------------------------------------------- + def dispose_character_sprite + @character_sprite.dispose unless @character_sprite.nil? + end + + #-------------------------------------------------------------------------- + # alias method: update + #-------------------------------------------------------------------------- + alias sprite_battler_update_vb update + def update + sprite_battler_update_vb + return if @battler.nil? + update_move_to + update_character_base + update_character_sprite + end + + #-------------------------------------------------------------------------- + # new method: update_character_base + #-------------------------------------------------------------------------- + def update_character_base + return if @character_base.nil? + @character_base.update + end + + #-------------------------------------------------------------------------- + # new method: update_character_sprite + #-------------------------------------------------------------------------- + def update_character_sprite + return if @character_sprite.nil? + @character_sprite.update + end + + #-------------------------------------------------------------------------- + # new method: update_move_to + #-------------------------------------------------------------------------- + def update_move_to + @battler.update_move_to + end + + #-------------------------------------------------------------------------- + # new method: moving? + #-------------------------------------------------------------------------- + def moving? + return false if @battler.nil? + return @battler.moving? + end + +end # Sprite_Battler + +#============================================================================== +# ? ₯ Sprite_BattleCharacter +#============================================================================== + +class Sprite_BattleCharacter < Sprite_Character + + #-------------------------------------------------------------------------- + # initialize + #-------------------------------------------------------------------------- + def initialize(viewport, character = nil) + super(viewport, character) + character.sprite = self + end + +end # Sprite_BattleCharacter + +#============================================================================== +# ? ₯ Spriteset_Battle +#============================================================================== + +class Spriteset_Battle + + #-------------------------------------------------------------------------- + # public instance_variable + #-------------------------------------------------------------------------- + attr_accessor :actor_sprites + attr_accessor :enemy_sprites + + #-------------------------------------------------------------------------- + # overwrite method: create_actors + #-------------------------------------------------------------------------- + def create_actors + total = $game_party.max_battle_members + @current_party = $game_party.battle_members.clone + @actor_sprites = Array.new(total) { Sprite_Battler.new(@viewport1) } + for actor in $game_party.battle_members + @actor_sprites[actor.index].battler = actor + create_actor_sprite(actor) + end + end + + #-------------------------------------------------------------------------- + # new method: create_actor_sprite + #-------------------------------------------------------------------------- + def create_actor_sprite(actor) + character = Game_BattleCharacter.new(actor) + character_sprite = Sprite_BattleCharacter.new(@viewport1, character) + @actor_sprites[actor.index].character_base = character + @actor_sprites[actor.index].character_sprite = character_sprite + actor.face_opposing_party + end + + #-------------------------------------------------------------------------- + # alias method: update_actors + #-------------------------------------------------------------------------- + alias spriteset_battle_update_actors_vb update_actors + def update_actors + if @current_party != $game_party.battle_members + dispose_actors + create_actors + end + spriteset_battle_update_actors_vb + end + + #-------------------------------------------------------------------------- + # new method: moving? + #-------------------------------------------------------------------------- + def moving? + return battler_sprites.any? {|sprite| sprite.moving? } + end + +end # Spriteset_Battle + +#============================================================================== +# ? ₯ Scene_Battle +#============================================================================== + +class Scene_Battle < Scene_Base + + #-------------------------------------------------------------------------- + # public instance variables + #-------------------------------------------------------------------------- + attr_accessor :spriteset + + #-------------------------------------------------------------------------- + # alias method: process_action_end + #-------------------------------------------------------------------------- + alias scene_battle_process_action_end_vb process_action_end + def process_action_end + start_battler_move_origin + scene_battle_process_action_end_vb + end + + #-------------------------------------------------------------------------- + # alias method: execute_action + #-------------------------------------------------------------------------- + alias scene_battle_execute_action_vb execute_action + def execute_action + start_battler_move_forward + scene_battle_execute_action_vb + end + + #-------------------------------------------------------------------------- + # new method: start_battler_move_forward + #-------------------------------------------------------------------------- + def start_battler_move_forward + return if @subject.started_turn + @subject.started_turn = true + @subject.move_forward + wait_for_moving + end + + #-------------------------------------------------------------------------- + # new method: start_battler_move_origin + #-------------------------------------------------------------------------- + def start_battler_move_origin + @subject.started_turn = nil + move_battlers_origin + wait_for_moving + @subject.face_opposing_party rescue 0 + end + + #-------------------------------------------------------------------------- + # new method: move_battlers_origin + #-------------------------------------------------------------------------- + def move_battlers_origin + for member in all_battle_members + next if member.dead? + next unless member.exist? + member.move_origin + end + end + + #-------------------------------------------------------------------------- + # new method: wait_for_moving + #-------------------------------------------------------------------------- + def wait_for_moving + update_for_wait + update_for_wait while @spriteset.moving? + end + +end # Scene_Battle + +#============================================================================== +# +# ₯ End of File +# +#============================================================================== diff --git a/samples/Text/iso8859-8-i.txt b/samples/Text/iso8859-8-i.txt new file mode 100644 index 00000000..ed2bf6c4 --- /dev/null +++ b/samples/Text/iso8859-8-i.txt @@ -0,0 +1 @@ +%Ώαι \ No newline at end of file diff --git a/samples/VCL/varnish2_default.vcl b/samples/VCL/varnish2_default.vcl new file mode 100644 index 00000000..9b01881f --- /dev/null +++ b/samples/VCL/varnish2_default.vcl @@ -0,0 +1,152 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2008 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id$ + * + * The default VCL code. + * + * NB! You do NOT need to copy & paste all of these functions into your + * own vcl code, if you do not provide a definition of one of these + * functions, the compiler will automatically fall back to the default + * code from this file. + * + * This code will be prefixed with a backend declaration built from the + * -b argument. + */ + +sub vcl_recv { + if (req.request != "GET" && + req.request != "HEAD" && + req.request != "PUT" && + req.request != "POST" && + req.request != "TRACE" && + req.request != "OPTIONS" && + req.request != "DELETE") { + /* Non-RFC2616 or CONNECT which is weird. */ + return (pipe); + } + if (req.request != "GET" && req.request != "HEAD") { + /* We only deal with GET and HEAD by default */ + return (pass); + } + if (req.http.Authorization || req.http.Cookie) { + /* Not cacheable by default */ + return (pass); + } + return (lookup); +} + +sub vcl_pipe { + # Note that only the first request to the backend will have + # X-Forwarded-For set. If you use X-Forwarded-For and want to + # have it set for all requests, make sure to have: + # set req.http.connection = "close"; + # here. It is not set by default as it might break some broken web + # applications, like IIS with NTLM authentication. + return (pipe); +} + +sub vcl_pass { + return (pass); +} + +sub vcl_hash { + set req.hash += req.url; + if (req.http.host) { + set req.hash += req.http.host; + } else { + set req.hash += server.ip; + } + return (hash); +} + +sub vcl_hit { + if (!obj.cacheable) { + return (pass); + } + return (deliver); +} + +sub vcl_miss { + return (fetch); +} + +sub vcl_fetch { + if (!obj.cacheable) { + return (pass); + } + if (obj.http.Set-Cookie) { + return (pass); + } + set obj.prefetch = -30s; + return (deliver); +} + +sub vcl_deliver { + return (deliver); +} + +sub vcl_discard { + /* XXX: Do not redefine vcl_discard{}, it is not yet supported */ + return (discard); +} + +sub vcl_prefetch { + /* XXX: Do not redefine vcl_prefetch{}, it is not yet supported */ + return (fetch); +} + +sub vcl_timeout { + /* XXX: Do not redefine vcl_timeout{}, it is not yet supported */ + return (discard); +} + +sub vcl_error { + set obj.http.Content-Type = "text/html; charset=utf-8"; + synthetic {" + + + + + "} obj.status " " obj.response {" + + +

Error "} obj.status " " obj.response {"

+

"} obj.response {"

+

Guru Meditation:

+

XID: "} req.xid {"

+
+
+ Varnish cache server +
+ + +"}; + return (deliver); +} diff --git a/samples/VCL/varnish3_default.vcl b/samples/VCL/varnish3_default.vcl new file mode 100644 index 00000000..412b6e94 --- /dev/null +++ b/samples/VCL/varnish3_default.vcl @@ -0,0 +1,149 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2011 Varnish Software AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The default VCL code. + * + * NB! You do NOT need to copy & paste all of these functions into your + * own vcl code, if you do not provide a definition of one of these + * functions, the compiler will automatically fall back to the default + * code from this file. + * + * This code will be prefixed with a backend declaration built from the + * -b argument. + */ + +sub vcl_recv { + if (req.restarts == 0) { + if (req.http.x-forwarded-for) { + set req.http.X-Forwarded-For = + req.http.X-Forwarded-For + ", " + client.ip; + } else { + set req.http.X-Forwarded-For = client.ip; + } + } + if (req.request != "GET" && + req.request != "HEAD" && + req.request != "PUT" && + req.request != "POST" && + req.request != "TRACE" && + req.request != "OPTIONS" && + req.request != "DELETE") { + /* Non-RFC2616 or CONNECT which is weird. */ + return (pipe); + } + if (req.request != "GET" && req.request != "HEAD") { + /* We only deal with GET and HEAD by default */ + return (pass); + } + if (req.http.Authorization || req.http.Cookie) { + /* Not cacheable by default */ + return (pass); + } + return (lookup); +} + +sub vcl_pipe { + # Note that only the first request to the backend will have + # X-Forwarded-For set. If you use X-Forwarded-For and want to + # have it set for all requests, make sure to have: + # set bereq.http.connection = "close"; + # here. It is not set by default as it might break some broken web + # applications, like IIS with NTLM authentication. + return (pipe); +} + +sub vcl_pass { + return (pass); +} + +sub vcl_hash { + hash_data(req.url); + if (req.http.host) { + hash_data(req.http.host); + } else { + hash_data(server.ip); + } + return (hash); +} + +sub vcl_hit { + return (deliver); +} + +sub vcl_miss { + return (fetch); +} + +sub vcl_fetch { + if (beresp.ttl <= 0s || + beresp.http.Set-Cookie || + beresp.http.Vary == "*") { + /* + * Mark as "Hit-For-Pass" for the next 2 minutes + */ + set beresp.ttl = 120 s; + return (hit_for_pass); + } + return (deliver); +} + +sub vcl_deliver { + return (deliver); +} + +sub vcl_error { + set obj.http.Content-Type = "text/html; charset=utf-8"; + set obj.http.Retry-After = "5"; + synthetic {" + + + + + "} + obj.status + " " + obj.response + {" + + +

Error "} + obj.status + " " + obj.response + {"

+

"} + obj.response + {"

+

Guru Meditation:

+

XID: "} + req.xid + {"

+
+

Varnish cache server

+ + +"}; + return (deliver); +} + +sub vcl_init { + return (ok); +} + +sub vcl_fini { + return (ok); +} diff --git a/samples/Zimpl/sample.zmpl b/samples/Zimpl/sample.zmpl new file mode 100644 index 00000000..ade112cd --- /dev/null +++ b/samples/Zimpl/sample.zmpl @@ -0,0 +1,21 @@ +# $Id: queens3.zpl,v 1.3 2009/09/13 16:15:53 bzfkocht Exp $ +# +# This is a formulation of the n queens problem using binary variables. +# variables. Since the number of queens is maximized, the size of the +# board can be set arbitrarily. +# +param columns := 8; + +set I := { 1 .. columns }; +set IxI := I * I; + +set TABU[ in IxI] := { in IxI with + (m != i or n != j) and (m == i or n == j or abs(m - i) == abs(n - j)) }; + +var x[IxI] binary; + +maximize queens: sum in IxI : x[i,j]; + +subto c1: forall in IxI do + card(TABU[i,j]) - card(TABU[i,j]) * x[i,j] >= sum in TABU[i,j] : x[m,n]; + diff --git a/test/test_blob.rb b/test/test_blob.rb index da13b96e..23a649ec 100644 --- a/test/test_blob.rb +++ b/test/test_blob.rb @@ -97,15 +97,26 @@ class TestBlob < Test::Unit::TestCase def test_sloc assert_equal 2, blob("Ruby/foo.rb").sloc assert_equal 3, blob("Text/utf16le-windows.txt").sloc + assert_equal 1, blob("Text/iso8859-8-i.txt").sloc end def test_encoding assert_equal "ISO-8859-2", blob("Text/README").encoding + assert_equal "ISO-8859-2", blob("Text/README").ruby_encoding assert_equal "ISO-8859-1", blob("Text/dump.sql").encoding + assert_equal "ISO-8859-1", blob("Text/dump.sql").ruby_encoding assert_equal "UTF-8", blob("Text/foo.txt").encoding + assert_equal "UTF-8", blob("Text/foo.txt").ruby_encoding assert_equal "UTF-16LE", blob("Text/utf16le.txt").encoding + assert_equal "UTF-16LE", blob("Text/utf16le.txt").ruby_encoding assert_equal "UTF-16LE", blob("Text/utf16le-windows.txt").encoding + assert_equal "UTF-16LE", blob("Text/utf16le-windows.txt").ruby_encoding + assert_equal "ISO-2022-KR", blob("Text/ISO-2022-KR.txt").encoding + assert_equal "binary", blob("Text/ISO-2022-KR.txt").ruby_encoding assert_nil blob("Binary/dog.o").encoding + + assert_equal "windows-1252", blob("Text/Visual_Battlers.rb").encoding + assert_equal "Windows-1252", blob("Text/Visual_Battlers.rb").ruby_encoding end def test_binary @@ -363,6 +374,10 @@ class TestBlob < Test::Unit::TestCase # NuGet Packages assert blob("packages/Modernizr.2.0.6/Content/Scripts/modernizr-2.0.6-development-only.js").vendored? + + # Html5shiv + assert blob("Scripts/html5shiv.js").vendored? + assert blob("Scripts/html5shiv.min.js").vendored? # Test fixtures assert blob("test/fixtures/random.rkt").vendored?