module Flor::Parser
Constants
- UNESCAPE
Public Instance Methods
Source
# File lib/flor/parser.rb, line 200 def arr(i); eseq(:arr, i, :sbstart, :exp_qmark, :coll_sep, :sbend); end
Source
# File lib/flor/parser.rb, line 248 def att(i); seq(:att, i, :sep, :keycol, '?', :exp); end
Source
# File lib/flor/parser.rb, line 74 def boolean(i); alt(:boolean, i, :tru, :fls); end
Source
# File lib/flor/parser.rb, line 186 def coll_sep(i); alt(nil, i, :comma_qmark_eol, :wstar); end
Source
# File lib/flor/parser.rb, line 76 def colon_eol(i); seq(:colo, i, :colon, :eol); end
Source
# File lib/flor/parser.rb, line 82 def colon_exp(i) seq(nil, i, :colon_eol, :exp_qmark) end
Source
# File lib/flor/parser.rb, line 182 def comma_eol(i); seq(nil, i, :comma, :eol, :wstar); end
Source
# File lib/flor/parser.rb, line 185 def comma_qmark_eol(i); seq(nil, i, :comma, '?', :eol); end
Source
# File lib/flor/parser.rb, line 175 def comment(i); rex(nil, i, /(#|\/\/)[^\r\n]*/); end
Source
# File lib/flor/parser.rb, line 133 def dor_lines(i) seq(:dpar_lines, i, :pipepipe, :eol_wstar, :line, '+') end
Source
# File lib/flor/parser.rb, line 140 def dpar(i) seq( :dpar, i, :dollar, :pstart, :dpar_lines, :dor_lines, '?', :eol_wstar, :pend) end
Source
# File lib/flor/parser.rb, line 136 def dpar_lines(i) seq(:dpar_lines, i, :eol_wstar, :line, '+') end
Source
# File lib/flor/parser.rb, line 150 def dpar_or_dqsc(i); alt(nil, i, :dpar, :dqsc); end
Source
# File lib/flor/parser.rb, line 146 def dpar_or_rxoc(i); alt(nil, i, :dpar, :rxoc); end
Source
# File lib/flor/parser.rb, line 151 def dpar_or_rxsc(i); alt(nil, i, :dpar, :rxsc); end
Source
# File lib/flor/parser.rb, line 109 def dqsc(i) rex(:dqsc, i, %r{ ( \\["\\\/bfnrt] | \\u[0-9a-fA-F]{4} | \$(?!\() | [^\$"\\\b\f\n\r\t] )+ }x) end
Source
# File lib/flor/parser.rb, line 153 def dqstring(i) seq(:dqstring, i, :dquote, :dpar_or_dqsc, '*', :dquote) end
Source
# File lib/flor/parser.rb, line 190 def ent(i) seq(:ent, i, :key, :postval, :colon, :postval, :exp, :postval) end
Source
# File lib/flor/parser.rb, line 193 def ent_qmark(i) rep(nil, i, :ent, 0, 1) end
Source
# File lib/flor/parser.rb, line 177 def eol(i); seq(nil, i, :wstar, :comment, '?', :rnstar); end
Source
# File lib/flor/parser.rb, line 179 def eol_plus(i); seq(nil, i, :wstar, :comment, '?', :rnplus); end
Source
# File lib/flor/parser.rb, line 178 def eol_wstar(i); seq(nil, i, :wstar, :comment, '?', :rnstar, :wstar); end
Source
# File lib/flor/parser.rb, line 241 def eor(i); jseq(:exp, i, :eand, :sor); end
Also aliased as: exp
Source
# File lib/flor/parser.rb, line 197 def exp_qmark(i); rep(nil, i, :exp, 0, 1); end
Source
# File lib/flor/parser.rb, line 450 def invert(operation, operand) l = operand[2] case operation when '+' if operand[0] == '_num' && operand[1].is_a?(Numeric) [ operand[0], - operand[1], l ] else [ '-', [ operand ], l ] end when '*' [ '/', [ [ 'num', 1, l ], operand ], l ] else fail "don't know how to invert #{operation.inspect}" # FIXME end end
Source
# File lib/flor/parser.rb, line 246 def keycol(i); seq(nil, i, :key, :wstar, :colon, :eol_wstar); end
Source
# File lib/flor/parser.rb, line 262 def line(i) seq(:line, i, :node, '?', :outdent) end
Source
# File lib/flor/parser.rb, line 273 def line_number(t) t.input.string[0..t.offset].scan("\n").count + 1 end
rewriting
Also aliased as: ln
Source
# File lib/flor/parser.rb, line 257 def linjoin(i); rex(nil, i, /[ \t]*(\\|\|(?!\|)|;)[ \t]*/); end
Source
# File lib/flor/parser.rb, line 255 def node(i); seq(:node, i, :indent, :head, :natt, '*'); end
Source
# File lib/flor/parser.rb, line 68 def number(i) rex(:number, i, /[-+]?[0-9]+(\.[0-9]+)?([eE][+-]?[0-9]+)?/) end
Source
# File lib/flor/parser.rb, line 199 def obj(i); eseq(:obj, i, :pbstart, :ent_qmark, :coll_sep, :pbend); end
Source
# File lib/flor/parser.rb, line 260 def outdent(i); alt(:outdent, i, :outjnl, :outnlj, :eol); end
Source
# File lib/flor/parser.rb, line 258 def outjnl(i); seq(nil, i, :linjoin, :comment, '?', :rnstar); end
Source
# File lib/flor/parser.rb, line 259 def outnlj(i); seq(nil, i, :wstar, :comment, '?', :rnstar, :linjoin); end
Source
# File lib/flor/parser.rb, line 265 def panode(i) seq(:panode, i, :pstart, :eol_wstar, :line, '*', :eol, :pend) end
Source
# File lib/flor/parser.rb, line 202 def par(i) seq(:par, i, :pstart, :eol_wstar, :node, :eol_wstar, :pend) end
Source
# File lib/flor/parser.rb, line 107 def reference(i); seq(:ref, i, :rf_symbol, :rf_index, '*'); end
Source
# File lib/flor/parser.rb, line 359 def restring(s) s.gsub( /\\(?:(['"\\\/bfnrt])|u([\da-fA-F]{4}))/ ) { $1 ? UNESCAPE[$1] : [ "#$2".hex ].pack('U*') } end
Source
# File lib/flor/parser.rb, line 435 def rewrite_arr(t) l = ln(t) cn = t.subgather(nil).collect { |n| rewrite(n) } cn = [ [ '_att', [ [ '_', [], l ] ], l ] ] if cn.empty? [ '_arr', cn, l ] end
Source
# File lib/flor/parser.rb, line 413 def rewrite_boolean(t); [ '_boo', t.string == 'true', line_number(t) ]; end
Source
# File lib/flor/parser.rb, line 376 def rewrite_dpar(t) [ '_dol', t.subgather(nil).collect { |ct| rewrite(ct) }, ln(t) ] end
Source
# File lib/flor/parser.rb, line 370 def rewrite_dpar_lines(t) #Raabro.pp(t, colours: true); p t.string [ '_dmute', t.subgather(:node).collect { |ct| rewrite(ct) }, ln(t) ] end
Source
# File lib/flor/parser.rb, line 367 def rewrite_dqsc(t); [ '_sqs', restring(t.string), ln(t) ]; end
Also aliased as: rewrite_rxsc
Source
# File lib/flor/parser.rb, line 381 def rewrite_dqstring(t) cn = t.subgather(nil).collect { |tt| rewrite(tt) } if cn.size == 1 && cn[0][0] == '_sqs' cn[0] elsif cn.size == 0 [ '_sqs', '', ln(t) ] else [ '_dqs', cn, ln(t) ] end end
Also aliased as: rewrite_rxopts
Source
# File lib/flor/parser.rb, line 468 def rewrite_exp(t) #puts "-" * 80 #puts caller[0, 7] #Raabro.pp(t, colours: true) return rewrite(t.c0) if t.children.size == 1 #puts "-" * 80 #puts caller[0, 7] #Raabro.pp(t, colours: true) cn = t.children.collect { |ct| ct.lookup(nil) } operation = cn.find { |ct| ct.name == :sop }.string operator = operation operands = [] cn.each do |ct| if ct.name == :sop operator = ct.string else o = rewrite(ct) o = invert(operation, o) if operator != operation operands << o end end [ operation, operands, operands.first[2] ] end
Source
# File lib/flor/parser.rb, line 683 def rewrite_flor(t) prev = root = Nod.new(nil, nil) t.gather(:line).each do |lt| nt = lt.lookup(:node); next unless nt ot = lt.children.last.string n = Nod.new(nt, ot) prev.append(n) prev = n end root.children.count == 1 ? root.children.first.to_a : root.to_a end
Also aliased as: rewrite_panode
Source
# File lib/flor/parser.rb, line 284 def rewrite_node(t) Nod.new(t, nil).to_a end
Source
# File lib/flor/parser.rb, line 414 def rewrite_null(t); [ '_nul', nil, line_number(t) ]; end
Source
# File lib/flor/parser.rb, line 416 def rewrite_number(t) s = t.string; [ '_num', s.index('.') ? s.to_f : s.to_i, ln(t) ] end
Source
# File lib/flor/parser.rb, line 421 def rewrite_obj(t) l = ln(t) cn = t.subgather(nil).inject([]) do |a, tt| a << rewrite(tt.c0.c0) a << rewrite(tt.c4) end cn = [ [ '_att', [ [ '_', [], l ] ], l ] ] if cn.empty? [ '_obj', cn, l ] end
Source
# File lib/flor/parser.rb, line 279 def rewrite_par(t) Nod.new(t.lookup(:node), nil).to_a end
Source
# File lib/flor/parser.rb, line 289 def rewrite_ref(t) tts = t.subgather(nil) if tts.length == 1 tt = tts.first [ tt.string, [], ln(tt) ] else [ '_ref', tts.collect { |ct| rewrite(ct) }, ln(t) ] end end
Source
# File lib/flor/parser.rb, line 323 def rewrite_refsl(t) st, co = t.subgather(nil) [ '_obj', [ [ '_sqs', 'start', ln(st) ], rewrite(st), [ '_sqs', 'count', ln(co) ], rewrite(co), ], ln(t) ] end
Source
# File lib/flor/parser.rb, line 312 def rewrite_refsq(t) tts = t.subgather(nil) if tts.length == 1 rewrite(tts.first) else [ '_arr', tts.collect { |tt| rewrite(tt) }, ln(t) ] end end
Source
# File lib/flor/parser.rb, line 333 def rewrite_refst(t) #puts "-" * 80 #Raabro.pp(t, colours: true) ts = t.subgather(nil).collect { |tt| tt.name == :colo ? ':' : tt } ts.unshift(0) if ts.first == ':' # begin ts.push(':') if ts.count { |ct| ct == ':' } < 2 # ts.push(1) if ts.last == ':' # step ts.insert(2, -1) if ts[2] == ':' # end be, _, en, _, st = ts be = be.is_a?(Integer) ? [ '_num', be, ln(t) ] : rewrite(be) en = en.is_a?(Integer) ? [ '_num', en, ln(t) ] : rewrite(en) st = st.is_a?(Integer) ? [ '_num', st, ln(t) ] : rewrite(st) [ '_obj', [ [ '_sqs', 'start', be[2] ], be, [ '_sqs', 'end', en[2] ], en, [ '_sqs', 'step', st[2] ], st, ], ln(t) ] end
Source
# File lib/flor/parser.rb, line 301 def rewrite_refsym(t) s = t.string if s.match(/\A\d+\z/) [ '_num', s.to_i, ln(t) ] else [ '_sqs', s, ln(t) ] end end
Source
# File lib/flor/parser.rb, line 396 def rewrite_rxoc(t); [ '_sqs', t.string, ln(t) ]; end
Source
# File lib/flor/parser.rb, line 398 def rewrite_rxstring(t) l = ln(t) cts = t.subgather(nil) rot = cts.pop cn = cts.collect(&method(:rewrite)) cn.unshift([ '_att', [ [ 'rxopts', [], l ], rewrite(rot) ], l ]) \ if rot.length > 0 [ '_rxs', cn, l ] end
Source
# File lib/flor/parser.rb, line 412 def rewrite_sqstring(t); [ '_sqs', restring(t.string[1..-2]), ln(t) ]; end
Source
# File lib/flor/parser.rb, line 97 def rf_dot_idx(i) seq(nil, i, :dot, :rf_symbol) end
Source
# File lib/flor/parser.rb, line 100 def rf_index(i); alt(nil, i, :rf_dot_idx, :rf_sqa_idx); end
Source
# File lib/flor/parser.rb, line 79 def rf_slice(i) seq(:refsl, i, :exp, :comma_qmark_eol, :exp) end
Source
# File lib/flor/parser.rb, line 94 def rf_sqa_idx(i) seq(:refsq, i, :sbstart, :rf_sqa_index, :rf_sqa_semico_index, '*', :sbend) end
Source
# File lib/flor/parser.rb, line 88 def rf_sqa_index(i) alt(nil, i, :rf_slice, :rf_steps, :exp) end
Source
# File lib/flor/parser.rb, line 91 def rf_sqa_semico_index(i) seq(nil, i, :semicolon_eol, :rf_sqa_index) end
Source
# File lib/flor/parser.rb, line 85 def rf_steps(i) seq(:refst, i, :exp_qmark, :colon_exp, :colon_exp, '?') end
Source
# File lib/flor/parser.rb, line 102 def rf_symbol(i) rex(:refsym, i, /([^.:;| \b\f\n\r\t"',()\[\]{}#\\\/]|\/(?!\/))+/) # anything but... a slash is ok, but not a double slash... end
Source
# File lib/flor/parser.rb, line 148 def rxopts(i); rep(:rxopts, i, :dpar_or_rxoc, 0); end
Source
# File lib/flor/parser.rb, line 157 def rxr(i) # used to break ambiguity against / (infix division) rex(nil, i, /(regex|rex|rx|re|r)/) end
Source
# File lib/flor/parser.rb, line 122 def rxsc(i) rex(:rxsc, i, %r{ ( \\[\/bfnrt] | \\u[0-9a-fA-F]{4} | \$(?!\() | [^\$/\b\f\n\r\t] )+ }x) end
Source
# File lib/flor/parser.rb, line 161 def rxstring(i) seq(:rxstring, i, :rxr, '?', :slash, :dpar_or_rxsc, '*', :slash, :rxopts) end
Source
# File lib/flor/parser.rb, line 77 def semicolon_eol(i); seq(nil, i, :semicolon, :eol); end
Source
# File lib/flor/parser.rb, line 231 def sequ(i); seq(nil, i, :ssequ, :eol, '?'); end
Source
# File lib/flor/parser.rb, line 230 def slgt(i); seq(nil, i, :sslgt, :eol, '?'); end
Source
# File lib/flor/parser.rb, line 227 def smod(i); seq(nil, i, :ssmod, :eol, '?'); end
Source
# File lib/flor/parser.rb, line 228 def sprd(i); seq(nil, i, :ssprd, :eol, '?'); end
Source
# File lib/flor/parser.rb, line 165 def sqstring(i) rex(:sqstring, i, %r{ '( \\['\\\/bfnrt] | \\u[0-9a-fA-F]{4} | [^'\\\b\f\n\r\t] )*' }x) end
Source
# File lib/flor/parser.rb, line 219 def ssmod(i); str(:sop, i, /%/); end
precedence
%w[ or or ], %w[ and and ], %w[ equ == != <> ], %w[ lgt < > <= >= ], %w[ sum + - ], %w[ prd * / % ],
Source
# File lib/flor/parser.rb, line 220 def ssprd(i); rex(:sop, i, /(\*|\/(?!\/))/); end
Source
# File lib/flor/parser.rb, line 229 def ssum(i); seq(nil, i, :sssum, :eol, '?'); end
Source
# File lib/flor/parser.rb, line 206 def val(i) altg(:val, i, :panode, :par, :reference, :sqstring, :dqstring, :rxstring, :arr, :obj, :number, :boolean, :null) end
Source
# File lib/flor/parser.rb, line 188 def woreol(i); alt(:woreol, i, :wplus, :eol_plus); end
Source
# File lib/flor/parser.rb, line 44 def wstar(i); rex(nil, i, /[ \t]*/); end
parsing