11
Buenos Aires - Crystal Meetup #1 Herramientas uso y creación Brian J. Cardiff [email protected]

Crystal: herramientas, uso y creación

Embed Size (px)

Citation preview

Page 1: Crystal: herramientas, uso y creación

Buenos Aires - Crystal Meetup #1

Herramientas uso y creación

Brian J. [email protected]

Page 2: Crystal: herramientas, uso y creación

Tipos de herramientas❖ Entrada

❖ Archivos planos

❖ Resultado del parsing

❖ Resultado de compilación

❖ Salida

❖ Información sobre el código

❖ Modificación del código

Page 3: Crystal: herramientas, uso y creación

Tipos de herramientas

Archivos planos

Resultado del parsing

Resultado de inferencia y/o compilación

Información sobre el código

Tamaño Archivos.

Dependencia de archivos via

regex

Información de jerarquía de clases,

etc.

Tipos de variables,Invocaciones,

Implementaciones

Modificación del código

¡NO! FormatterRefactor semántico🎩✨🐰🎉❤

¿alguien?

Page 4: Crystal: herramientas, uso y creación

Herramientas actuales$  crystal  tool  

Usage: crystal tool [tool] [switches] [program file] [--] [arguments]

format format project, directories and/or files

hierarchy show type hierarchy

types show type of main variables

context show context for given location

implementations show implementations for given call in location

Page 5: Crystal: herramientas, uso y creación

Typessample.cr  

class  Person  

   property  name  

   property  age  

   def  initialize(@name,  @age)  

   end  

end  

p  =  Person.new("John",  35)  

n  =  p.name

$  crystal  tool  types  sample.cr    

p  :  Person  

n  :  String

Page 6: Crystal: herramientas, uso y creación

Implementationssample-­‐impl.cr  

class  Foo  

   def  hi  

       "I'm  a  foo"  

   end  

end  

class  Bar  

   def  hi  

       "I'm  a  bar"  

   end  

end  

obj  =  rand  <  0.5  ?  Foo.new  :  Bar.new  

obj.hi  

$  crystal  tool  implementations  -­‐-­‐cursor  sample-­‐impl.cr:14:6  sample-­‐impl.cr  

2  implementations  found  

./sample-­‐impl.cr:2:3  

./sample-­‐impl.cr:8:3  

Page 7: Crystal: herramientas, uso y creación

Contextsample-­‐context.cr  

class  Foo  

   def  set(a)  

       r  =  a  +  a  

       r  

   end  

end  

class  Bar  

   def  set(a)  

       a  

   end  

end  

obj  =  rand  <  0.5  ?  Foo.new  :  Bar.new  

obj.set("a  string")  

obj.set(1)  if  obj.is_a?(Foo)  

obj.set(1.5)  if  obj.is_a?(Bar)  

$  crystal  tool  context  -­‐-­‐cursor  sample-­‐context.cr:4:5  sample-­‐context.cr  

2  possible  contexts  found  

|  Expr  |  Type                      |  

-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  

|  self  |    Foo      |    Foo    |  

|  a        |  String  |  Int32  |  

|  r        |  String  |  Int32  |  

Page 8: Crystal: herramientas, uso y creación

Demo: Contar variables de instancia

require  "compiler/crystal/**"  

include  Crystal  

filename  =  File.expand_path(...)  

compiler  =  Compiler.new  

compiler.no_codegen  =  true  

source  =  Compiler::Source.new(filename,  File.read(filename))  

result  =  compiler.compile(source,  “not  used  due  to  no  codegen”)  

pp  result  #  =>  Crystal::Compiler::Result  

pp  result.program.types.values  #  =>  Array(Crystal::Type+)

https://github.com/bcardiff/crystal-tool-demo

Page 9: Crystal: herramientas, uso y creación

Integración con editores❖ Salida para consola, sin estructura

❖ a parsear o mostrar directamente

❖ JSON, CSV, etc.

❖ intercambiar datos con el editor

❖ posibilidad de mejores interacciones

❖ http://crystal-lang.org/2015/09/05/tools.html

Page 10: Crystal: herramientas, uso y creación

Ecosistema de Editores

❖ Vim

❖ https://github.com/rhysd/vim-crystal

❖ Atom

❖ https://github.com/manastech/atom-crystal-tools

❖ https://github.com/atom-crystal

❖ Sublime

❖ https://github.com/manastech/sublime-crystal

Page 11: Crystal: herramientas, uso y creación

¡Gracias!

Brian J. Cardiff

email: [email protected]: @bcardiff