Module: LangScan::Io

Defined in:
lib/langscan/io.rb

Constant Summary collapse

Pattern =
[
  [:comment, '/\\*', '\\*/'],
  [:comment, '//.*'],
  [:comment, '#.*'],
  [:string, '"""', '[^\\\\]"""'],
  [:string, '""'],
  [:string, '"', '[^\\\\]"'],
  [:floating, '\\d*(?:(?:\\.\\d+)?(?:e-?\\d+)|(?:\\.\\d+))'],
  [:integer, '0[xX][\\dA-Fa-f]+'],
  [:integer, '\\d+'],
  [:ident, "\\w*[a-zA-Z_]\\w*"],
  [:punct, '[:\\.\'~!@$%=^&*-+|<>?/]+'],
  [:punct, '[\\[\\]{}();,]'],
]
Types =
[]
Keywords =
%w(

Class Method Summary collapse

Class Method Details

.abbrevObject



21
22
23
# File 'lib/langscan/io.rb', line 21

def abbrev
  "io"
end

.extnamesObject



25
26
27
# File 'lib/langscan/io.rb', line 25

def extnames
  [".io"]
end

.nameObject



17
18
19
# File 'lib/langscan/io.rb', line 17

def name
  "Io"
end

.parse_token(t, new_tokens) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/langscan/io.rb', line 48

def parse_token(t, new_tokens)
  if t.type == :ident
    t.type = :funcall
  end

  last_token = new_tokens.last
  return if last_token.nil?

  return unless t.type == :punct and last_token.type == :funcall

  if t.text == ':=' || t.text == '='
    last_token.type = :fundef
  end
end

.scan(input, &block) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/langscan/io.rb', line 63

def scan(input, &block)
  scanner = EasyScanner.new(Pattern, Types, Keywords)

  tokens = []
  scanner.scan(input) {|t|
    tokens << t
  }

  new_tokens = []
  tokens.each {|t|
    parse_token(t, new_tokens)
    new_tokens << t
  }

  new_tokens.each {|t|
    yield t
  }
end