class Travis::Conditions::V1::Parser
Constants
- BOUND
- COMMA
- CONT
- EQ
- FUNC
- IN
- IS
- MSGS
- NEQ
- NRE
- OP
- PRED
- RE
- VAR
- WORD
Attributes
str[R]
Public Class Methods
new(str)
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 90 def initialize(str) raise ArgumentError, MSGS[:invalid] % [str] unless str.is_a?(String) @str = StringScanner.new(filter(str)) end
Public Instance Methods
boundary?()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 146 def boundary? peek(1) =~ BOUND || str.eos? end
call()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 150 def call return unless name = func args = parens { list } args or return return [:call, name.to_sym, args] end
comma()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 206 def comma space { scan(COMMA) } end
eq()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 127 def eq op = space { scan(EQ) || scan(NEQ) } and OP[op] end
error(key, *vals)
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 210 def error(key, *vals) raise ParseError, MSGS[key] % vals end
filter(str)
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 95 def filter(str) str.gsub(CONT, ' ') end
func()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 184 def func space { scan(FUNC) } end
in()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 198 def in space { scan(IN) } end
in_list(term)
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 167 def in_list(term) op = self.in or return list = parens { list! } [op.downcase.sub(' ', '_').to_sym, term, list] end
is()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 202 def is space { scan(IS) } end
is_pred(term)
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 161 def is_pred(term) op = is or return pr = pred or return [op.downcase.sub(' ', '_').to_sym, term, pr.downcase.to_sym] end
list()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 177 def list return [] unless item = var || call || val list = comma ? [item] + self.list : [item] skip(COMMA) list.compact end
list!()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 173 def list! list.tap { |list| err 'a list of values' if list.empty? } end
operand()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 114 def operand op = space { var || call || val } op or err('an operand') end
parse()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 99 def parse res = expr error(:parse_error, string.inspect) unless res && !str.rest? res end
pred()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 188 def pred space { scan(PRED)&.to_sym } end
re()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 131 def re op = space { scan(RE) || scan(NRE) } and OP[op] end
regex()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 119 def regex val = call return [:reg, val] if val return unless reg = space { Regex.new(rest).scan } str.pos = str.pos + reg.size [:reg, reg.gsub(%r(^/|/$), '')] # or err('an operand') end
term()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 105 def term lft = operand lst = in_list(lft) and return lst prd = is_pred(lft) and return prd op = re and return [op, lft, regex] op = eq and return [op, lft, operand] lft end
val()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 157 def val val = quoted || word and [:val, val] end
var()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 135 def var pos = str.pos var = scan(VAR) error(:shell_var) if var && var[0] == '$' return [:var, var.downcase.to_sym] if var && boundary? str.pos = pos nil end
word()
click to toggle source
# File lib/travis/conditions/v1/parser.rb, line 192 def word str = space { scan(WORD) } error(:shell_str) if str && str[0] == '$' str end