Class: Cucumber::CucumberExpressions::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/cucumber_expressions/ast.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, text, start, ending) ⇒ Token

Returns a new instance of Token.



54
55
56
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 54

def initialize(type, text, start, ending)
  @type, @text, @start, @end = type, text, start, ending
end

Instance Attribute Details

#endObject (readonly)

Returns the value of attribute end.



52
53
54
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 52

def end
  @end
end

#startObject (readonly)

Returns the value of attribute start.



52
53
54
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 52

def start
  @start
end

#textObject (readonly)

Returns the value of attribute text.



52
53
54
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 52

def text
  @text
end

#typeObject (readonly)

Returns the value of attribute type.



52
53
54
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 52

def type
  @type
end

Class Method Details

.can_escape(codepoint) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 62

def self.can_escape(codepoint)
  c = codepoint.chr(Encoding::UTF_8)
  if c == ' '
    # TODO: Unicode whitespace?
    return true
  end

  case c
  when ESCAPE_CHARACTER
    true
  when ALTERNATION_CHARACTER
    true
  when BEGIN_PARAMETER_CHARACTER
    true
  when END_PARAMETER_CHARACTER
    true
  when BEGIN_OPTIONAL_CHARACTER
    true
  when END_OPTIONAL_CHARACTER
    true
  else
    false
  end
end

.is_escape_character(codepoint) ⇒ Object



58
59
60
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 58

def self.is_escape_character(codepoint)
  codepoint.chr(Encoding::UTF_8) == ESCAPE_CHARACTER
end

.purpose_of(token) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 127

def self.purpose_of(token)
  case token
  when TokenType::BEGIN_OPTIONAL
    return 'optional text'
  when TokenType::END_OPTIONAL
    return 'optional text'
  when TokenType::BEGIN_PARAMETER
    return 'a parameter'
  when TokenType::END_PARAMETER
    return 'a parameter'
  when TokenType::ALTERNATION
    return 'alternation'
  else
    return ''
  end
end

.symbol_of(token) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 110

def self.symbol_of(token)
  case token
  when TokenType::BEGIN_OPTIONAL
    return BEGIN_OPTIONAL_CHARACTER
  when TokenType::END_OPTIONAL
    return END_OPTIONAL_CHARACTER
  when TokenType::BEGIN_PARAMETER
    return BEGIN_PARAMETER_CHARACTER
  when TokenType::END_PARAMETER
    return END_PARAMETER_CHARACTER
  when TokenType::ALTERNATION
    return ALTERNATION_CHARACTER
  else
    return ''
  end
end

.type_of(codepoint) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 87

def self.type_of(codepoint)
  c = codepoint.chr(Encoding::UTF_8)
  if c == ' '
    # TODO: Unicode whitespace?
    return TokenType::WHITE_SPACE
  end

  case c
  when ALTERNATION_CHARACTER
    TokenType::ALTERNATION
  when BEGIN_PARAMETER_CHARACTER
    TokenType::BEGIN_PARAMETER
  when END_PARAMETER_CHARACTER
    TokenType::END_PARAMETER
  when BEGIN_OPTIONAL_CHARACTER
    TokenType::BEGIN_OPTIONAL
  when END_OPTIONAL_CHARACTER
    TokenType::END_OPTIONAL
  else
    TokenType::TEXT
  end
end

Instance Method Details

#to_hashObject



144
145
146
147
148
149
150
151
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 144

def to_hash
  {
    'type' => @type,
    'text' => @text,
    'start' => @start,
    'end' => @end
  }
end