From a978c4eb34f81fde3fa7b4cf1e76e43c045b7f79 Mon Sep 17 00:00:00 2001 From: Oldes Date: Tue, 29 Apr 2014 23:04:53 +0200 Subject: [PATCH 1/8] Red language (red-lang.org) --- lib/linguist/languages.yml | 8 ++ samples/Red/example.red | 257 +++++++++++++++++++++++++++++++++++++ samples/Red/example.reds | 124 ++++++++++++++++++ 3 files changed, 389 insertions(+) create mode 100644 samples/Red/example.red create mode 100644 samples/Red/example.reds diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 70302378..962d525c 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1655,6 +1655,14 @@ Rebol: - .r3 - .rebol +Red language: + type: programming + lexer: Red + color: "#ee0000" + primary_extension: .red + extensions: + - .reds + Redcode: primary_extension: .cw diff --git a/samples/Red/example.red b/samples/Red/example.red new file mode 100644 index 00000000..66a5ada3 --- /dev/null +++ b/samples/Red/example.red @@ -0,0 +1,257 @@ +Red [ + Title: "Red console" + Author: ["Nenad Rakocevic" "Kaj de Vos"] + File: %console.red + Tabs: 4 + Rights: "Copyright (C) 2012-2013 Nenad Rakocevic. All rights reserved." + License: { + Distributed under the Boost Software License, Version 1.0. + See https://github.com/dockimbel/Red/blob/master/BSL-License.txt + } + Purpose: "Just some code for testing Pygments colorizer" + Language: http://www.red-lang.org/ +] + +#system-global [ + #either OS = 'Windows [ + #import [ + "kernel32.dll" stdcall [ + AttachConsole: "AttachConsole" [ + processID [integer!] + return: [integer!] + ] + SetConsoleTitle: "SetConsoleTitleA" [ + title [c-string!] + return: [integer!] + ] + ReadConsole: "ReadConsoleA" [ + consoleInput [integer!] + buffer [byte-ptr!] + charsToRead [integer!] + numberOfChars [int-ptr!] + inputControl [int-ptr!] + return: [integer!] + ] + ] + ] + line-buffer-size: 16 * 1024 + line-buffer: allocate line-buffer-size + ][ + #switch OS [ + MacOSX [ + #define ReadLine-library "libreadline.dylib" + ] + #default [ + #define ReadLine-library "libreadline.so.6" + #define History-library "libhistory.so.6" + ] + ] + #import [ + ReadLine-library cdecl [ + read-line: "readline" [ ; Read a line from the console. + prompt [c-string!] + return: [c-string!] + ] + rl-bind-key: "rl_bind_key" [ + key [integer!] + command [integer!] + return: [integer!] + ] + rl-insert: "rl_insert" [ + count [integer!] + key [integer!] + return: [integer!] + ] + ] + #if OS <> 'MacOSX [ + History-library cdecl [ + add-history: "add_history" [ ; Add line to the history. + line [c-string!] + ] + ] + ] + ] + + rl-insert-wrapper: func [ + [cdecl] + count [integer!] + key [integer!] + return: [integer!] + ][ + rl-insert count key + ] + + ] +] + +Windows?: system/platform = 'Windows + +read-argument: routine [ + /local + args [str-array!] + str [red-string!] +][ + if system/args-count <> 2 [ + SET_RETURN(none-value) + exit + ] + args: system/args-list + 1 ;-- skip binary filename + str: simple-io/read-txt args/item + SET_RETURN(str) +] + +init-console: routine [ + str [string!] + /local + ret +][ + #either OS = 'Windows [ + ;ret: AttachConsole -1 + ;if zero? ret [print-line "ReadConsole failed!" halt] + + ret: SetConsoleTitle as c-string! string/rs-head str + if zero? ret [print-line "SetConsoleTitle failed!" halt] + ][ + rl-bind-key as-integer tab as-integer :rl-insert-wrapper + ] +] + +input: routine [ + prompt [string!] + /local + len ret str buffer line +][ + #either OS = 'Windows [ + len: 0 + print as c-string! string/rs-head prompt + ret: ReadConsole stdin line-buffer line-buffer-size :len null + if zero? ret [print-line "ReadConsole failed!" halt] + len: len + 1 + line-buffer/len: null-byte + str: string/load as c-string! line-buffer len + ][ + line: read-line as c-string! string/rs-head prompt + if line = null [halt] ; EOF + + #if OS <> 'MacOSX [add-history line] + + str: string/load line 1 + length? line +; free as byte-ptr! line + ] + SET_RETURN(str) +] + +count-delimiters: function [ + buffer [string!] + return: [block!] +][ + list: copy [0 0] + c: none + + foreach c buffer [ + case [ + escaped? [ + escaped?: no + ] + in-comment? [ + switch c [ + #"^/" [in-comment?: no] + ] + ] + 'else [ + switch c [ + #"^^" [escaped?: yes] + #";" [if zero? list/2 [in-comment?: yes]] + #"[" [list/1: list/1 + 1] + #"]" [list/1: list/1 - 1] + #"{" [list/2: list/2 + 1] + #"}" [list/2: list/2 - 1] + ] + ] + ] + ] + list +] + +do-console: function [][ + buffer: make string! 10000 + prompt: red-prompt: "red>> " + mode: 'mono + + switch-mode: [ + mode: case [ + cnt/1 > 0 ['block] + cnt/2 > 0 ['string] + 'else [ + prompt: red-prompt + do eval + 'mono + ] + ] + prompt: switch mode [ + block ["[^-"] + string ["{^-"] + mono [red-prompt] + ] + ] + + eval: [ + code: load/all buffer + + unless tail? code [ + set/any 'result do code + + unless unset? :result [ + if 67 = length? result: mold/part :result 67 [ ;-- optimized for width = 72 + clear back tail result + append result "..." + ] + print ["==" result] + ] + ] + clear buffer + ] + + while [true][ + unless tail? line: input prompt [ + append buffer line + cnt: count-delimiters buffer + + either Windows? [ + remove skip tail buffer -2 ;-- clear extra CR (Windows) + ][ + append buffer lf ;-- Unix + ] + + switch mode [ + block [if cnt/1 <= 0 [do switch-mode]] + string [if cnt/2 <= 0 [do switch-mode]] + mono [do either any [cnt/1 > 0 cnt/2 > 0][switch-mode][eval]] + ] + ] + ] +] + +q: :quit + +if script: read-argument [ + script: load script + either any [ + script/1 <> 'Red + not block? script/2 + ][ + print "*** Error: not a Red program!" + ][ + do skip script 2 + ] + quit +] + +init-console "Red Console" + +print { +-=== Red Console alpha version ===- +(only ASCII input supported) +} + +do-console \ No newline at end of file diff --git a/samples/Red/example.reds b/samples/Red/example.reds new file mode 100644 index 00000000..dd4ad0f9 --- /dev/null +++ b/samples/Red/example.reds @@ -0,0 +1,124 @@ +Red/System [ + Title: "Red/System example file" + Purpose: "Just some code for testing Pygments colorizer" + Language: http://www.red-lang.org/ +] + +#include %../common/FPU-configuration.reds + +; C types + +#define time! long! +#define clock! long! + +date!: alias struct! [ + second [integer!] ; 0-61 (60?) + minute [integer!] ; 0-59 + hour [integer!] ; 0-23 + + day [integer!] ; 1-31 + month [integer!] ; 0-11 + year [integer!] ; Since 1900 + + weekday [integer!] ; 0-6 since Sunday + yearday [integer!] ; 0-365 + daylight-saving-time? [integer!] ; Negative: unknown +] + +#either OS = 'Windows [ + #define clocks-per-second 1000 +][ + ; CLOCKS_PER_SEC value for Syllable, Linux (XSI-conformant systems) + ; TODO: check for other systems + #define clocks-per-second 1000'000 +] + +#import [LIBC-file cdecl [ + + ; Error handling + + form-error: "strerror" [ ; Return error description. + code [integer!] + return: [c-string!] + ] + print-error: "perror" [ ; Print error to standard error output. + string [c-string!] + ] + + + ; Memory management + + make: "calloc" [ ; Allocate zero-filled memory. + chunks [size!] + size [size!] + return: [binary!] + ] + resize: "realloc" [ ; Resize memory allocation. + memory [binary!] + size [size!] + return: [binary!] + ] + ] + + JVM!: alias struct! [ + reserved0 [int-ptr!] + reserved1 [int-ptr!] + reserved2 [int-ptr!] + + DestroyJavaVM [function! [[JNICALL] vm [JVM-ptr!] return: [jint!]]] + AttachCurrentThread [function! [[JNICALL] vm [JVM-ptr!] penv [struct! [p [int-ptr!]]] args [byte-ptr!] return: [jint!]]] + DetachCurrentThread [function! [[JNICALL] vm [JVM-ptr!] return: [jint!]]] + GetEnv [function! [[JNICALL] vm [JVM-ptr!] penv [struct! [p [int-ptr!]]] version [integer!] return: [jint!]]] + AttachCurrentThreadAsDaemon [function! [[JNICALL] vm [JVM-ptr!] penv [struct! [p [int-ptr!]]] args [byte-ptr!] return: [jint!]]] +] + + ;just some datatypes for testing: + + #some-hash + 10-1-2013 + quit + + ;binary: + #{00FF0000} + #{00FF0000 FF000000} + #{00FF0000 FF000000} ;with tab instead of space + 2#{00001111} + 64#{/wAAAA==} + 64#{/wAAA A==} ;with space inside + 64#{/wAAA A==} ;with tab inside + + + ;string with char + {bla ^(ff) foo} + {bla ^(( foo} + ;some numbers: + 12 + 1'000 + 1.2 + FF00FF00h + + ;some tests of hexa number notation with not common ending + [ff00h ff00h] ff00h{} FFh"foo" 00h(1 + 2) (AEh) + +;normal words: +foo char + +;get-word +:foo + +;lit-word: +'foo 'foo + +to-integer foo +foo/(a + 1)/b + +call/output reform ['which interpreter] path: copy "" + + version-1.1: 00010001h + + #if type = 'exe [ + push system/stack/frame ;-- save previous frame pointer + system/stack/frame: system/stack/top ;-- @@ reposition frame pointer just after the catch flag +] +push CATCH_ALL ;-- exceptions root barrier +push 0 ;-- keep stack aligned on 64-bit \ No newline at end of file From ea45db38e90d44f3ebf891ccabb776c7436744b5 Mon Sep 17 00:00:00 2001 From: Oldes Date: Tue, 29 Apr 2014 23:09:24 +0200 Subject: [PATCH 2/8] Changed name to just: Red --- lib/linguist/languages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 962d525c..2e15071c 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1655,7 +1655,7 @@ Rebol: - .r3 - .rebol -Red language: +Red: type: programming lexer: Red color: "#ee0000" From 5c3d32cafd465b46699a87e581e5e12e15767015 Mon Sep 17 00:00:00 2001 From: Oldes Date: Tue, 29 Apr 2014 23:28:39 +0200 Subject: [PATCH 3/8] Using Text lexer untill proper lexer will be accepted --- lib/linguist/languages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 2e15071c..3b413dfd 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1657,7 +1657,7 @@ Rebol: Red: type: programming - lexer: Red + lexer: Text color: "#ee0000" primary_extension: .red extensions: From cf5646d45a825d70f53b1de236976612b73e32a4 Mon Sep 17 00:00:00 2001 From: Oldes Date: Tue, 29 Apr 2014 23:32:30 +0200 Subject: [PATCH 4/8] Fixing the Text only lexer --- lib/linguist/languages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 3b413dfd..9cd4e5e4 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1657,7 +1657,7 @@ Rebol: Red: type: programming - lexer: Text + lexer: Text only color: "#ee0000" primary_extension: .red extensions: From 7e81a9e50b24ebdfbb18570145bfe1e879fc6d22 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Fri, 2 May 2014 13:43:24 -0500 Subject: [PATCH 5/8] Updating escape_utils --- github-linguist.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github-linguist.gemspec b/github-linguist.gemspec index 9d2f73c1..df0943e1 100644 --- a/github-linguist.gemspec +++ b/github-linguist.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.executables << 'linguist' s.add_dependency 'charlock_holmes', '~> 0.6.6' - s.add_dependency 'escape_utils', '>= 0.3.1' + s.add_dependency 'escape_utils', '~> 1.0.1' s.add_dependency 'mime-types', '~> 1.19' s.add_dependency 'pygments.rb', '~> 0.5.4' From 84e43d7d3f4c76540300824a3a1a4d9cfcdcd6be Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Fri, 2 May 2014 15:07:09 -0500 Subject: [PATCH 6/8] Dropping < 1.9.2 --- .travis.yml | 2 -- Gemfile | 5 ----- 2 files changed, 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index f75b3d89..df080b73 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,9 @@ before_install: - sudo apt-get install libicu-dev -y - gem update --system 2.1.11 rvm: - - 1.8.7 - 1.9.2 - 1.9.3 - 2.0.0 - 2.1.1 - - ree notifications: disabled: true diff --git a/Gemfile b/Gemfile index 3df9dcfc..851fabc2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,2 @@ source 'https://rubygems.org' gemspec - -if RUBY_VERSION < "1.9.3" - # escape_utils 1.0.0 requires 1.9.3 and above - gem "escape_utils", "0.3.2" -end From df3b1a983eece6f466fb17861fd88b5f3b6a7073 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Fri, 2 May 2014 15:13:57 -0500 Subject: [PATCH 7/8] > 1.9.3 even --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index df080b73..83880550 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ before_install: - sudo apt-get install libicu-dev -y - gem update --system 2.1.11 rvm: - - 1.9.2 - 1.9.3 - 2.0.0 - 2.1.1 From 3023516796e826f39dc365eda33093156eee10f6 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Sat, 3 May 2014 17:10:02 -0500 Subject: [PATCH 8/8] Samples update --- lib/linguist/samples.json | 255 +++++++++++++++++++++++++++++++++++++- 1 file changed, 252 insertions(+), 3 deletions(-) diff --git a/lib/linguist/samples.json b/lib/linguist/samples.json index a278b643..6320bde3 100644 --- a/lib/linguist/samples.json +++ b/lib/linguist/samples.json @@ -461,6 +461,10 @@ ".reb", ".rebol" ], + "Red": [ + ".red", + ".reds" + ], "RMarkdown": [ ".rmd" ], @@ -684,8 +688,8 @@ ".gemrc" ] }, - "tokens_total": 590909, - "languages_total": 717, + "tokens_total": 591725, + "languages_total": 719, "tokens": { "ABAP": { "*/**": 1, @@ -53178,6 +53182,249 @@ "print": 4, "author": 1 }, + "Red": { + "Red": 3, + "[": 111, + "Title": 2, + "Author": 1, + "]": 114, + "File": 1, + "%": 2, + "console.red": 1, + "Tabs": 1, + "Rights": 1, + "License": 2, + "{": 11, + "Distributed": 1, + "under": 1, + "the": 3, + "Boost": 1, + "Software": 1, + "Version": 1, + "See": 1, + "https": 1, + "//github.com/dockimbel/Red/blob/master/BSL": 1, + "-": 74, + "License.txt": 1, + "}": 11, + "Purpose": 2, + "Language": 2, + "http": 2, + "//www.red": 2, + "lang.org/": 2, + "#system": 1, + "global": 1, + "#either": 3, + "OS": 3, + "MacOSX": 2, + "History": 1, + "library": 1, + "cdecl": 3, + "add": 2, + "history": 2, + ";": 31, + "Add": 1, + "line": 9, + "to": 2, + "history.": 1, + "c": 7, + "string": 10, + "rl": 4, + "insert": 3, + "wrapper": 2, + "func": 1, + "count": 3, + "integer": 16, + "key": 3, + "return": 10, + "Windows": 2, + "system/platform": 1, + "ret": 5, + "AttachConsole": 1, + "if": 2, + "zero": 3, + "print": 5, + "halt": 2, + "SetConsoleTitle": 1, + "as": 4, + "string/rs": 1, + "head": 1, + "str": 4, + "bind": 1, + "tab": 3, + "input": 2, + "routine": 1, + "prompt": 3, + "/local": 1, + "len": 1, + "buffer": 4, + "string/load": 1, + "+": 1, + "length": 1, + "free": 1, + "byte": 3, + "ptr": 14, + "SET_RETURN": 1, + "(": 6, + ")": 4, + "delimiters": 1, + "function": 6, + "block": 3, + "list": 1, + "copy": 2, + "none": 1, + "foreach": 1, + "case": 2, + "escaped": 2, + "no": 2, + "in": 2, + "comment": 2, + "switch": 3, + "#": 8, + "mono": 3, + "mode": 3, + "cnt/1": 1, + "red": 1, + "eval": 1, + "code": 3, + "load/all": 1, + "unless": 1, + "tail": 1, + "set/any": 1, + "not": 1, + "script/2": 1, + "do": 2, + "skip": 1, + "script": 1, + "quit": 2, + "init": 1, + "console": 2, + "Console": 1, + "alpha": 1, + "version": 3, + "only": 1, + "ASCII": 1, + "supported": 1, + "Red/System": 1, + "#include": 1, + "../common/FPU": 1, + "configuration.reds": 1, + "C": 1, + "types": 1, + "#define": 2, + "time": 2, + "long": 2, + "clock": 1, + "date": 1, + "alias": 2, + "struct": 5, + "second": 1, + "minute": 1, + "hour": 1, + "day": 1, + "month": 1, + "year": 1, + "Since": 1, + "weekday": 1, + "since": 1, + "Sunday": 1, + "yearday": 1, + "daylight": 1, + "saving": 1, + "Negative": 1, + "unknown": 1, + "#import": 1, + "LIBC": 1, + "file": 1, + "Error": 1, + "handling": 1, + "form": 1, + "error": 5, + "Return": 1, + "description.": 1, + "Print": 1, + "standard": 1, + "output.": 1, + "Memory": 1, + "management": 1, + "make": 1, + "Allocate": 1, + "filled": 1, + "memory.": 1, + "chunks": 1, + "size": 5, + "binary": 4, + "resize": 1, + "Resize": 1, + "memory": 2, + "allocation.": 1, + "JVM": 6, + "reserved0": 1, + "int": 6, + "reserved1": 1, + "reserved2": 1, + "DestroyJavaVM": 1, + "JNICALL": 5, + "vm": 5, + "jint": 5, + "AttachCurrentThread": 1, + "penv": 3, + "p": 3, + "args": 2, + "DetachCurrentThread": 1, + "GetEnv": 1, + "AttachCurrentThreadAsDaemon": 1, + "just": 2, + "some": 2, + "datatypes": 1, + "for": 1, + "testing": 1, + "#some": 1, + "hash": 1, + "FF0000": 3, + "FF000000": 2, + "with": 4, + "instead": 1, + "of": 1, + "space": 2, + "/wAAAA": 1, + "/wAAA": 2, + "A": 2, + "inside": 2, + "char": 1, + "bla": 2, + "ff": 1, + "foo": 3, + "numbers": 1, + "which": 1, + "interpreter": 1, + "path": 1, + "h": 1, + "#if": 1, + "type": 1, + "exe": 1, + "push": 3, + "system/stack/frame": 2, + "save": 1, + "previous": 1, + "frame": 2, + "pointer": 2, + "system/stack/top": 1, + "@@": 1, + "reposition": 1, + "after": 1, + "catch": 1, + "flag": 1, + "CATCH_ALL": 1, + "exceptions": 1, + "root": 1, + "barrier": 1, + "keep": 1, + "stack": 1, + "aligned": 1, + "on": 1, + "bit": 1 + }, "RMarkdown": { "Some": 1, "text.": 1, @@ -62814,6 +63061,7 @@ "Ragel in Ruby Host": 593, "RDoc": 279, "Rebol": 533, + "Red": 816, "RMarkdown": 19, "RobotFramework": 483, "Ruby": 3862, @@ -62993,6 +63241,7 @@ "Ragel in Ruby Host": 3, "RDoc": 1, "Rebol": 6, + "Red": 2, "RMarkdown": 1, "RobotFramework": 3, "Ruby": 17, @@ -63038,5 +63287,5 @@ "YAML": 2, "Zephir": 2 }, - "md5": "948328ed3c1f2bbc5be44e8460905c2c" + "md5": "58816c8da227d1157f624a68c2f3ab55" } \ No newline at end of file