Class: Code::Parser::Whitespace

Inherits:
Language
  • Object
show all
Defined in:
lib/code/parser/whitespace.rb

Instance Method Summary collapse

Methods inherited from Language

<<, >>, absent, aka, #any, ignore, #inspect, maybe, parse, #parse, repeat, #str, then, #to_s, |

Instance Method Details

#asteriskObject



20
21
22
# File 'lib/code/parser/whitespace.rb', line 20

def asterisk
  str("*")
end

#double_slash_commentObject



28
29
30
# File 'lib/code/parser/whitespace.rb', line 28

def double_slash_comment
  slash << slash << (newline.absent << any).repeat << newline.maybe
end

#hash_commentObject



24
25
26
# File 'lib/code/parser/whitespace.rb', line 24

def hash_comment
  hashtag << (newline.absent << any).repeat << newline.maybe
end

#hashtagObject



12
13
14
# File 'lib/code/parser/whitespace.rb', line 12

def hashtag
  str("#")
end

#multi_line_commentObject



32
33
34
35
# File 'lib/code/parser/whitespace.rb', line 32

def multi_line_comment
  slash << asterisk << ((asterisk << slash).absent << any).repeat <<
    asterisk.maybe << slash.maybe
end

#newlineObject



8
9
10
# File 'lib/code/parser/whitespace.rb', line 8

def newline
  str("\n")
end

#rootObject



41
42
43
44
45
46
# File 'lib/code/parser/whitespace.rb', line 41

def root
  (
    space | newline | hash_comment | double_slash_comment |
      multi_line_comment
  ).repeat(1)
end

#slashObject



16
17
18
# File 'lib/code/parser/whitespace.rb', line 16

def slash
  str("/")
end

#spaceObject



4
5
6
# File 'lib/code/parser/whitespace.rb', line 4

def space
  str(" ")
end

#without_newlineObject



37
38
39
# File 'lib/code/parser/whitespace.rb', line 37

def without_newline
  (space | multi_line_comment).repeat(1)
end