Class: OFX::OFX102::Parser
- Inherits:
-
Racc::Parser
- Object
- Racc::Parser
- OFX::OFX102::Parser
- Defined in:
- lib/ofx/1.0.2/lexer.rb,
lib/ofx/1.0.2/parser.rb
Defined Under Namespace
Classes: ScanError
Constant Summary collapse
- Racc_arg =
[ racc_action_table, racc_action_check, racc_action_default, racc_action_pointer, racc_goto_table, racc_goto_check, racc_goto_default, racc_goto_pointer, racc_nt_base, racc_reduce_table, racc_token_table, racc_shift_n, racc_reduce_n, racc_use_result_var ]
- Racc_token_to_s_table =
[ "$end", "error", "tag_in", "element", "tag_out", "etag_in", "text", "$start", "target", "ofx_body", "tag_from", "contents", "tag_to", "content", "aggregate", "value" ]
- Racc_debug_parser =
false
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #_next_token ⇒ Object
- #_reduce_none(val, _values, result) ⇒ Object
- #action ⇒ Object
- #load_file(filename) ⇒ Object
- #next_token ⇒ Object
- #scan_file(filename) ⇒ Object
- #scan_setup(str) ⇒ Object
- #scan_str(str) ⇒ Object (also: #scan)
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
33 34 35 |
# File 'lib/ofx/1.0.2/lexer.rb', line 33 def filename @filename end |
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
32 33 34 |
# File 'lib/ofx/1.0.2/lexer.rb', line 32 def lineno @lineno end |
#state ⇒ Object
Returns the value of attribute state.
34 35 36 |
# File 'lib/ofx/1.0.2/lexer.rb', line 34 def state @state end |
Instance Method Details
#_next_token ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ofx/1.0.2/lexer.rb', line 73 def _next_token text = @ss.peek(1) @lineno += 1 if text == "\n" token = case @state when nil case when (text = @ss.scan(/\<\//)) action { @state = :TAG; [:etag_in, text] } when (text = @ss.scan(/\</)) action { @state = :TAG; [:tag_in, text] } when (text = @ss.scan(/\s+(?=\S)/)) ; when (text = @ss.scan(/.*?(?=(\<|\<\/)+?)/)) action { [:text, text] } when (text = @ss.scan(/.*\S(?=\s*$)/)) action { [:text, text] } when (text = @ss.scan(/\s+(?=$)/)) ; else text = @ss.string[@ss.pos .. -1] raise ScanError, "can not match: '" + text + "'" end # if when :TAG case when (text = @ss.scan(/\>/)) action { @state = nil; [:tag_out, text] } when (text = @ss.scan(/[\w\-\.]+/)) action { [:element, text] } else text = @ss.string[@ss.pos .. -1] raise ScanError, "can not match: '" + text + "'" end # if else raise ScanError, "undefined state: '" + state.to_s + "'" end # case state token end |
#_reduce_none(val, _values, result) ⇒ Object
207 208 209 |
# File 'lib/ofx/1.0.2/parser.rb', line 207 def _reduce_none(val, _values, result) val[0] end |
#action ⇒ Object
42 43 44 |
# File 'lib/ofx/1.0.2/lexer.rb', line 42 def action yield end |
#load_file(filename) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/ofx/1.0.2/lexer.rb', line 52 def load_file( filename ) @filename = filename open(filename, "r") do |f| scan_setup(f.read) end end |
#next_token ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/ofx/1.0.2/lexer.rb', line 65 def next_token return if @ss.eos? # skips empty actions until token = _next_token or @ss.eos?; end token end |
#scan_file(filename) ⇒ Object
59 60 61 62 |
# File 'lib/ofx/1.0.2/lexer.rb', line 59 def scan_file( filename ) load_file(filename) do_parse end |
#scan_setup(str) ⇒ Object
36 37 38 39 40 |
# File 'lib/ofx/1.0.2/lexer.rb', line 36 def scan_setup(str) @ss = StringScanner.new(str) @lineno = 1 @state = nil end |
#scan_str(str) ⇒ Object Also known as: scan
46 47 48 49 |
# File 'lib/ofx/1.0.2/lexer.rb', line 46 def scan_str(str) scan_setup(str) do_parse end |