Class: Cfruby::Cfp_Parser
- Inherits:
-
Object
- Object
- Cfruby::Cfp_Parser
- Defined in:
- lib/libcfenjin/cfp_parser.rb
Instance Method Summary collapse
-
#do_parse(fn) ⇒ Object
Parse the Cfruby code of a single
fn
and add to the source tree - also add the standard class initalisation method. -
#dump ⇒ Object
See
Cfp_Code.dump
. -
#initialize(cf, codetree) ⇒ Cfp_Parser
constructor
A new instance of Cfp_Parser.
Constructor Details
#initialize(cf, codetree) ⇒ Cfp_Parser
Returns a new instance of Cfp_Parser.
16 17 18 19 |
# File 'lib/libcfenjin/cfp_parser.rb', line 16 def initialize cf,codetree @cf = cf @codetree = codetree end |
Instance Method Details
#do_parse(fn) ⇒ Object
Parse the Cfruby code of a single fn
and add to the source tree - also add the standard class initalisation method
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/libcfenjin/cfp_parser.rb', line 23 def do_parse fn @cf.cfp_logger.trace TRACE_ENGINE,"Parsing #{fn}" # ---- Create standard initilisation method @codetree.add fn,nil,'initialize',['cf','sourcepath','homepath','user'],0,[ ' @cf=cf @[email protected] @sourcepath=sourcepath @home=homepath @user=user ' ] # ---- Store source file into buffer f = File.new fn buf = [] f.each_line do | line | buf.push line end # ---- Parse buffer action = 'control' # default action num = 0 blockstartline = 0 linenum = 0 snippet = Array.new buf.each do | line | linenum += 1 l = line.chomp # @cf.cfp_logger.trace TRACE_ALL,l # ---- Parse for action: style syntax - but skip double colons if l.strip =~ /^(\S+[^:]):$/ newaction = $1 @codetree.add fn,num,action,nil,blockstartline,snippet blockstartline = linenum action = newaction num += 1 snippet = Array.new next end snippet.push l end @codetree.add fn,num,action,nil,blockstartline,snippet end |
#dump ⇒ Object
See Cfp_Code.dump
67 68 69 |
# File 'lib/libcfenjin/cfp_parser.rb', line 67 def dump @codetree.dump end |