Class: Knj::Php_parser

Inherits:
Object show all
Defined in:
lib/knj/php_parser/arguments.rb,
lib/knj/php_parser/functions.rb,
lib/knj/php_parser/php_parser.rb

Defined Under Namespace

Modules: Functions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Php_parser

Returns a new instance of Php_parser.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/knj/php_parser/php_parser.rb', line 4

def initialize(args)
  @args = args
  @cont = File.read(@args["file"])
  
  if !args.key?("require_requirements") or args["require_requirements"]
    @retcont = "require \"knj/autoload\"\n"
    @retcont << "require \"knj/php\"\n"
    @retcont << "require \"knj/php_parser/php_parser\"\n"
    @retcont << "\n"
  else
    @retcont = ""
  end
end

Instance Attribute Details

#contObject (readonly)

Returns the value of attribute cont.



2
3
4
# File 'lib/knj/php_parser/php_parser.rb', line 2

def cont
  @cont
end

#retcontObject (readonly)

Returns the value of attribute retcont.



2
3
4
# File 'lib/knj/php_parser/php_parser.rb', line 2

def retcont
  @retcont
end

Instance Method Details

#argsObject



2
3
4
# File 'lib/knj/php_parser/arguments.rb', line 2

def args
  
end

#func_args(func_name) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/knj/php_parser/functions.rb', line 2

def func_args(func_name)
  func_arg_count = 0
  args = []
  
  loop do
    if match = self.matchclear(/\A\$#{@regex_varname}\s*(,\s*|)/)
      args << {
        "varname" => match[1],
        "newname" => "phpvar_#{match[1]}"
      }
    elsif match = self.matchclear(/\A\)\s*\{/)
      break
    else
      raise "Could not match function arguments."
    end
  end
  
  @retcont << "#{self.tabs}module Knj::Php_parser::Functions\n"
  @tabs << 1
  @retcont << "#{self.tabs}def self.#{func_name}("
  
  first = true
  args.each do |arg|
    @retcont << ", " if !first
    first = false if first
    @retcont << arg["newname"]
  end
  
  @retcont << ")\n"
  @tabs += 1
  @funcs_started += 1
  
  self.search_newstuff
end

#func_args_givenObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/knj/php_parser/functions.rb', line 61

def func_args_given
  arg_found = false
  
  loop do
    if !arg_found and match = self.matchclear(/\A\"/)
      @retcont << "\""
      self.match_semi
      @retcont << ")"
      arg_found = true
    elsif !arg_found and match = self.matchclear(/\A\$(#{@regex_varname})/)
      @retcont << "phpvar_#{match[1]}"
      arg_found = true
    elsif arg_found and match = self.matchclear(/\A\.\s*/)
      @retcont << " + "
      arg_found = false
    elsif arg_found and match = self.matchclear(/\A\)\s*;/)
      @retcont << "\n"
      break
    else
      raise "Could not figure out what to do."
    end
  end
end

#func_args_single_givenObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/knj/php_parser/functions.rb', line 37

def func_args_single_given
  arg_found = false
  
  loop do
    if !arg_found and match = self.matchclear(/\A\"/)
      @retcont << "\""
      self.match_semi
      @retcont << ")"
      arg_found = true
    elsif !arg_found and match = self.matchclear(/\A\$(#{@regex_varname})/)
      @retcont << "phpvar_#{match[1]}"
      arg_found = true
    elsif arg_found and match = self.matchclear(/\A\.\s*/)
      @retcont << " + "
      arg_found = false
    elsif arg_found and match = self.matchclear(/\A;/)
      @retcont << "\n"
      break
    else
      raise "Could not figure out what to do."
    end
  end
end

#match_semiObject



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/knj/php_parser/functions.rb', line 85

def match_semi
  loop do
    if match = self.matchclear(/\A[A-z\d_\.]+/)
      @retcont << match[0]
    elsif match = self.matchclear(/\A\"/)
      @retcont << "\""
      break
    else
      raise "Could not figure out what to do."
    end
  end
end