GoRuby, an implementation of Ruby written in Go
If anyone wants to help to get the project to the real implementation please ping me or fork it and send a pull request.
- #goruby Channel on Gophers Slack (invites to Gophers Slack are available here)
There is a basic REPL within cmd/girb. It supports multiline expressions and all syntax elements the language supports yet.
To run it ad hoc run go run cmd/girb/main.go and exit the REPL with CTRL-D.
To run the command as one off run go run main.go.
- parse program files
- program file arguments
- Flags
-
-0[octal]specify record separator (\0, if no argument) -
-aautosplit mode with -n or -p (splits $_ into $F) -
-ccheck syntax only -
-Cdirectorycd to directory before executing your script -
-dset debugging flags (set $DEBUG to true) -
-e 'command'one line of script. Several -e's allowed. Omit [programfile] -
-Eex[:in]specify the default external and internal character encodings -
-Fpatternsplit() pattern for autosplit (-a) -
-i[extension]edit ARGV files in place (make backup if extension supplied) -
-Idirectoryspecify $LOAD_PATH directory (may be used more than once) -
-lenable line ending processing -
-nassume 'while gets(); ... end' loop around your script -
-passume loop like -n but print line also like sed -
-rlibraryrequire the library before executing your script -
-senable some switch parsing for switches after script name -
-Slook for the script using PATH environment variable -
-T[level=1]turn on tainting checks -
-vprint version number, then turn on verbose mode -
-wturn warnings on for your script -
-W[level=2]set warning level; 0=silence, 1=medium, 2=verbose -
-x[directory]strip off text before #!ruby line and perhaps cd to directory -
-hshow this message, --help for more info
-
- parse program files
- program file arguments
- Flags
-
-fSuppress read of ~/.irbrc -
-mBc mode (load mathn, fraction or matrix are available) -
-dSet $DEBUG to true (same as `ruby -d') -
-r load-moduleSame as `ruby -r' -
-I pathSpecify $LOAD_PATH directory -
-USame asruby -U -
-E encSame asruby -E -
-wSame asruby -w -
-W[level=2]Same asruby -W -
--context-mode nSet n[0-3] to method to create Binding Object, when new workspace was created -
--echoShow result(default) -
--noechoDon't show result -
--inspectUse `inspect' for output (default except for bc mode) -
--noinspectDon't use inspect for output -
--readlineUse Readline extension module -
--noreadlineDon't use Readline extension module -
--prompt prompt-mode/--prompt-mode prompt-modeSwitch prompt mode. Pre-defined prompt modes aredefault',simple',xmp' andinf-ruby' -
--inf-ruby-modeUse prompt appropriate for inf-ruby-mode on emacs. Suppresses --readline. -
--sample-book-mode/--simple-promptSimple prompt mode -
--nopromptNo prompt mode -
--single-irbShare self with sub-irb. -
--tracerDisplay trace for each execution of commands. -
--back-trace-limit nDisplay backtrace top n and tail n. The default value is 16. -
--irb_debug nSet internal debug level to n (not for popular use) -
--verboseShow details -
--noverboseDon't show details -
-v,--versionPrint the version of irb -
-h,--helpPrint help -
--Separate options of irb from the list of command-line args
-
- everything is an object
- allow method calls on everything
- operators are method calls
- full UTF8 support
- Unicode identifier
- Unicode symbols
- functions
- with parens
- without parens
- return keyword
- default values for parameters
- keyword arguments
- block arguments
- hash as last argument without braces
- function calls
- with parens
- without parens
- with block arguments
- conditionals
- if
- if/else
- if/elif/else
- tenary
? : - unless
- unless/else
- case
-
|| -
&&
- control flow
- for loop
- while loop
- until loop
- break
- next
- redo
- flip flop
- numbers
- integers
- integer arithmetics
- integers
1234 - integers with underscores
1_234 - decimal numbers
0d170,0D170 - octal numbers
0252,0o252,0O252 - hexadecimal numbers
0xaa,0xAa,0xAA,0Xaa,0XAa,0XaA - binary numbers
0b10101010,0B10101010
- floats
- float arithmetics
-
12.34 -
1234e-2 -
1.234E1 - floats with underscores
2.2_22
- integers
- booleans
- strings
- double quoted
- single quoted
- character literals (
?\n,?a,...) -
%q{} -
%Q{} - heredoc
- without indentation (
<<EOF) - indented (
<<-EOF) - “squiggly” heredoc
<<~ - quoted heredoc
- single quotes
<<-'HEREDOC' - double quotes
<<-"HEREDOC" - backticks <<-`HEREDOC`"
- single quotes
- without indentation (
- escaped characters
-
\abell, ASCII 07h (BEL) -
\bbackspace, ASCII 08h (BS) -
\thorizontal tab, ASCII 09h (TAB) -
\nnewline (line feed), ASCII 0Ah (LF) -
\vvertical tab, ASCII 0Bh (VT) -
\fform feed, ASCII 0Ch (FF) -
\rcarriage return, ASCII 0Dh (CR) -
\eescape, ASCII 1Bh (ESC) -
\sspace, ASCII 20h (SPC) -
\\backslash, \ -
\nnnoctal bit pattern, where nnn is 1-3 octal digits ([0-7]) -
\xnnhexadecimal bit pattern, where nn is 1-2 hexadecimal digits ([0-9a-fA-F]) -
\unnnnUnicode character, where nnnn is exactly 4 hexadecimal digits ([0-9a-fA-F]) -
\u{nnnn ...}Unicode character(s), where each nnnn is 1-6 hexadecimal digits ([0-9a-fA-F]) -
\cxor\C-xcontrol character, where x is an ASCII printable character -
\M-xmeta character, where x is an ASCII printable character -
\M-\C-xmeta control character, where x is an ASCII printable character -
\M-\cxsame as above -
\c\M-xsame as above -
\c?or\C-?delete, ASCII 7Fh (DEL)
-
- interpolation
#{} - automatic concatenation
- arrays
- array literal
[1,2] - array indexing
arr[2] - splat
- array decomposition
- implicit array assignment
- array of strings
%w{} - array of symbols
%i{}
- array literal
- nil
- hashes
- literal with
=>notation - literal with
key:notation - indexing
hash[:foo] - every Ruby Object can be a hash key
- literal with
- symbols
-
:symbol -
:"symbol" -
:"symbol"with interpolation -
:'symbol' -
%s{symbol} - singleton symbols
-
- regexp
-
/regex/ -
%r{regex}
-
- ranges
-
..inclusive -
...exclusive
-
- procs
-> - variables
- variable assignments
- globals
- operators
-
+ -
- -
/ -
* -
! -
< -
> -
**(pow) -
%(modulus) -
&(AND) -
^(XOR) -
>>(right shift) -
<<(left shift, append) -
==(equal) -
!=(not equal) -
===(case equality) -
=~(pattern match) -
!~(does not match) -
<=>(comparison or spaceship operator) -
<=(less or equal) -
>=(greater or equal) - assignment operators
-
+= -
-= -
/= -
*= -
%= -
**= -
&= -
|= -
^= -
<<= -
>>= -
||= -
&&=
-
-
- function blocks (procs)
- error handling
- begin/rescue
- ensure
- retry
- constants
- scope operator
:: - classes
- class objects
- class Class
- instance variables
- class variables
- class methods
- instance methods
- method overrides
- private
- protected
- public
- inheritance
- constructors
- new
-
self - singleton classes (also known as the metaclass or eigenclass)
class << self - assigment methods
- self defined classes
- self defined classes with inheritance
- modules
- object main
- comments '#'