Upload
crystal-language
View
988
Download
2
Embed Size (px)
Citation preview
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
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?
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
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
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
‸
༓
༓
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 |
‸
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
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
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