Comments (10)
Is any Ruby program a valid Crystal program?
No, same as ruby is not the goal, it just follow the good part of ruby's design.
macro (it looks like elisp's macro i guess), annotate are invalid in ruby-mode.
And the colon
serve both as type declare and return value declare.
# This methods greets *recipient*.
def say_hello(recipient : String)
puts "Hello #{recipient}!"
end
# This method greets *times* times.
def say_hello(times : Int32)
puts "Hello " * times
end
say_hello "World"
say_hello 3
# return type is String
def some_method : String
"hello"
end
Tough, almost all case the type_inference always works, you don't need specify it. but, those all valid syntax.
And, it support untagged union type, like this:
if 1 + 2 == 3
a = 1
else
a = "hello"
end
# the type of a at compile time is a union type.
typeof(a) # : Int32 | String
# can be used as type declare directly
b : typeof(a) # same as `b : Int32 | String`
b = 100
b = "hello world"
b = :hello # Error: type must be (Int32 | String), not (Int32 | String | Symbol
this probably is all the supported keywords in Crystal.
this is a good chance to try this awesome language. 😄, i am a newcomer use this language 2 months, tough, familiar with ruby make this learning curve more smoothness then ever, if you have any question about it, i will always try to answer it try my best.
Thank you very much, @dgutov
from robe.
I wouldn't say I have a lot of time, so maybe someday. Happy to answer questions, though.
There also seems to be a fair amount of duplication, so I wonder how many differences there are between the languages. Is any Ruby program a valid Crystal program? Perhaps it might be more efficient to maintain just one language mode instead of two.
So far I see: 1) the abstract
keyword, 2) the {%
syntax (a macros thingy, apparently).
from robe.
@dgutov Unfortunately any arbitrary Ruby program is not a valid Crystal program. It is possible to create very simple (trivial) Ruby programs that can compile as valid Crystal, but this is more the exception than the rule.
from robe.
Okay. I should probably turn the question a little differently.
Does ruby-mode
generally work okay for Crystal now? Or are there a lot of examples where it does the wrong thing?
It's about whether there should be two different major modes, or just one with minor tweaks (call it dialects, say).
from robe.
Macros do look like a pain to support, but it's not having separate crystal-mode
makes it easier.
from robe.
Hi, @dgutov , i create a new repo for record all known different syntax part of Ruby and Crystal here, please have a look, and give me feedback.
All code in ruby_invalid.cr
is totally valid crystal source code, no any error when run with crystal run src/ruby_invalid.cr
, but each section(separate by -------------), have one or more syntax error when run it in ruby interpreter.
from robe.
Cool. It seems like most of the syntax works okay-ish already.
What's missing is the enum ... end
closer pair (maybe lib ... end
as well) and tokenization/indentation support for private
and abstract
. private
looks like it should be treated as a separate keyword (with support in the grammar and indendation logic), whereas abstract
could be that too, but also seems like it should be ignored when before def
(so, some support in the tokenizer).
I suggest you try implementing some of that yourself now, and we could get around to adding/merging this in some form to ruby-mode
later.
from robe.
Or, and macros need support too, but the implementation could be trickier than the changes mentioned above.
from robe.
Cool. It seems like most of the syntax works okay-ish already.
Yes, though, it need following the newest changes from emacs official ruby-mode anyway.'
I suggest you try implementing some of that yourself now, and we could get around to adding/merging this in some form to ruby-mode later.
Okay, i will try, though i consider add a new major-mode crystal-mode to emacs which use ruby-mode as base, and only includes the changes part is better than merging somethings into ruby-mode.
from robe.
though i consider add a new major-mode crystal-mode to emacs which use ruby-mode as base, and only includes the changes part is better than merging somethings into ruby-mode
If it can be done, that would be preferable, of course.
from robe.
Related Issues (20)
- Robe cannot autostart: "No matching directory found" HOT 4
- Robe not working on Ruby 2.7.1 HOT 3
- robe make emacs freeze on 27 on large projects HOT 16
- Non-string path in LOAD_PATH HOT 3
- Emacs freezes when robe is called while byebug is active on console HOT 3
- How to disable robe? HOT 2
- Get search failed message when run robe-jump. HOT 19
- `Can't find the location` when try to search a class defined on current project. (but can in irb) HOT 6
- `find-tag-marker-ring` breaks `robe-jump` on Emacs 28. HOT 2
- Environment variables HOT 1
- Can't jump to the nested module's class in `enh-ruby-mode`, but ruby-mode works HOT 29
- robe-jump returns error file doesnt exists - but it exists HOT 11
- CPU spikes during rails process buffer completion HOT 7
- Allow for configurable specificity of `robe-jump` entries HOT 9
- Should be possible to change Robe errors buffer from inf-ruby buffer to another buffer HOT 2
- `robe-completing-read` for `Module: ` is excessively interrupting HOT 20
- `*robe-doc*`: optionally show the method source directly HOT 3
- Consider RBS (when available) for local type inference
- robe hangs Emacs HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from robe.