pax_global_header00006660000000000000000000000064126225635600014521gustar00rootroot0000000000000052 comment=e7159d1f027a52b6ea0361cd54aa1aedc74fbb2f yecht-yecht-1.1/000077500000000000000000000000001262256356000136105ustar00rootroot00000000000000yecht-yecht-1.1/.gitignore000066400000000000000000000000631262256356000155770ustar00rootroot00000000000000build rels prj.el lib/yecht-*.jar build.properties yecht-yecht-1.1/LICENSE000066400000000000000000000020661262256356000146210ustar00rootroot00000000000000Copyright (c) 2009-2010 Ola Bini Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. yecht-yecht-1.1/TIMINGS000066400000000000000000000134021262256356000146450ustar00rootroot00000000000000Syck scanning ../jruby_newyaml/bench/big_yaml.yml 10000 times took 13959ms parsing ../jruby_newyaml/bench/big_yaml.yml 10000 times took 16101ms JvYAMLb scanning ../jruby_newyaml/bench/big_yaml.yml 10000 times took 5325ms parsing ../jruby_newyaml/bench/big_yaml.yml 10000 times took 15794ms Yecht - Original scanning ../jruby_newyaml/bench/big_yaml.yml 10000 times took 93658ms parsing ../jruby_newyaml/bench/big_yaml.yml 10000 times took 117213ms Yecht - Fixed scanner scanning ../jruby_newyaml/bench/big_yaml.yml 10000 times took 12207ms parsing ../jruby_newyaml/bench/big_yaml.yml 10000 times took 31280ms Yecht - Fixed parser (switched to Jay) scanning ../jruby_newyaml/bench/big_yaml.yml 10000 times took 12960ms parsing ../jruby_newyaml/bench/big_yaml.yml 10000 times took 15411ms Yecht - Optimized parser (Tom's fixes from JRuby) (no difference, really) scanning ../jruby_newyaml/bench/big_yaml.yml 10000 times took 12951ms parsing ../jruby_newyaml/bench/big_yaml.yml 10000 times took 16298ms Yecht - Handwritten document-section in Scanner scanning ../jruby_newyaml/bench/big_yaml.yml 10000 times took 11226ms parsing ../jruby_newyaml/bench/big_yaml.yml 10000 times took 14059ms Yecht - Handwritten plain-section in Scanner scanning ../jruby_newyaml/bench/big_yaml.yml 10000 times took 9581ms parsing ../jruby_newyaml/bench/big_yaml.yml 10000 times took 12838ms Yecht - Rewrite the implicit-scanner scanning ../jruby_newyaml/bench/big_yaml.yml 10000 times took 4804ms parsing ../jruby_newyaml/bench/big_yaml.yml 10000 times took 8424ms MRI user system total real 1k small parse 0.090000 0.000000 0.090000 ( 0.104769) 1k small loads 0.060000 0.010000 0.070000 ( 0.072829) 1k small dumps 0.370000 0.000000 0.370000 ( 0.396296) 1k small roundtrip 0.410000 0.010000 0.420000 ( 0.429103) 1k big parse 4.440000 0.050000 4.490000 ( 4.615258) 1k big loads 1.920000 0.020000 1.940000 ( 1.991891) 1k big dumps 22.170000 0.270000 22.440000 ( 23.361924) 1k big roundtrip 24.180000 0.300000 24.480000 ( 25.483744) JRuby trunk user system total real 1k small parse 0.327000 0.000000 0.327000 ( 0.326000) 1k small loads 0.100000 0.000000 0.100000 ( 0.099000) 1k small dumps 0.202000 0.000000 0.202000 ( 0.202000) 1k small roundtrip 0.322000 0.000000 0.322000 ( 0.322000) 1k big parse 16.259000 0.000000 16.259000 ( 16.259000) 1k big loads 1.752000 0.000000 1.752000 ( 1.752000) 1k big dumps 10.333000 0.000000 10.333000 ( 10.333000) 1k big roundtrip 13.886000 0.000000 13.886000 ( 13.886000) JRuby with old Yecht user system total real 1k small parse 0.380000 0.000000 0.380000 ( 0.380000) 1k small loads 0.284000 0.000000 0.284000 ( 0.284000) 1k small dumps 0.347000 0.000000 0.347000 ( 0.347000) 1k small roundtrip 0.582000 0.000000 0.582000 ( 0.582000) 1k big parse 23.629000 0.000000 23.629000 ( 23.630000) 1k big loads 14.802000 0.000000 14.802000 ( 14.802000) 1k big dumps 19.526000 0.000000 19.526000 ( 19.526000) 1k big roundtrip 36.202000 0.000000 36.202000 ( 36.202000) JRuby with new Yecht user system total real 1k small parse 0.165000 0.000000 0.165000 ( 0.165000) 1k small loads 0.089000 0.000000 0.089000 ( 0.089000) 1k small dumps 0.299000 0.000000 0.299000 ( 0.299000) 1k small roundtrip 0.386000 0.000000 0.386000 ( 0.386000) 1k big parse 10.558000 0.000000 10.558000 ( 10.558000) 1k big loads 2.678000 0.000000 2.678000 ( 2.678000) 1k big dumps 19.109000 0.000000 19.109000 ( 19.110000) 1k big roundtrip 23.039000 0.000000 23.039000 ( 23.039000) JRuby with some slight optimizations to Yecht user system total real 1k small parse 0.188000 0.000000 0.188000 ( 0.188000) 1k small loads 0.076000 0.000000 0.076000 ( 0.076000) 1k small dumps 0.323000 0.000000 0.323000 ( 0.323000) 1k small roundtrip 0.362000 0.000000 0.362000 ( 0.363000) 1k big parse 9.053000 0.000000 9.053000 ( 9.053000) 1k big loads 2.262000 0.000000 2.262000 ( 2.262000) 1k big dumps 18.551000 0.000000 18.551000 ( 18.551000) 1k big roundtrip 21.675000 0.000000 21.675000 ( 21.675000) JRuby with some call site caching in Yecht user system total real 1k small parse 0.142000 0.000000 0.142000 ( 0.142000) 1k small loads 0.076000 0.000000 0.076000 ( 0.076000) 1k small dumps 0.278000 0.000000 0.278000 ( 0.278000) 1k small roundtrip 0.346000 0.000000 0.346000 ( 0.346000) 1k big parse 9.042000 0.000000 9.042000 ( 9.042000) 1k big loads 2.200000 0.000000 2.200000 ( 2.200000) 1k big dumps 18.451000 0.000000 18.451000 ( 18.451000) 1k big roundtrip 22.087000 0.000000 22.087000 ( 22.087000) yecht-yecht-1.1/build.xml000066400000000000000000000150611262256356000154340ustar00rootroot00000000000000 Yecht is a Syck port, a YAML 1.0 processor for Ruby yecht-yecht-1.1/default.build.properties000077500000000000000000000007561262256356000204630ustar00rootroot00000000000000# Defaults. To override, create a file called build.properties in # the same directory and put your changes in that. src.dir=src main.src.dir=${src.dir}/main test.src.dir=${src.dir}/test lib.dir=lib build.dir=build classes.dir=${build.dir}/classes yecht.classes.dir=${classes.dir}/yecht test.classes.dir=${classes.dir}/test ruby.classes.dir=${classes.dir}/ruby docs.dir=docs api.docs.dir=${docs.dir}/api release.dir=rels javac.version=1.5 ruby.src.dir=ext/ruby/src/java jruby.lib=../jruby/lib yecht-yecht-1.1/ext/000077500000000000000000000000001262256356000144105ustar00rootroot00000000000000yecht-yecht-1.1/ext/ruby/000077500000000000000000000000001262256356000153715ustar00rootroot00000000000000yecht-yecht-1.1/ext/ruby/lib/000077500000000000000000000000001262256356000161375ustar00rootroot00000000000000yecht-yecht-1.1/ext/ruby/lib/okay.rb000066400000000000000000000113061262256356000174300ustar00rootroot00000000000000# # vim:sw=4:ts=4 # $Id$ # # Okay Project # require 'yaml' module Okay @@type_registry = { 'boolean' => nil, 'str' => nil, 'int' => nil, 'null' => nil, 'float' => nil, 'seq' => nil, 'map' => nil } class Error < StandardError; end # Transfer methods for okay types TRANSFER_TYPES = {} OKAY_TYPE_DOMAIN = 'okay.yaml.org,2002' OKAY_TYPE_REGEXP = /^tag:#{ Regexp::quote( OKAY_TYPE_DOMAIN ) }:([^;]+)((?:;\w+)*)$/ # # Base class for Okay types # All types should inherit this class to use modules # class ModuleBase attr_accessor :modules end # # Quick Okay type handler, handles modules # def Okay.add_type( type_name, &transfer_proc ) type_re = /^(#{Regexp::quote( type_name )})((?:;\w+)*)$/ Okay::TRANSFER_TYPES[ type_name ] = transfer_proc YAML.add_domain_type( OKAY_TYPE_DOMAIN, type_re ) { |type, val| type, mods = OKAY_TYPE_REGEXP.match( type ).to_a[1,2] unless mods.to_s.empty? mod_re = /^(#{ mods.slice( 1..-1 ).gsub( /;/, '|' ) });/ modules = {} val.reject! { |k, v| if k =~ mod_re modules[ $1 ] ||= {} modules[ $1 ][ $' ] = v true else false end } end Okay::TRANSFER_TYPES[ type ].call( type, val, modules ) } end def Okay.object_maker( obj_class, val, modules ) obj = YAML.object_maker( obj_class, val ) unless obj.respond_to?( :modules= ) raise Okay::Error, "Modules #{modules.keys.join( ',' )} can't be handled by class #{obj_class}" if modules end obj.modules = modules obj end def Okay.load_schema( schema ) schema = YAML::load( schema ) schema.each { |k,v| @@type_registry[k] = v['schema'] } end def Okay.schema( type_name ) @@type_registry[type_name] end def Okay.validate_node( node ) type, mods = OKAY_TYPE_REGEXP.match( node.type_id ).to_a[1,2] unless @@type_registry.has_key?( type ) raise Okay::Error, "Type `#{type}' not found in loaded schema." end return true if @@type_registry[ type ].nil? node_vs_schema( @@type_registry[ type ], node, [], true ) end def Okay.node_vs_schema( schema, node, depth, head ) # # Head type can be matched against a core type # type_id = head ? node.kind : node.type_id type_id = node.kind if type_id.empty? if type_id =~ /^okay\// type_id, mods = OKAY_TYPE_REGEXP.match( type_id ).to_a[1,2] end if schema.has_key?( type_id ) attr = schema[ type_id ] else raise Okay::Error, "Node of type !#{type_id} invalid at /" + depth.join( "/" ) end if @@type_registry[ type_id ] node_vs_schema( @@type_registry[ type_id ], node, depth, true ) end # # Descend and match types of nodes # if attr attr.each { |prop, prop_schema| # # Mini-paths # if prop =~ /^\// key = $' if key == "*" node.children_with_index.each { |c| node_vs_schema( prop_schema, c[0], depth + [c[1]], false ) } else if node[key] child = node[key] node_vs_schema( prop_schema, child, depth + [key], false ) else unless Array === attr['optional'] and attr['optional'].include?( "/" + key ) raise Okay::Error, "No key '#{key}' found at /" + depth.join( "/" ) end end end end } else end return true end def Okay.make_schema_flexhash( type_root ) type_root = YAML::transfer( 'tag:ruby.yaml.org,2002:flexhash', type_root ) type_root.collect! { |e| if Hash === e[1] e[1].each { |k,v| if k =~ /^\// and Array === v e[1][k] = make_schema_flexhash( v ) end } end e } type_root end Okay.add_type( 'schema' ) { |type, val, modules| val.each { |k,v| v['schema'] = make_schema_flexhash( v['schema'] ) } } end yecht-yecht-1.1/ext/ruby/lib/okay/000077500000000000000000000000001262256356000171025ustar00rootroot00000000000000yecht-yecht-1.1/ext/ruby/lib/okay/news.rb000066400000000000000000000026501262256356000204060ustar00rootroot00000000000000# # The !okay/news module for YAML.rb # require 'okay' module Okay class News < ModuleBase attr_accessor :title, :link, :description, :updatePeriod, :items def to_yaml_properties [ '@title', '@link', '@description', '@updatePeriod', '@items' ] end def to_yaml_type "!okay/news" end end Okay.add_type( "news" ) { |type, val, modules| Okay.object_maker( Okay::News, val, modules ) } class NewsItem < ModuleBase attr_accessor :title, :link, :description, :pubTime def to_yaml_properties [ '@title', '@link', '@description', '@pubTime' ] end def to_yaml_type "!okay/news/item" end end Okay.add_type( "news/item" ) { |type, val, modules| Okay.object_maker( Okay::NewsItem, val, modules ) } end Okay.load_schema( < Inspired by RSS, more limited... examples: > If I had a news site... schema: - map: /title: [ str ] /link: [ str ] /description: [ str ] /updatePeriod: [ str ] /items: - seq: { /*: [ okay/news/item ] } okay/news/item: description: > Inside okay/news lies... examples: > See okay/news examples... schema: - map: /title: [ str ] /pubTime: [ time ] /link: [ str ] /description: [ str ] optional: [ /title ] EOY yecht-yecht-1.1/ext/ruby/lib/okay/rpc.rb000066400000000000000000000343301262256356000202160ustar00rootroot00000000000000# # The !okay/rpc module for YAML.rb # Specification at http://wiki.yaml.org/yamlwiki/OkayRpcProtocol # require 'okay' require 'net/http' module Okay module RPC VERSION = '0.06' class Method attr_accessor :methodName, :params def initialize( mn, p ) @methodName = mn @params = p end def to_yaml( opts = {} ) YAML::quick_emit( self.id, opts ) { |out| out.map( "!okay/rpc/method" ) { |map| map.add( self.methodName, self.params ) } } end end YAML.add_domain_type( "okay.yaml.org,2002", "rpc/method" ) { |type, val| if val.class == Hash and val.length == 1 val = val.to_a.first RPC::Method.new( val[0], val[1] ) end } class Fault attr_accessor :code, :message def initialize( c, m ) @code = c @message = m end def to_yaml( opts = {} ) YAML::quick_emit( self.id, opts ) { |out| out.map( "!okay/rpc/fault" ) { |map| map.add( self.code, self.message ) } } end end YAML.add_domain_type( "okay.yaml.org,2002", "rpc/fault" ) { |type, val| if val.class == Hash and val.length == 1 val = val.to_a.first Fault.new( val[0], val[1] ) end } class Client USER_AGENT = "Okay::RPC::Client (Ruby #{RUBY_VERSION})" def initialize(host=nil, path=nil, port=nil, proxy_host=nil, proxy_port=nil, user=nil, password=nil, use_ssl=nil, timeout=nil) @host = host || "localhost" @path = path || "/okayRpc/" @proxy_host = proxy_host @proxy_port = proxy_port @proxy_host ||= 'localhost' if @proxy_port != nil @proxy_port ||= 8080 if @proxy_host != nil @use_ssl = use_ssl || false @timeout = timeout || 30 @queue = YAML::Stream.new( :UseHeader => true ) if use_ssl require "net/https" @port = port || 443 else @port = port || 80 end @user, @password = user, password set_auth # convert ports to integers @port = @port.to_i if @port != nil @proxy_port = @proxy_port.to_i if @proxy_port != nil # HTTP object for synchronous calls Net::HTTP.version_1_2 @http = Net::HTTP.new(@host, @port, @proxy_host, @proxy_port) @http.use_ssl = @use_ssl if @use_ssl @http.read_timeout = @timeout @http.open_timeout = @timeout @parser = nil @create = nil end # Attribute Accessors ------------------------------------------------------------------- attr_reader :timeout, :user, :password def timeout=(new_timeout) @timeout = new_timeout @http.read_timeout = @timeout @http.open_timeout = @timeout end def user=(new_user) @user = new_user set_auth end def password=(new_password) @password = new_password set_auth end # Call methods -------------------------------------------------------------- def call(method, *args) meth = Method.new( method, args ) YAML::load( do_rpc(meth.to_yaml, false) ) end def qcall(method, *args) @queue.add( Method.new( method, args ) ) end def qrun ret = YAML.load_stream( do_rpc( @queue.emit, false ) ) @queue = YAML::Stream.new( :UseHeader => true ) ret end private # ---------------------------------------------------------- def set_auth if @user.nil? @auth = nil else a = "#@user" a << ":#@password" if @password != nil @auth = ("Basic " + [a].pack("m")).chomp end end def do_rpc(request, async=false) header = { "User-Agent" => USER_AGENT, "Content-Type" => "text/yaml", "Content-Length" => request.size.to_s, "Connection" => (async ? "close" : "keep-alive") } if @auth != nil # add authorization header header["Authorization"] = @auth end if async # use a new HTTP object for each call Net::HTTP.version_1_2 http = Net::HTTP.new(@host, @port, @proxy_host, @proxy_port) http.use_ssl = @use_ssl if @use_ssl http.read_timeout = @timeout http.open_timeout = @timeout else # reuse the HTTP object for each call => connection alive is possible http = @http end # post request resp = http.post2(@path, request, header) data = resp.body http.finish if async if resp.code == "401" # Authorization Required raise "Authorization failed.\nHTTP-Error: #{resp.code} #{resp.message}" elsif resp.code[0,1] != "2" raise "HTTP-Error: #{resp.code} #{resp.message}" end if resp["Content-Type"] != "text/yaml" raise "Wrong content-type [#{resp['Content-Type']}]: \n#{data}" end expected = resp["Content-Length"] || "" if data.nil? or data.size == 0 raise "Wrong size. Was #{data.size}, should be #{expected}" elsif expected.to_i != data.size and resp["Transfer-Encoding"].nil? raise "Wrong size. Was #{data.size}, should be #{expected}" end return data end end class BasicServer def initialize @handlers = {} @aboutHash = { 'name' => 'An !okay/rpc server.', 'uri' => nil, 'version' => VERSION, 'authors' => nil, 'about' => "Welcome to the !okay/rpc server." } add_introspection end def name( str ) @aboutHash['name'] end def name=( str ) @aboutHash['name'] = str end def about @aboutHash['about'] end def about=( str ) @aboutHash['about'] = str.strip.gsub( /^ +/, '' ).gsub( /\n(\n*)/, ' \1' ) end def uri( str ) @aboutHash['uri'] end def uri=( str ) @aboutHash['uri'] = str end def add_author( name, email, url ) @aboutHash['authors'] ||= [] @aboutHash['authors'] << { 'name' => name, 'email' => email, 'url' => url } end def add_handler( methodName, sig, doc, &block ) @handlers[ methodName ] = { :signature => sig, :help => doc, :block => block } end def get_handler( methodName, prop ) unless @handlers.has_key?( methodName ) Fault.new( 101, "No method ''#{methodName}'' available." ) else @handlers[ methodName ][ prop ] end end def dispatch( meth ) b = get_handler( meth.methodName, :block ) return b if b.is_a? Fault b.call( meth ) end def process( meth_yml ) s = YAML::Stream.new( :UseHeader => true ) YAML::load_documents( meth_yml ) { |doc| s.add( dispatch( doc ) ) } s.emit end private def add_introspection add_handler( "system.about", %w(map), "Provides a short description of this !okay/rpc server's intent." ) { @aboutHash } add_handler( "system.getCapabilities", %w(map), "Describes this server's capabilities, including version of " + "!okay/rpc available and YAML implementation." ) { { 'okay/rpc' => { 'version' => Okay::RPC::VERSION, 'id' => 'YAML.rb Okay::RPC', 'url' => 'http://wiki.yaml.org/yamlwiki/OkayRpcProtocol' }, 'yaml' => { 'version' => YAML::VERSION, 'id' => 'YAML.rb', 'url' => 'http://yaml4r.sf.net/' }, 'sys' => { 'version' => Kernel::RUBY_VERSION, 'id' => Kernel::RUBY_PLATFORM } } } add_handler( "system.listMethods", %w(seq), "Lists the available methods for this !okay/rpc server." ) { @handlers.keys.sort } add_handler( "system.methodSignature", %w(seq str), "Returns a method signature." ) { |meth| get_handler( meth.params[0], :signature ) } add_handler( "system.methodHelp", %w(str str), "Returns help on using this method." ) { |meth| get_handler( meth.params[0], :help ) } add_handler( "system.methodBlank", %w(str str), "Returns a blank method." ) { |meth| sig = get_handler( meth.params[0], :signature ) unless sig.is_a? Fault "--- !okay/rpc/method\n#{meth.params[0]}:\n" + sig[1..-1].collect { |type| " - !#{type}" }.join( "\n" ) else sig end } end end class ModRubyServer < BasicServer def initialize(*a) @ap = Apache::request super(*a) url ||= @ap.uri end def serve catch(:exit_serve) { header = {} hdr_in_proc = proc {|key, value| header[key.capitalize] = value} if @ap.respond_to? :headers_in @ap.headers_in.each( &hdr_in_proc ) else @ap.each_header( &hdr_in_proc ) end length = header['Content-length'].to_i http_error(405, "Method Not Allowed") unless @ap.request_method == "POST" http_error(400, "Bad Request") unless header['Content-type'] == "text/yaml" http_error(411, "Length Required") unless length > 0 # TODO: do we need a call to binmode? @ap.binmode data = @ap.read(length) http_error(400, "Bad Request") if data.nil? or data.size != length resp = begin process(data) rescue Exception => e Fault.new(101, e.message).to_yaml end http_write(resp, 200, "Content-type" => "text/yaml") } end private def http_error(status, message) err = "#{status} #{message}" msg = <<-"MSGEND" #{err}

#{err}

Unexpected error occured while processing !okay/rpc request!

MSGEND http_write(msg, status, "Status" => err, "Content-type" => "text/html") throw :exit_serve # exit from the #serve method end def http_write(body, status, header) h = {} header.each {|key, value| h[key.to_s.capitalize] = value} h['Status'] ||= "200 OK" h['Content-length'] ||= body.size.to_s h.each do |key, value| if @ap.respond_to? :headers_out @ap.headers_out[key] = value else @ap[key] = value end end @ap.content_type = h["Content-type"] @ap.status = status.to_i @ap.send_http_header @ap.print body end end end end Okay.load_schema( < XML-RPC for YAML. examples: > Testing schema: - map: /*: [ seq ] length: 1 EOY yecht-yecht-1.1/ext/ruby/lib/yaml.rb000066400000000000000000000303411262256356000174270ustar00rootroot00000000000000# -*- mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- vim: sw=4 ts=4 # $Id$ # # = yaml.rb: top-level module with methods for loading and parsing YAML documents # # Author:: why the lucky stiff # require 'stringio' require 'yaml/compat' require 'yaml/error' require 'yaml/yecht' require 'yaml/tag' require 'yaml/stream' require 'yaml/constants' # == YAML # # YAML(tm) (rhymes with 'camel') is a # straightforward machine parsable data serialization format designed for # human readability and interaction with scripting languages such as Perl # and Python. YAML is optimized for data serialization, formatted # dumping, configuration files, log files, Internet messaging and # filtering. This specification describes the YAML information model and # serialization format. Together with the Unicode standard for characters, it # provides all the information necessary to understand YAML Version 1.0 # and construct computer programs to process it. # # See http://yaml.org/ for more information. For a quick tutorial, please # visit YAML In Five Minutes (http://yaml.kwiki.org/?YamlInFiveMinutes). # # == About This Library # # The YAML 1.0 specification outlines four stages of YAML loading and dumping. # This library honors all four of those stages, although data is really only # available to you in three stages. # # The four stages are: native, representation, serialization, and presentation. # # The native stage refers to data which has been loaded completely into Ruby's # own types. (See +YAML::load+.) # # The representation stage means data which has been composed into # +YAML::BaseNode+ objects. In this stage, the document is available as a # tree of node objects. You can perform YPath queries and transformations # at this level. (See +YAML::parse+.) # # The serialization stage happens inside the parser. The YAML parser used in # Ruby is called Yecht. Serialized nodes are available in the extension as # Node structs. # # The presentation stage is the YAML document itself. This is accessible # to you as a string. (See +YAML::dump+.) # # For more information about the various information models, see Chapter # 3 of the YAML 1.0 Specification (http://yaml.org/spec/#id2491269). # # The YAML module provides quick access to the most common loading (YAML::load) # and dumping (YAML::dump) tasks. This module also provides an API for registering # global types (YAML::add_domain_type). # # == Example # # A simple round-trip (load and dump) of an object. # # require "yaml" # # test_obj = ["dogs", "cats", "badgers"] # # yaml_obj = YAML::dump( test_obj ) # # -> --- # - dogs # - cats # - badgers # ruby_obj = YAML::load( yaml_obj ) # # => ["dogs", "cats", "badgers"] # ruby_obj == test_obj # # => true # # To register your custom types with the global resolver, use +add_domain_type+. # # YAML::add_domain_type( "your-site.com,2004", "widget" ) do |type, val| # Widget.new( val ) # end # module YAML Resolver = YAML::Yecht::Resolver DefaultResolver = YAML::Yecht::DefaultResolver DefaultResolver.use_types_at( @@tagged_classes ) GenericResolver = YAML::Yecht::GenericResolver Parser = YAML::Yecht::Parser Emitter = YAML::Yecht::Emitter # Returns a new default parser def YAML.parser; Parser.new.set_resolver( YAML.resolver ); end # Returns a new generic parser def YAML.generic_parser; Parser.new.set_resolver( GenericResolver ); end # Returns the default resolver def YAML.resolver; DefaultResolver; end # Returns a new default emitter def YAML.emitter; Emitter.new.set_resolver( YAML.resolver ); end # # Converts _obj_ to YAML and writes the YAML result to _io_. # # File.open( 'animals.yaml', 'w' ) do |out| # YAML.dump( ['badger', 'elephant', 'tiger'], out ) # end # # If no _io_ is provided, a string containing the dumped YAML # is returned. # # YAML.dump( :locked ) # #=> "--- :locked" # def YAML.dump( obj, io = nil ) obj.to_yaml( io || io2 = StringIO.new ) io || ( io2.rewind; io2.read ) end # # Load a document from the current _io_ stream. # # File.open( 'animals.yaml' ) { |yf| YAML::load( yf ) } # #=> ['badger', 'elephant', 'tiger'] # # Can also load from a string. # # YAML.load( "--- :locked" ) # #=> :locked # def YAML.load( io ) yp = parser.load( io ) end # # Load a document from the file located at _filepath_. # # YAML.load_file( 'animals.yaml' ) # #=> ['badger', 'elephant', 'tiger'] # def YAML.load_file( filepath ) File.open( filepath ) do |f| load( f ) end end # # Parse the first document from the current _io_ stream # # File.open( 'animals.yaml' ) { |yf| YAML::load( yf ) } # #=> #, # #, # #]> # # Can also load from a string. # # YAML.parse( "--- :locked" ) # #=> # # def YAML.parse( io ) yp = generic_parser.load( io ) end # # Parse a document from the file located at _filepath_. # # YAML.parse_file( 'animals.yaml' ) # #=> #, # #, # #]> # def YAML.parse_file( filepath ) File.open( filepath ) do |f| parse( f ) end end # # Calls _block_ with each consecutive document in the YAML # stream contained in _io_. # # File.open( 'many-docs.yaml' ) do |yf| # YAML.each_document( yf ) do |ydoc| # ## ydoc contains the single object # ## from the YAML document # end # end # def YAML.each_document( io, &block ) yp = parser.load_documents( io, &block ) end # # Calls _block_ with each consecutive document in the YAML # stream contained in _io_. # # File.open( 'many-docs.yaml' ) do |yf| # YAML.load_documents( yf ) do |ydoc| # ## ydoc contains the single object # ## from the YAML document # end # end # def YAML.load_documents( io, &doc_proc ) YAML.each_document( io, &doc_proc ) end # # Calls _block_ with a tree of +YAML::BaseNodes+, one tree for # each consecutive document in the YAML stream contained in _io_. # # File.open( 'many-docs.yaml' ) do |yf| # YAML.each_node( yf ) do |ydoc| # ## ydoc contains a tree of nodes # ## from the YAML document # end # end # def YAML.each_node( io, &doc_proc ) yp = generic_parser.load_documents( io, &doc_proc ) end # # Calls _block_ with a tree of +YAML::BaseNodes+, one tree for # each consecutive document in the YAML stream contained in _io_. # # File.open( 'many-docs.yaml' ) do |yf| # YAML.parse_documents( yf ) do |ydoc| # ## ydoc contains a tree of nodes # ## from the YAML document # end # end # def YAML.parse_documents( io, &doc_proc ) YAML.each_node( io, &doc_proc ) end # # Loads all documents from the current _io_ stream, # returning a +YAML::Stream+ object containing all # loaded documents. # def YAML.load_stream( io ) d = nil parser.load_documents( io ) do |doc| d = YAML::Stream.new if not d d.add( doc ) end return d end # # Returns a YAML stream containing each of the items in +objs+, # each having their own document. # # YAML.dump_stream( 0, [], {} ) # #=> --- 0 # --- [] # --- {} # def YAML.dump_stream( *objs ) d = YAML::Stream.new objs.each do |doc| d.add( doc ) end d.emit end # # Add a global handler for a YAML domain type. # def YAML.add_domain_type( domain, type_tag, &transfer_proc ) resolver.add_type( "tag:#{ domain }:#{ type_tag }", transfer_proc ) end # # Add a transfer method for a builtin type # def YAML.add_builtin_type( type_tag, &transfer_proc ) resolver.add_type( "tag:yaml.org,2002:#{ type_tag }", transfer_proc ) end # # Add a transfer method for a builtin type # def YAML.add_ruby_type( type_tag, &transfer_proc ) resolver.add_type( "tag:ruby.yaml.org,2002:#{ type_tag }", transfer_proc ) end # # Add a private document type # def YAML.add_private_type( type_re, &transfer_proc ) resolver.add_type( "x-private:" + type_re, transfer_proc ) end # # Detect typing of a string # def YAML.detect_implicit( val ) resolver.detect_implicit( val ) end # # Convert a type_id to a taguri # def YAML.tagurize( val ) resolver.tagurize( val ) end # # Apply a transfer method to a Ruby object # def YAML.transfer( type_id, obj ) resolver.transfer( YAML.tagurize( type_id ), obj ) end # # Apply any implicit a node may qualify for # def YAML.try_implicit( obj ) YAML.transfer( YAML.detect_implicit( obj ), obj ) end # # Method to extract colon-seperated type and class, returning # the type and the constant of the class # def YAML.read_type_class( type, obj_class ) scheme, domain, type, tclass = type.split( ':', 4 ) tclass.split( "::" ).each { |c| obj_class = obj_class.const_get( c ) } if tclass return [ type, obj_class ] end # # Allocate blank object # def YAML.object_maker( obj_class, val ) if Hash === val o = obj_class.allocate val.each_pair { |k,v| o.instance_variable_set("@#{k}", v) } o else raise YAML::Error, "Invalid object explicitly tagged !ruby/Object: " + val.inspect end end # # Allocate an Emitter if needed # def YAML.quick_emit( oid, opts = {}, &e ) out = if opts.is_a? YAML::Emitter opts else emitter.reset( opts ) end out.emit( oid, &e ) end end require 'yaml/rubytypes' require 'yaml/types' module Kernel # # ryan:: You know how Kernel.p is a really convenient way to dump ruby # structures? The only downside is that it's not as legible as # YAML. # # _why:: (listening) # # ryan:: I know you don't want to urinate all over your users' namespaces. # But, on the other hand, convenience of dumping for debugging is, # IMO, a big YAML use case. # # _why:: Go nuts! Have a pony parade! # # ryan:: Either way, I certainly will have a pony parade. # # Prints any supplied _objects_ out in YAML. Intended as # a variation on +Kernel::p+. # # S = Struct.new(:name, :state) # s = S['dave', 'TX'] # y s # # _produces:_ # # --- !ruby/struct:S # name: dave # state: TX # def y( object, *objects ) objects.unshift object puts( if objects.length == 1 YAML::dump( *objects ) else YAML::dump_stream( *objects ) end ) end private :y end yecht-yecht-1.1/ext/ruby/lib/yaml/000077500000000000000000000000001262256356000171015ustar00rootroot00000000000000yecht-yecht-1.1/ext/ruby/lib/yaml/baseemitter.rb000066400000000000000000000131761262256356000217420ustar00rootroot00000000000000# # BaseEmitter # require 'yaml/constants' require 'yaml/encoding' require 'yaml/error' module YAML module BaseEmitter def options( opt = nil ) if opt @options[opt] || YAML::DEFAULTS[opt] else @options end end def options=( opt ) @options = opt end # # Emit binary data # def binary_base64( value ) self << "!binary " self.node_text( [value].pack("m"), '|' ) end # # Emit plain, normal flowing text # def node_text( value, block = nil ) @seq_map = false valx = value.dup unless block block = if options(:UseBlock) '|' elsif not options(:UseFold) and valx =~ /\n[ \t]/ and not valx =~ /#{YAML::ESCAPE_CHAR}/ '|' else '>' end indt = $&.to_i if block =~ /\d+/ if valx =~ /(\A\n*[ \t#]|^---\s+)/ indt = options(:Indent) unless indt.to_i > 0 block += indt.to_s end block += if valx =~ /\n\Z\n/ "+" elsif valx =~ /\Z\n/ "" else "-" end end block += "\n" if block[0] == ?" esc_skip = ( "\t\n" unless valx =~ /^[ \t]/ ) || "" valx = fold( YAML::escape( valx, esc_skip ) + "\"" ).chomp self << '"' + indent_text( valx, indt, false ) else if block[0] == ?> valx = fold( valx ) end #p [block, indt] self << block + indent_text( valx, indt ) end end # # Emit a simple, unqouted string # def simple( value ) @seq_map = false self << value.to_s end # # Emit double-quoted string # def double( value ) "\"#{YAML.escape( value )}\"" end # # Emit single-quoted string # def single( value ) "'#{value}'" end # # Write a text block with the current indent # def indent_text( text, mod, first_line = true ) return "" if text.to_s.empty? spacing = indent( mod ) text = text.gsub( /\A([^\n])/, "#{ spacing }\\1" ) if first_line return text.gsub( /\n^([^\n])/, "\n#{spacing}\\1" ) end # # Write a current indent # def indent( mod = nil ) #p [ self.id, level, mod, :INDENT ] if level <= 0 mod ||= 0 else mod ||= options(:Indent) mod += ( level - 1 ) * options(:Indent) end return " " * mod end # # Add indent to the buffer # def indent! self << indent end # # Folding paragraphs within a column # def fold( value ) value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]|\Z))|$)/ ) do |s| $1 || $2 + ( $3 || "\n" ) end end # # Quick mapping # def map( type, &e ) val = Mapping.new e.call( val ) self << "#{type} " if type.length.nonzero? # # Empty hashes # if val.length.zero? self << "{}" @seq_map = false else # FIXME # if @buffer.length == 1 and options(:UseHeader) == false and type.length.zero? # @headless = 1 # end defkey = @options.delete( :DefaultKey ) if defkey seq_map_shortcut self << "= : " defkey.to_yaml( :Emitter => self ) end # # Emit the key and value # val.each { |v| seq_map_shortcut if v[0].is_complex_yaml? self << "? " end v[0].to_yaml( :Emitter => self ) if v[0].is_complex_yaml? self << "\n" indent! end self << ": " v[1].to_yaml( :Emitter => self ) } end end def seq_map_shortcut # FIXME: seq_map needs to work with the new anchoring system # if @seq_map # @anchor_extras[@buffer.length - 1] = "\n" + indent # @seq_map = false # else self << "\n" indent! # end end # # Quick sequence # def seq( type, &e ) @seq_map = false val = Sequence.new e.call( val ) self << "#{type} " if type.length.nonzero? # # Empty arrays # if val.length.zero? self << "[]" else # FIXME # if @buffer.length == 1 and options(:UseHeader) == false and type.length.zero? # @headless = 1 # end # # Emit the key and value # val.each { |v| self << "\n" indent! self << "- " @seq_map = true if v.class == Hash v.to_yaml( :Emitter => self ) } end end end # # Emitter helper classes # class Mapping < Array def add( k, v ) push [k, v] end end class Sequence < Array def add( v ) push v end end end yecht-yecht-1.1/ext/ruby/lib/yaml/basenode.rb000066400000000000000000000137611262256356000212160ustar00rootroot00000000000000# # YAML::BaseNode class # require 'yaml/ypath' module YAML # # YAML Generic Model container # module BaseNode # # Search for YPath entry and return # qualified nodes. # def select( ypath_str ) matches = match_path( ypath_str ) # # Create a new generic view of the elements selected # if matches result = [] matches.each { |m| result.push m.last } YAML.transfer( 'seq', result ) end end # # Search for YPath entry and return # transformed nodes. # def select!( ypath_str ) matches = match_path( ypath_str ) # # Create a new generic view of the elements selected # if matches result = [] matches.each { |m| result.push m.last.transform } result end end # # Search for YPath entry and return a list of # qualified paths. # def search( ypath_str ) matches = match_path( ypath_str ) if matches matches.collect { |m| path = [] m.each_index { |i| path.push m[i] if ( i % 2 ).zero? } "/" + path.compact.join( "/" ) } end end def at( seg ) if Hash === @value self[seg] elsif Array === @value and seg =~ /\A\d+\Z/ and @value[seg.to_i] @value[seg.to_i] end end # # YPath search returning a complete depth array # def match_path( ypath_str ) depth = 0 matches = [] YPath.each_path( ypath_str ) do |ypath| seg = match_segment( ypath, 0 ) matches += seg if seg end matches.uniq end # # Search a node for a single YPath segment # def match_segment( ypath, depth ) deep_nodes = [] seg = ypath.segments[ depth ] if seg == "/" unless String === @value idx = -1 @value.collect { |v| idx += 1 if Hash === @value match_init = [v[0].transform, v[1]] match_deep = v[1].match_segment( ypath, depth ) else match_init = [idx, v] match_deep = v.match_segment( ypath, depth ) end if match_deep match_deep.each { |m| deep_nodes.push( match_init + m ) } end } end depth += 1 seg = ypath.segments[ depth ] end match_nodes = case seg when "." [[nil, self]] when ".." [["..", nil]] when "*" if @value.is_a? Enumerable idx = -1 @value.collect { |h| idx += 1 if Hash === @value [h[0].transform, h[1]] else [idx, h] end } end else if seg =~ /^"(.*)"$/ seg = $1 elsif seg =~ /^'(.*)'$/ seg = $1 end if ( v = at( seg ) ) [[ seg, v ]] end end return deep_nodes unless match_nodes pred = ypath.predicates[ depth ] if pred case pred when /^\.=/ pred = $' # ' match_nodes.reject! { |n| n.last.value != pred } else match_nodes.reject! { |n| n.last.at( pred ).nil? } end end return match_nodes + deep_nodes unless ypath.segments.length > depth + 1 #puts "DEPTH: #{depth + 1}" deep_nodes = [] match_nodes.each { |n| if n[1].is_a? BaseNode match_deep = n[1].match_segment( ypath, depth + 1 ) if match_deep match_deep.each { |m| deep_nodes.push( n + m ) } end else deep_nodes = [] end } deep_nodes = nil if deep_nodes.length == 0 deep_nodes end # # We want the node to act like as Hash # if it is. # def []( *key ) if Hash === @value v = @value.detect { |k,v| k.transform == key.first } v[1] if v elsif Array === @value @value.[]( *key ) end end def children if Hash === @value @value.values.collect { |c| c[1] } elsif Array === @value @value end end def children_with_index if Hash === @value @value.keys.collect { |i| [self[i], i] } elsif Array === @value i = -1; @value.collect { |v| i += 1; [v, i] } end end def emit transform.to_yaml end end end yecht-yecht-1.1/ext/ruby/lib/yaml/compat.rb000066400000000000000000000016211262256356000207110ustar00rootroot00000000000000# # Ruby 1.6 -> 1.8 compatibility # (an isolated incident) # class Object; alias_method :object_id, :id; end unless Object.respond_to? :object_id class Object; def instance_variable_set(k, v); self.instance_eval "#{k} = v"; end; end \ unless Object.respond_to? :instance_variable_set class Object; def instance_variable_get(k); self.instance_eval "#{k}"; end; end \ unless Object.respond_to? :instance_variable_get unless Object.respond_to? :allocate class Object def allocate name = self.class.name if Marshal::const_defined? :MAJOR_VERSION ostr = sprintf( "%c%co:%c%s\000", Marshal::MAJOR_VERSION, Marshal::MINOR_VERSION, name.length + 5, name ) else ostr = sprintf( "\004\006o:%c%s\000", name.length + 5, name ) end ::Marshal.load( ostr ) end end end yecht-yecht-1.1/ext/ruby/lib/yaml/constants.rb000066400000000000000000000022421262256356000214420ustar00rootroot00000000000000# # Constants used throughout the library # module YAML # # Constants # VERSION = '0.60' SUPPORTED_YAML_VERSIONS = ['1.0'] # # Parser tokens # WORD_CHAR = 'A-Za-z0-9' PRINTABLE_CHAR = '-_A-Za-z0-9!?/()$\'". ' NOT_PLAIN_CHAR = '\x7f\x0-\x1f\x80-\x9f' ESCAPE_CHAR = '[\\x00-\\x09\\x0b-\\x1f]' INDICATOR_CHAR = '*&!|\\\\^@%{}[]=' SPACE_INDICATORS = '-#:,?' RESTRICTED_INDICATORS = '#:,}]' DNS_COMP_RE = "\\w(?:[-\\w]*\\w)?" DNS_NAME_RE = "(?:(?:#{DNS_COMP_RE}\\.)+#{DNS_COMP_RE}|#{DNS_COMP_RE})" ESCAPES = %w{\x00 \x01 \x02 \x03 \x04 \x05 \x06 \a \x08 \t \n \v \f \r \x0e \x0f \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1a \e \x1c \x1d \x1e \x1f } UNESCAPES = { 'a' => "\x07", 'b' => "\x08", 't' => "\x09", 'n' => "\x0a", 'v' => "\x0b", 'f' => "\x0c", 'r' => "\x0d", 'e' => "\x1b", '\\' => '\\', } # # Default settings # DEFAULTS = { :Indent => 2, :UseHeader => false, :UseVersion => false, :Version => '1.0', :SortKeys => false, :AnchorFormat => 'id%03d', :ExplicitTypes => false, :WidthType => 'absolute', :BestWidth => 80, :UseBlock => false, :UseFold => false, :Encoding => :None } end yecht-yecht-1.1/ext/ruby/lib/yaml/dbm.rb000066400000000000000000000043721262256356000201760ustar00rootroot00000000000000require 'yaml' require 'dbm' # # YAML + DBM = YDBM # - Same interface as DBM class # module YAML class DBM < ::DBM VERSION = "0.1" def []( key ) fetch( key ) end def []=( key, val ) store( key, val ) end def fetch( keystr, ifnone = nil ) begin val = super( keystr ) return YAML::load( val ) if String === val rescue IndexError end if block_given? yield keystr else ifnone end end def index( keystr ) super( keystr.to_yaml ) end def values_at( *keys ) keys.collect { |k| fetch( k ) } end def delete( key ) v = super( key ) if String === v v = YAML::load( v ) end v end def delete_if del_keys = keys.dup del_keys.delete_if { |k| yield( k, fetch( k ) ) == false } del_keys.each { |k| delete( k ) } self end def reject hsh = self.to_hash hsh.reject { |k,v| yield k, v } end def each_pair keys.each { |k| yield k, fetch( k ) } self end def each_value super { |v| yield YAML::load( v ) } self end def values super.collect { |v| YAML::load( v ) } end def has_value?( val ) each_value { |v| return true if v == val } return false end def invert h = {} keys.each { |k| h[ self.fetch( k ) ] = k } h end def replace( hsh ) clear update( hsh ) end def shift a = super a[1] = YAML::load( a[1] ) if a a end def select( *keys ) if block_given? self.keys.collect { |k| v = self[k]; [k, v] if yield k, v }.compact else values_at( *keys ) end end def store( key, val ) super( key, val.to_yaml ) val end def update( hsh ) hsh.keys.each do |k| self.store( k, hsh.fetch( k ) ) end self end def to_a a = [] keys.each { |k| a.push [ k, self.fetch( k ) ] } a end def to_hash h = {} keys.each { |k| h[ k ] = self.fetch( k ) } h end alias :each :each_pair end end yecht-yecht-1.1/ext/ruby/lib/yaml/emitter.rb000066400000000000000000000041341262256356000211010ustar00rootroot00000000000000# # Output classes and methods # require 'yaml/baseemitter' require 'yaml/encoding' module YAML # # Emit a set of values # class Emitter include BaseEmitter attr_accessor :options def initialize( opts ) opts = {} if opts.class != Hash @options = YAML::DEFAULTS.dup.update( opts ) @headless = 0 @seq_map = false @anchors = {} @anchor_extras = {} @active_anchors = [] @level = -1 self.clear end def clear @buffer = [] end def level @level end # # Version string # def version_s " %YAML:#{@options[:Version]}" if @options[:UseVersion] end # # Header # def header if @headless.nonzero? "" else "---#{version_s} " end end # # Concatenate to the buffer # def <<( str ) #p [ self.id, @level, str ] @buffer.last << str end # # Monitor objects and allow references # def start_object( oid ) @level += 1 @buffer.push( "" ) #p [ self.id, @level, :OPEN ] idx = nil if oid if @anchors.has_key?( oid ) idx = @active_anchors.index( oid ) unless idx idx = @active_anchors.length af_str = "&#{@options[:AnchorFormat]} " % [ idx + 1 ] af_str += @anchor_extras[ @anchors[ oid ] ].to_s @buffer[ @anchors[ oid ] ][0,0] = af_str @headless = 0 if @anchors[ oid ].zero? end idx += 1 @active_anchors.push( oid ) else @anchors[ oid ] = @buffer.length - 1 end end return idx end # # Output method # def end_object @level -= 1 @buffer.push( "" ) #p [ self.id, @level, :END ] if @level < 0 header + @buffer.to_s[@headless..-1].to_s end end end end yecht-yecht-1.1/ext/ruby/lib/yaml/encoding.rb000066400000000000000000000011441262256356000212140ustar00rootroot00000000000000# # Handle Unicode-to-Internal conversion # module YAML # # Escape the string, condensing common escapes # def YAML.escape( value, skip = "" ) value.gsub( /\\/, "\\\\\\" ). gsub( /"/, "\\\"" ). gsub( /([\x00-\x1f])/ ) do |x| skip[x] || ESCAPES[ x.unpack("C")[0] ] end end # # Unescape the condenses escapes # def YAML.unescape( value ) value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) { |x| if $3 ["#$3".hex ].pack('U*') elsif $2 [$2].pack( "H2" ) else UNESCAPES[$1] end } end end yecht-yecht-1.1/ext/ruby/lib/yaml/error.rb000066400000000000000000000020551262256356000205610ustar00rootroot00000000000000# # Error messages and exception class # module YAML # # Error messages # ERROR_NO_HEADER_NODE = "With UseHeader=false, the node Array or Hash must have elements" ERROR_NEED_HEADER = "With UseHeader=false, the node must be an Array or Hash" ERROR_BAD_EXPLICIT = "Unsupported explicit transfer: '%s'" ERROR_MANY_EXPLICIT = "More than one explicit transfer" ERROR_MANY_IMPLICIT = "More than one implicit request" ERROR_NO_ANCHOR = "No anchor for alias '%s'" ERROR_BAD_ANCHOR = "Invalid anchor: %s" ERROR_MANY_ANCHOR = "More than one anchor" ERROR_ANCHOR_ALIAS = "Can't define both an anchor and an alias" ERROR_BAD_ALIAS = "Invalid alias: %s" ERROR_MANY_ALIAS = "More than one alias" ERROR_ZERO_INDENT = "Can't use zero as an indentation width" ERROR_UNSUPPORTED_VERSION = "This release of YAML.rb does not support YAML version %s" ERROR_UNSUPPORTED_ENCODING = "Attempt to use unsupported encoding: %s" # # YAML Error classes # class Error < StandardError; end class ParseError < Error; end class TypeError < StandardError; end end yecht-yecht-1.1/ext/ruby/lib/yaml/rubytypes.rb000066400000000000000000000343141262256356000215010ustar00rootroot00000000000000# -*- mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- vim: sw=4 ts=4 require 'date' require 'yaml/compat' # For Compatibility with Syck 0.60 # class Module # yaml_as "tag:ruby.yaml.org,2002:module" # def Module.yaml_new( klass, tag, val ) # if String === val # val.split(/::/).inject(Object) do |m, n| # begin # m.const_get(n) # rescue NameError # raise ArgumentError, "undefined class/module #{n} in #{val}" # end # end # else # raise YAML::TypeError, "Invalid Module: " + val.inspect # end # end # def to_yaml( opts = {} ) # YAML::quick_emit( nil, opts ) { |out| # out.scalar( "tag:ruby.yaml.org,2002:module", self.name, :plain ) # } # end # end # class Class # yaml_as "tag:ruby.yaml.org,2002:class" # def Class.yaml_new( klass, tag, val ) # if String === val # val.split(/::/).inject(Object) do |m, n| # begin # m.const_get(n) # rescue NameError # raise ArgumentError, "undefined class/module #{n} in #{val}" # end # end # else # raise YAML::TypeError, "Invalid Class: " + val.inspect # end # end # def to_yaml( opts = {} ) # YAML::quick_emit( nil, opts ) { |out| # out.scalar( "tag:ruby.yaml.org,2002:class", self.name, :plain ) # } # end # end class Class def to_yaml( opts = {} ) raise TypeError, "can't dump anonymous class %s" % self.class end end class Object yaml_as "tag:ruby.yaml.org,2002:object" def to_yaml_style; end def to_yaml_properties; instance_variables.sort; end def to_yaml( opts = {} ) YAML::quick_emit( object_id, opts ) do |out| out.map( taguri, to_yaml_style ) do |map| to_yaml_properties.each do |m| map.add( m[1..-1], instance_variable_get( m ) ) end end end end end class Hash yaml_as "tag:ruby.yaml.org,2002:hash" yaml_as "tag:yaml.org,2002:map" def yaml_initialize( tag, val ) if Array === val update Hash.[]( *val ) # Convert the map to a sequence elsif Hash === val update val else raise YAML::TypeError, "Invalid map explicitly tagged #{ tag }: " + val.inspect end end def to_yaml( opts = {} ) YAML::quick_emit( object_id, opts ) do |out| out.map( taguri, to_yaml_style ) do |map| each do |k, v| map.add( k, v ) end end end end end class Struct yaml_as "tag:ruby.yaml.org,2002:struct" def self.yaml_tag_class_name; self.name.gsub( "Struct::", "" ); end def self.yaml_tag_read_class( name ); "Struct::#{ name }"; end def self.yaml_new( klass, tag, val ) if Hash === val struct_type = nil # # Use existing Struct if it exists # props = {} val.delete_if { |k,v| props[k] = v if k =~ /^@/ } begin struct_name, struct_type = YAML.read_type_class( tag, Struct ) rescue NameError end if not struct_type struct_def = [ tag.split( ':', 4 ).last ] struct_type = Struct.new( *struct_def.concat( val.keys.collect { |k| k.intern } ) ) end # # Set the Struct properties # st = YAML::object_maker( struct_type, {} ) st.members.each do |m| st.send( "#{m}=", val[m] ) end props.each do |k,v| st.instance_variable_set(k, v) end st else raise YAML::TypeError, "Invalid Ruby Struct: " + val.inspect end end def to_yaml( opts = {} ) YAML::quick_emit( object_id, opts ) do |out| # # Basic struct is passed as a YAML map # out.map( taguri, to_yaml_style ) do |map| self.members.each do |m| map.add( m, self[m] ) end self.to_yaml_properties.each do |m| map.add( m, instance_variable_get( m ) ) end end end end end class Array yaml_as "tag:ruby.yaml.org,2002:array" yaml_as "tag:yaml.org,2002:seq" def yaml_initialize( tag, val ); concat( val.to_a ); end def to_yaml( opts = {} ) YAML::quick_emit( object_id, opts ) do |out| out.seq( taguri, to_yaml_style ) do |seq| each do |x| seq.add( x ) end end end end end class Exception yaml_as "tag:ruby.yaml.org,2002:exception" def Exception.yaml_new( klass, tag, val ) o = YAML.object_maker( klass, { 'mesg' => val.delete( 'message' ) } ) val.each_pair do |k,v| o.instance_variable_set("@#{k}", v) end o end def to_yaml( opts = {} ) YAML::quick_emit( object_id, opts ) do |out| out.map( taguri, to_yaml_style ) do |map| map.add( 'message', message ) to_yaml_properties.each do |m| map.add( m[1..-1], instance_variable_get( m ) ) end end end end end class String yaml_as "tag:ruby.yaml.org,2002:string" yaml_as "tag:yaml.org,2002:binary" yaml_as "tag:yaml.org,2002:str" def is_complex_yaml? to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.+/ end def is_binary_data? ( self.count( "^ -~", "^\r\n" ) / self.size > 0.3 || self.count( "\x00" ) > 0 ) unless empty? end def String.yaml_new( klass, tag, val ) val = val.unpack("m")[0] if tag == "tag:yaml.org,2002:binary" val = { 'str' => val } if String === val if Hash === val s = klass.allocate # Thank you, NaHi String.instance_method(:initialize). bind(s). call( val.delete( 'str' ) ) val.each { |k,v| s.instance_variable_set( k, v ) } s else raise YAML::TypeError, "Invalid String: " + val.inspect end end def to_yaml( opts = {} ) YAML::quick_emit( is_complex_yaml? ? object_id : nil, opts ) do |out| if is_binary_data? out.scalar( "tag:yaml.org,2002:binary", [self].pack("m"), :literal ) elsif to_yaml_properties.empty? out.scalar( taguri, self, self =~ /^:/ ? :quote2 : to_yaml_style ) else out.map( taguri, to_yaml_style ) do |map| map.add( 'str', "#{self}" ) to_yaml_properties.each do |m| map.add( m, instance_variable_get( m ) ) end end end end end end class Symbol yaml_as "tag:ruby.yaml.org,2002:symbol" yaml_as "tag:ruby.yaml.org,2002:sym" def Symbol.yaml_new( klass, tag, val ) if String === val val = YAML::load( val ) if val =~ /\A(["']).*\1\z/ val.intern else raise YAML::TypeError, "Invalid Symbol: " + val.inspect end end def to_yaml( opts = {} ) YAML::quick_emit( nil, opts ) do |out| out.scalar( "tag:yaml.org,2002:str", self.inspect, :plain ) end end end class Range yaml_as "tag:ruby.yaml.org,2002:range" def Range.yaml_new( klass, tag, val ) inr = %r'(\w+|[+-]?\d+(?:\.\d+)?(?:e[+-]\d+)?|"(?:[^\\"]|\\.)*")' opts = {} if String === val and val =~ /^#{inr}(\.{2,3})#{inr}$/o r1, rdots, r2 = $1, $2, $3 opts = { 'begin' => YAML.load( "--- #{r1}" ), 'end' => YAML.load( "--- #{r2}" ), 'excl' => rdots.length == 3 } val = {} elsif Hash === val opts['begin'] = val.delete('begin') opts['end'] = val.delete('end') opts['excl'] = val.delete('excl') end if Hash === opts r = YAML::object_maker( klass, {} ) # Thank you, NaHi Range.instance_method(:initialize). bind(r). call( opts['begin'], opts['end'], opts['excl'] ) val.each { |k,v| r.instance_variable_set( k, v ) } r else raise YAML::TypeError, "Invalid Range: " + val.inspect end end def to_yaml( opts = {} ) YAML::quick_emit( object_id, opts ) do |out| # if self.begin.is_complex_yaml? or self.begin.respond_to? :to_str or # self.end.is_complex_yaml? or self.end.respond_to? :to_str or # not to_yaml_properties.empty? out.map( taguri, to_yaml_style ) do |map| map.add( 'begin', self.begin ) map.add( 'end', self.end ) map.add( 'excl', self.exclude_end? ) to_yaml_properties.each do |m| map.add( m, instance_variable_get( m ) ) end end # else # out.scalar( taguri ) do |sc| # sc.embed( self.begin ) # sc.concat( self.exclude_end? ? "..." : ".." ) # sc.embed( self.end ) # end # end end end end class Regexp yaml_as "tag:ruby.yaml.org,2002:regexp" def Regexp.yaml_new( klass, tag, val ) if String === val and val =~ /^\/(.*)\/([mix]*)$/ val = { 'regexp' => $1, 'mods' => $2 } end if Hash === val mods = nil unless val['mods'].to_s.empty? mods = 0x00 mods |= Regexp::EXTENDED if val['mods'].include?( 'x' ) mods |= Regexp::IGNORECASE if val['mods'].include?( 'i' ) mods |= Regexp::MULTILINE if val['mods'].include?( 'm' ) end val.delete( 'mods' ) r = YAML::object_maker( klass, {} ) Regexp.instance_method(:initialize). bind(r). call( val.delete( 'regexp' ), mods ) val.each { |k,v| r.instance_variable_set( k, v ) } r else raise YAML::TypeError, "Invalid Regular expression: " + val.inspect end end def to_yaml( opts = {} ) YAML::quick_emit( nil, opts ) do |out| if to_yaml_properties.empty? out.scalar( taguri, self.inspect, :plain ) else out.map( taguri, to_yaml_style ) do |map| src = self.inspect if src =~ /\A\/(.*)\/([a-z]*)\Z/ map.add( 'regexp', $1 ) map.add( 'mods', $2 ) else raise YAML::TypeError, "Invalid Regular expression: " + src end to_yaml_properties.each do |m| map.add( m, instance_variable_get( m ) ) end end end end end end class Time yaml_as "tag:ruby.yaml.org,2002:time" yaml_as "tag:yaml.org,2002:timestamp" def Time.yaml_new( klass, tag, val ) if Hash === val t = val.delete( 'at' ) val.each { |k,v| t.instance_variable_set( k, v ) } t else raise YAML::TypeError, "Invalid Time: " + val.inspect end end def to_yaml( opts = {} ) YAML::quick_emit( object_id, opts ) do |out| tz = "Z" # from the tidy Tobias Peters Thanks! unless self.utc? utc_same_instant = self.dup.utc utc_same_writing = Time.utc(year,month,day,hour,min,sec,usec) difference_to_utc = utc_same_writing - utc_same_instant if (difference_to_utc < 0) difference_sign = '-' absolute_difference = -difference_to_utc else difference_sign = '+' absolute_difference = difference_to_utc end difference_minutes = (absolute_difference/60).round tz = "%s%02d:%02d" % [ difference_sign, difference_minutes / 60, difference_minutes % 60] end standard = self.strftime( "%Y-%m-%d %H:%M:%S" ) standard += ".%06d" % [usec] if usec.nonzero? standard += " %s" % [tz] if to_yaml_properties.empty? out.scalar( taguri, standard, :plain ) else out.map( taguri, to_yaml_style ) do |map| map.add( 'at', standard ) to_yaml_properties.each do |m| map.add( m, instance_variable_get( m ) ) end end end end end end class Date yaml_as "tag:yaml.org,2002:timestamp#ymd" def to_yaml( opts = {} ) YAML::quick_emit( object_id, opts ) do |out| out.scalar( "tag:yaml.org,2002:timestamp", self.to_s, :plain ) end end end class Integer yaml_as "tag:yaml.org,2002:int" def to_yaml( opts = {} ) YAML::quick_emit( nil, opts ) do |out| out.scalar( "tag:yaml.org,2002:int", self.to_s, :plain ) end end end class Float yaml_as "tag:yaml.org,2002:float" def to_yaml( opts = {} ) YAML::quick_emit( nil, opts ) do |out| str = self.to_s if str == "Infinity" str = ".Inf" elsif str == "-Infinity" str = "-.Inf" elsif str == "NaN" str = ".NaN" end out.scalar( "tag:yaml.org,2002:float", str, :plain ) end end end class TrueClass yaml_as "tag:yaml.org,2002:bool#yes" def to_yaml( opts = {} ) YAML::quick_emit( nil, opts ) do |out| out.scalar( taguri, "true", :plain ) end end end class FalseClass yaml_as "tag:yaml.org,2002:bool#no" def to_yaml( opts = {} ) YAML::quick_emit( nil, opts ) do |out| out.scalar( taguri, "false", :plain ) end end end class NilClass yaml_as "tag:yaml.org,2002:null" def to_yaml( opts = {} ) YAML::quick_emit( nil, opts ) do |out| out.scalar( taguri, "", :plain ) end end end yecht-yecht-1.1/ext/ruby/lib/yaml/store.rb000066400000000000000000000006251262256356000205650ustar00rootroot00000000000000# # YAML::Store # require 'yaml' require 'pstore' class YAML::Store < PStore def initialize( *o ) @opt = YAML::DEFAULTS.dup if String === o.first super(o.shift) end if o.last.is_a? Hash @opt.update(o.pop) end end def dump(table) @table.to_yaml(@opt) end def load(content) YAML::load(content) end def load_file(file) YAML::load(file) end end yecht-yecht-1.1/ext/ruby/lib/yaml/stream.rb000066400000000000000000000012741262256356000207250ustar00rootroot00000000000000module YAML # # YAML::Stream -- for emitting many documents # class Stream attr_accessor :documents, :options def initialize( opts = {} ) @options = opts @documents = [] end def []( i ) @documents[ i ] end def add( doc ) @documents << doc end def edit( doc_num, doc ) @documents[ doc_num ] = doc end def emit( io = nil ) # opts = @options.dup # opts[:UseHeader] = true if @documents.length > 1 out = YAML.emitter out.reset( io || io2 = StringIO.new ) @documents.each { |v| v.to_yaml( out ) } io || ( io2.rewind; io2.read ) end end end yecht-yecht-1.1/ext/ruby/lib/yaml/stringio.rb000066400000000000000000000036611262256356000212720ustar00rootroot00000000000000# # Limited StringIO if no core lib is available # begin require 'stringio' rescue LoadError # StringIO based on code by MoonWolf class StringIO def initialize(string="") @string=string @pos=0 @eof=(string.size==0) end def pos @pos end def eof @eof end alias eof? eof def readline(rs=$/) if @eof raise EOFError else if p = @string[@pos..-1]=~rs line = @string[@pos,p+1] else line = @string[@pos..-1] end @pos+=line.size @eof =true if @pos==@string.size $_ = line end end def rewind seek(0,0) end def seek(offset,whence) case whence when 0 @pos=offset when 1 @pos+=offset when 2 @pos=@string.size+offset end @eof=(@pos>=@string.size) 0 end end # # Class method for creating streams # def YAML.make_stream( io ) if String === io io = StringIO.new( io ) elsif not IO === io raise YAML::Error, "YAML stream must be an IO or String object." end if YAML::unicode def io.readline YAML.utf_to_internal( readline( @ln_sep ), @utf_encoding ) end def io.check_unicode @utf_encoding = YAML.sniff_encoding( read( 4 ) ) @ln_sep = YAML.enc_separator( @utf_encoding ) seek( -4, IO::SEEK_CUR ) end def io.utf_encoding @utf_encoding end io.check_unicode else def io.utf_encoding :None end end io end end yecht-yecht-1.1/ext/ruby/lib/yaml/tag.rb000066400000000000000000000060441262256356000202050ustar00rootroot00000000000000# -*- mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- vim: sw=4 ts=4 # $Id$ # # = yaml/tag.rb: methods for associating a taguri to a class. # # Author:: why the lucky stiff # module YAML # A dictionary of taguris which map to # Ruby classes. @@tagged_classes = {} # # Associates a taguri _tag_ with a Ruby class _cls_. The taguri is used to give types # to classes when loading YAML. Taguris are of the form: # # tag:authorityName,date:specific # # The +authorityName+ is a domain name or email address. The +date+ is the date the type # was issued in YYYY or YYYY-MM or YYYY-MM-DD format. The +specific+ is a name for # the type being added. # # For example, built-in YAML types have 'yaml.org' as the +authorityName+ and '2002' as the # +date+. The +specific+ is simply the name of the type: # # tag:yaml.org,2002:int # tag:yaml.org,2002:float # tag:yaml.org,2002:timestamp # # The domain must be owned by you on the +date+ declared. If you don't own any domains on the # date you declare the type, you can simply use an e-mail address. # # tag:why@ruby-lang.org,2004:notes/personal # def YAML.tag_class( tag, cls ) if @@tagged_classes.has_key? tag warn "class #{ @@tagged_classes[tag] } held ownership of the #{ tag } tag" end @@tagged_classes[tag] = cls end # Returns the complete dictionary of taguris, paired with classes. The key for # the dictionary is the full taguri. The value for each key is the class constant # associated to that taguri. # # YAML.tagged_classes["tag:yaml.org,2002:int"] => Integer # def YAML.tagged_classes @@tagged_classes end end class Module # :nodoc: all # Adds a taguri _tag_ to a class, used when dumping or loading the class # in YAML. See YAML::tag_class for detailed information on typing and # taguris. def yaml_as( tag, sc = true ) verbose, $VERBOSE = $VERBOSE, nil class_eval <<-"end;", __FILE__, __LINE__+1 attr_writer :taguri def taguri if respond_to? :to_yaml_type YAML::tagurize( to_yaml_type[1..-1] ) else return @taguri if defined?(@taguri) and @taguri tag = #{ tag.dump } if self.class.yaml_tag_subclasses? and self.class != YAML::tagged_classes[tag] tag = "\#{ tag }:\#{ self.class.yaml_tag_class_name }" end tag end end def self.yaml_tag_subclasses?; #{ sc ? 'true' : 'false' }; end end; YAML::tag_class tag, self ensure $VERBOSE = verbose end # Transforms the subclass name into a name suitable for display # in a subclassed tag. def yaml_tag_class_name self.name end # Transforms the subclass name found in the tag into a Ruby # constant name. def yaml_tag_read_class( name ) name end end yecht-yecht-1.1/ext/ruby/lib/yaml/types.rb000066400000000000000000000120201262256356000205650ustar00rootroot00000000000000# -*- mode: ruby; ruby-indent-level: 4 -*- vim: sw=4 # # Classes required by the full core typeset # require 'yaml/compat' module YAML # # Default private type # class PrivateType def self.tag_subclasses?; false; end attr_accessor :type_id, :value verbose, $VERBOSE = $VERBOSE, nil def initialize( type, val ) @type_id = type; @value = val @value.taguri = "x-private:#{ @type_id }" end def to_yaml( opts = {} ) @value.to_yaml( opts ) end ensure $VERBOSE = verbose end # # Default domain type # class DomainType def self.tag_subclasses?; false; end attr_accessor :domain, :type_id, :value verbose, $VERBOSE = $VERBOSE, nil def initialize( domain, type, val ) @domain = domain; @type_id = type; @value = val @value.taguri = "tag:#{ @domain }:#{ @type_id }" end def to_yaml( opts = {} ) @value.to_yaml( opts ) end ensure $VERBOSE = verbose end # # Unresolved objects # class Object def self.tag_subclasses?; false; end def to_yaml( opts = {} ) YAML::quick_emit( object_id, opts ) do |out| out.map( "tag:ruby.yaml.org,2002:object:#{ @class }", to_yaml_style ) do |map| @ivars.each do |k,v| map.add( k, v ) end end end end end # # YAML Hash class to support comments and defaults # class SpecialHash < ::Hash attr_accessor :default def inspect self.default.to_s end def to_s self.default.to_s end def update( h ) if YAML::SpecialHash === h @default = h.default if h.default end super( h ) end def to_yaml( opts = {} ) opts[:DefaultKey] = self.default super( opts ) end end # # Builtin collection: !omap # class Omap < ::Array yaml_as "tag:yaml.org,2002:omap" def yaml_initialize( tag, val ) if Array === val val.each do |v| if Hash === v concat( v.to_a ) # Convert the map to a sequence else raise YAML::Error, "Invalid !omap entry: " + val.inspect end end else raise YAML::Error, "Invalid !omap: " + val.inspect end self end def self.[]( *vals ) o = Omap.new 0.step( vals.length - 1, 2 ) do |i| o[vals[i]] = vals[i+1] end o end def []( k ) self.assoc( k ).to_a[1] end def []=( k, *rest ) val, set = rest.reverse if ( tmp = self.assoc( k ) ) and not set tmp[1] = val else self << [ k, val ] end val end def has_key?( k ) self.assoc( k ) ? true : false end def is_complex_yaml? true end def to_yaml( opts = {} ) YAML::quick_emit( self.object_id, opts ) do |out| out.seq( taguri, to_yaml_style ) do |seq| self.each do |v| seq.add( Hash[ *v ] ) end end end end end # # Builtin collection: !pairs # class Pairs < ::Array yaml_as "tag:yaml.org,2002:pairs" def yaml_initialize( tag, val ) if Array === val val.each do |v| if Hash === v concat( v.to_a ) # Convert the map to a sequence else raise YAML::Error, "Invalid !pairs entry: " + val.inspect end end else raise YAML::Error, "Invalid !pairs: " + val.inspect end self end def self.[]( *vals ) p = Pairs.new 0.step( vals.length - 1, 2 ) { |i| p[vals[i]] = vals[i+1] } p end def []( k ) self.assoc( k ).to_a end def []=( k, val ) self << [ k, val ] val end def has_key?( k ) self.assoc( k ) ? true : false end def is_complex_yaml? true end def to_yaml( opts = {} ) YAML::quick_emit( self.object_id, opts ) do |out| out.seq( taguri, to_yaml_style ) do |seq| self.each do |v| seq.add( Hash[ *v ] ) end end end end end # # Builtin collection: !set # class Set < ::Hash yaml_as "tag:yaml.org,2002:set" end end yecht-yecht-1.1/ext/ruby/lib/yaml/yamlnode.rb000066400000000000000000000023001262256356000212310ustar00rootroot00000000000000# # YAML::YamlNode class # require 'yaml/basenode' module YAML # # YAML Generic Model container # class YamlNode include BaseNode attr_accessor :kind, :type_id, :value, :anchor def initialize( t, v ) @type_id = t if Hash === v @kind = 'map' @value = {} v.each { |k,v| @value[ k.transform ] = [ k, v ] } elsif Array === v @kind = 'seq' @value = v elsif String === v @kind = 'scalar' @value = v end end # # Transform this node fully into a native type # def transform t = nil if @value.is_a? Hash t = {} @value.each { |k,v| t[ k ] = v[1].transform } elsif @value.is_a? Array t = [] @value.each { |v| t.push v.transform } else t = @value end YAML.transfer_method( @type_id, t ) end end end yecht-yecht-1.1/ext/ruby/lib/yaml/yecht.rb000066400000000000000000000004231262256356000205410ustar00rootroot00000000000000# # YAML::Yecht module # .. glues yecht and yaml.rb together .. # require 'yecht' require 'yaml/basenode' module YAML module Yecht # # Mixin BaseNode functionality # class Node include YAML::BaseNode end end end yecht-yecht-1.1/ext/ruby/lib/yaml/ypath.rb000066400000000000000000000024601262256356000205550ustar00rootroot00000000000000# # YAML::YPath # module YAML class YPath attr_accessor :segments, :predicates, :flags def initialize( str ) @segments = [] @predicates = [] @flags = nil while str =~ /^\/?(\/|[^\/\[]+)(?:\[([^\]]+)\])?/ @segments.push $1 @predicates.push $2 str = $' end unless str.to_s.empty? @segments += str.split( "/" ) end if @segments.length == 0 @segments.push "." end end def YPath.each_path( str ) # # Find choices # paths = [] str = "(#{ str })" while str.sub!( /\(([^()]+)\)/, "\n#{ paths.length }\n" ) paths.push $1.split( '|' ) end # # Construct all possible paths # all = [ str ] ( paths.length - 1 ).downto( 0 ) do |i| all = all.collect do |a| paths[i].collect do |p| a.gsub( /\n#{ i }\n/, p ) end end.flatten.uniq end all.collect do |path| yield YPath.new( path ) end end end end yecht-yecht-1.1/ext/ruby/src/000077500000000000000000000000001262256356000161605ustar00rootroot00000000000000yecht-yecht-1.1/ext/ruby/src/java/000077500000000000000000000000001262256356000171015ustar00rootroot00000000000000yecht-yecht-1.1/ext/ruby/src/java/YechtService.java000066400000000000000000000112171262256356000223430ustar00rootroot00000000000000 import java.io.IOException; import org.jruby.Ruby; import org.jruby.RubyClass; import org.jruby.RubyModule; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.runtime.load.BasicLibraryService; import org.yecht.YAML; import org.yecht.ruby.*; public class YechtService implements BasicLibraryService { public boolean basicLoad(final Ruby runtime) throws IOException { ThreadContext ctx = runtime.getCurrentContext(); RubyModule rb_yaml = runtime.getOrCreateModule("YAML"); RubyModule rb_yecht = rb_yaml.defineModuleUnder("Yecht"); rb_yecht.defineConstant("VERSION", runtime.newString(YAML.YECHT_VERSION)); rb_yecht.defineAnnotatedMethods(Module.class); RubyClass cResolver = rb_yecht.defineClassUnder("Resolver", runtime.getObject(), runtime.getObject().getAllocator()); cResolver.defineAnnotatedMethods(Resolver.class); cResolver.addReadWriteAttribute(ctx, "tags"); IRubyObject oDefaultResolver = cResolver.callMethod(ctx, "new"); oDefaultResolver.getSingletonClass().defineAnnotatedMethods(DefaultResolver.class); rb_yecht.defineConstant("DefaultResolver", oDefaultResolver); IRubyObject oGenericResolver = cResolver.callMethod(ctx, "new"); oGenericResolver.getSingletonClass().defineAnnotatedMethods(GenericResolver.class); rb_yecht.defineConstant("GenericResolver", oGenericResolver); RubyClass cParser = rb_yecht.defineClassUnder("Parser", runtime.getObject(), YParser.Allocator); cParser.defineAnnotatedMethods(YParser.class); cParser.addReadWriteAttribute(ctx, "options"); cParser.addReadWriteAttribute(ctx, "resolver"); cParser.addReadWriteAttribute(ctx, "input"); RubyClass cNode = rb_yecht.defineClassUnder("Node", runtime.getObject(), Node.Allocator); cNode.defineAnnotatedMethods(Node.class); cNode.addReadWriteAttribute(ctx, "emitter"); cNode.addReadWriteAttribute(ctx, "resolver"); cNode.addReadAttribute(ctx, "kind"); cNode.addReadAttribute(ctx, "type_id"); cNode.addReadAttribute(ctx, "kind"); cNode.addReadAttribute(ctx, "value"); RubyClass cScalar = rb_yecht.defineClassUnder("Scalar", cNode, Scalar.Allocator); cScalar.defineAnnotatedMethods(Scalar.class); cScalar.addReadAttribute(ctx, "value"); RubyClass cSeq = rb_yecht.defineClassUnder("Seq", cNode, Seq.Allocator); cSeq.defineAnnotatedMethods(Seq.class); RubyClass cMap = rb_yecht.defineClassUnder("Map", cNode, Map.Allocator); cMap.defineAnnotatedMethods(Map.class); RubyClass cPrivateType = rb_yecht.defineClassUnder("PrivateType", runtime.getObject(), runtime.getObject().getAllocator()); cPrivateType.defineAnnotatedMethods(PrivateType.class); cPrivateType.addReadWriteAttribute(ctx, "type_id"); cPrivateType.addReadWriteAttribute(ctx, "value"); RubyClass cDomainType = rb_yecht.defineClassUnder("DomainType", runtime.getObject(), runtime.getObject().getAllocator()); cDomainType.defineAnnotatedMethods(DomainType.class); cDomainType.addReadWriteAttribute(ctx, "domain"); cDomainType.addReadWriteAttribute(ctx, "type_id"); cDomainType.addReadWriteAttribute(ctx, "value"); RubyClass cYObject = rb_yaml.defineClassUnder("Object", runtime.getObject(), runtime.getObject().getAllocator()); cYObject.defineAnnotatedMethods(YObject.class); cYObject.addReadWriteAttribute(ctx, "class"); cYObject.addReadWriteAttribute(ctx, "ivars"); RubyClass cBadAlias = rb_yecht.defineClassUnder("BadAlias", runtime.getObject(), BadAlias.Allocator); cBadAlias.defineAnnotatedMethods(BadAlias.class); cBadAlias.addReadWriteAttribute(ctx, "name"); cBadAlias.includeModule(runtime.getComparable()); rb_yecht.defineClassUnder("MergeKey", runtime.getObject(), runtime.getObject().getAllocator()); rb_yecht.defineClassUnder("DefaultKey", runtime.getObject(), runtime.getObject().getAllocator()); RubyClass cOut = rb_yecht.defineClassUnder("Out", runtime.getObject(), runtime.getObject().getAllocator()); cOut.defineAnnotatedMethods(Out.class); cOut.addReadWriteAttribute(ctx, "emitter"); RubyClass cEmitter = rb_yecht.defineClassUnder("Emitter", runtime.getObject(), YEmitter.Allocator); cEmitter.defineAnnotatedMethods(YEmitter.class); cEmitter.addReadWriteAttribute(ctx, "level"); oGenericResolver.dataWrapStruct(new GenericResolver.Extra(runtime)); rb_yaml.dataWrapStruct(new YAMLExtra(runtime)); return true; } } yecht-yecht-1.1/ext/ruby/src/java/org/000077500000000000000000000000001262256356000176705ustar00rootroot00000000000000yecht-yecht-1.1/ext/ruby/src/java/org/yecht/000077500000000000000000000000001262256356000210045ustar00rootroot00000000000000yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/000077500000000000000000000000001262256356000217655ustar00rootroot00000000000000yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/ArrayStorageLink.java000066400000000000000000000010651262256356000260530ustar00rootroot00000000000000package org.yecht.ruby; import org.jruby.RubyArray; import org.jruby.runtime.builtin.IRubyObject; class ArrayStorageLink extends StorageLink { private final RubyArray array; private final int index; private final IRubyObject originalObject; public ArrayStorageLink(IRubyObject arr, int index, IRubyObject originalObject) { this.array = (RubyArray)arr; this.index = index; this.originalObject = originalObject; } public void replaceLinkWith(IRubyObject newObject) { array.store(index, newObject); } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/BadAlias.java000066400000000000000000000032641262256356000242750ustar00rootroot00000000000000package org.yecht.ruby; import java.util.List; import java.util.LinkedList; import org.jruby.Ruby; import org.jruby.RubyClass; import org.jruby.RubyObject; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.ObjectAllocator; import org.jruby.runtime.builtin.IRubyObject; public class BadAlias extends RubyObject implements PossibleLinkNode { public static final ObjectAllocator Allocator = new ObjectAllocator() { public IRubyObject allocate(Ruby runtime, RubyClass klass) { return new BadAlias(runtime, klass); } }; public BadAlias(Ruby runtime, RubyClass metaClass) { super(runtime, metaClass); } private List links = new LinkedList(); public List getLinks() { return links; } public void addLink(StorageLink link) { links.add(link); } public void replaceLinks(IRubyObject newObject) { for(StorageLink sl : links) { sl.replaceLinkWith(newObject); } links.clear(); } // syck_badalias_initialize @JRubyMethod public static IRubyObject initialize(IRubyObject self, IRubyObject val) { ((RubyObject)self).fastSetInstanceVariable("@name", val); return self; } // syck_badalias_cmp @JRubyMethod(name = "<=>") public static IRubyObject cmp(IRubyObject alias1, IRubyObject alias2) { IRubyObject str1 = (IRubyObject)((RubyObject)alias1).fastGetInstanceVariable("@name"); IRubyObject str2 = (IRubyObject)((RubyObject)alias2).fastGetInstanceVariable("@name"); return str1.callMethod(alias1.getRuntime().getCurrentContext(), "<=>", str2); } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/DefaultResolver.java000066400000000000000000000514451262256356000257470ustar00rootroot00000000000000package org.yecht.ruby; import java.util.List; import java.util.LinkedList; import java.util.Map; import java.util.HashMap; import org.yecht.BadAnchorHandler; import org.yecht.BytecodeNodeHandler; import org.yecht.Bytestring; import org.yecht.Data; import org.yecht.Emitter; import org.yecht.EmitterHandler; import org.yecht.ErrorHandler; import org.yecht.IoStrRead; import org.yecht.JechtIO; import org.yecht.MapPart; import org.yecht.NodeHandler; import org.yecht.Parser; import org.yecht.ParserInput; import org.yecht.OutputHandler; import org.yecht.Pointer; import org.yecht.ImplicitScanner; import org.yecht.ImplicitScanner2; import org.yecht.MapStyle; import org.yecht.SeqStyle; import org.yecht.ScalarStyle; import org.jruby.Ruby; import org.jruby.RubyArray; import org.jruby.RubyClass; import org.jruby.RubyEnumerable; import org.jruby.RubyFixnum; import org.jruby.RubyHash; import org.jruby.RubyKernel; import org.jruby.RubyModule; import org.jruby.RubyNumeric; import org.jruby.RubyObject; import org.jruby.RubyString; import org.jruby.RubyTime; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.Block; import org.jruby.runtime.BlockCallback; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.runtime.ObjectAllocator; import org.jruby.util.ByteList; import org.jruby.util.TypeConverter; public class DefaultResolver { private static int extractInt(byte[] buff, int p, int pend) { int len = 0; while((p+len) < pend && Character.isDigit((char)buff[p+len])) { len++; } try { return Integer.parseInt(new String(buff, p, len, "ISO-8859-1")); } catch(java.io.UnsupportedEncodingException e) {return -1;} } // rb_syck_mktime public static IRubyObject makeTime(Ruby runtime, Pointer str, int len) { // System.err.println("makeTime(" + new String(str.buffer, str.start, len) + ")"); int ptr = str.start; int pend = ptr + len; IRubyObject year = runtime.newFixnum(0); IRubyObject mon = runtime.newFixnum(0); IRubyObject day = runtime.newFixnum(0); IRubyObject hour = runtime.newFixnum(0); IRubyObject min = runtime.newFixnum(0); IRubyObject sec = runtime.newFixnum(0); IRubyObject addSec = runtime.newFixnum(0); long usec = 0; if(str.buffer[ptr] != 0 && ptr < pend) { year = runtime.newFixnum(extractInt(str.buffer, ptr, pend)); } ptr += 4; if(str.buffer[ptr] != 0 && ptr < pend) { while(!Character.isDigit((char)str.buffer[ptr]) && ptr < pend) ptr++; mon = runtime.newFixnum(extractInt(str.buffer, ptr, pend)); } ptr += 2; if(str.buffer[ptr] != 0 && ptr < pend) { while(!Character.isDigit((char)str.buffer[ptr]) && ptr < pend) ptr++; day = runtime.newFixnum(extractInt(str.buffer, ptr, pend)); } ptr += 2; if(str.buffer[ptr] != 0 && ptr < pend) { while(!Character.isDigit((char)str.buffer[ptr]) && ptr < pend) ptr++; hour = runtime.newFixnum(extractInt(str.buffer, ptr, pend)); } ptr += 2; if(str.buffer[ptr] != 0 && ptr < pend) { while(!Character.isDigit((char)str.buffer[ptr]) && ptr < pend) ptr++; min = runtime.newFixnum(extractInt(str.buffer, ptr, pend)); } ptr += 2; if(str.buffer[ptr] != 0 && ptr < pend) { while(!Character.isDigit((char)str.buffer[ptr]) && ptr < pend) ptr++; sec = runtime.newFixnum(extractInt(str.buffer, ptr, pend)); } ptr += 2; if(ptr < pend && str.buffer[ptr] == '.') { int end = ptr + 1; while(Character.isDigit((char)str.buffer[end]) && end < pend) end++; byte[] padded = new byte[]{'0', '0', '0', '0', '0', '0'}; int begin = ptr+1; int extraSeconds = 0; if(end - begin > 6) { extraSeconds = (end - begin) - 6; begin += extraSeconds; addSec = runtime.newFixnum(extractInt(str.buffer, begin - extraSeconds, begin)); } System.arraycopy(str.buffer, begin, padded, 0, end - begin); try { usec = Long.parseLong(new String(padded, 0, 6, "ISO-8859-1")); } catch(java.io.UnsupportedEncodingException e) {} } else { usec = 0; } while(ptr < pend && str.buffer[ptr] != 'Z' && str.buffer[ptr] != '+' && str.buffer[ptr] != '-' && str.buffer[ptr] != 0) { ptr++; } if(ptr < pend && (str.buffer[ptr] == '-' || str.buffer[ptr] == '+')) { int lenx = 1; while(ptr+lenx < pend && Character.isDigit((char)str.buffer[ptr+lenx])) { lenx++; } if(str.buffer[ptr] == '+') { ptr++; lenx--; } try { long tz_offset = Long.parseLong(new String(str.buffer, ptr, lenx, "ISO-8859-1")) * 3600; ptr+=lenx; while(ptr < pend && str.buffer[ptr] != ':' && str.buffer[ptr] != 0 ) { ptr++; } if(ptr < pend && str.buffer[ptr] == ':') { ptr++; if(tz_offset < 0) { tz_offset -= extractInt(str.buffer, ptr, pend) * 60; } else { tz_offset += extractInt(str.buffer, ptr, pend) * 60; } } IRubyObject time = runtime.getClass("Time").callMethod(runtime.getCurrentContext(), "utc", new IRubyObject[]{year,mon,day,hour,min,sec}); long tmp = RubyNumeric.num2long(time.callMethod(runtime.getCurrentContext(), "to_i")) - tz_offset; return ((RubyTime)runtime.getClass("Time").callMethod(runtime.getCurrentContext(), "at", new IRubyObject[]{runtime.newFixnum(tmp), runtime.newFixnum(usec)})).op_plus(addSec); } catch(java.io.UnsupportedEncodingException e) {} } else { // Make UTC time return ((RubyTime)runtime.getClass("Time").callMethod(runtime.getCurrentContext(), "utc", new IRubyObject[]{year,mon,day,hour,min,sec,runtime.newFixnum(usec)})).op_plus(addSec); } System.err.println("oopsie, returning null"); return null; } private static interface ObjectCreator { IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) throws java.io.UnsupportedEncodingException; } private static Map scalarTypes = new HashMap(); static { scalarTypes.put("null", new ObjectCreator() { public IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) { return runtime.getNil(); } }); scalarTypes.put("binary", new ObjectCreator() { public IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) { ThreadContext ctx = runtime.getCurrentContext(); IRubyObject obj = RubyString.newStringShared(runtime, ds.ptr.buffer, ds.ptr.start, ds.len); obj.callMethod(ctx, "tr!", new IRubyObject[]{runtime.newString("\n\t "), runtime.newString("")}); IRubyObject arr = obj.callMethod(ctx, "unpack", runtime.newString("m")); return ((RubyArray)arr).shift(ctx); } }); scalarTypes.put("bool#yes", new ObjectCreator() { public IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) { return runtime.getTrue(); } }); scalarTypes.put("bool#no", new ObjectCreator() { public IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) { return runtime.getFalse(); } }); scalarTypes.put("int#hex", new ObjectCreator() { public IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) { n.strBlowAwayCommas(); return RubyNumeric.str2inum(runtime, RubyString.newStringShared(runtime, ds.ptr.buffer, ds.ptr.start, ds.len), 16, true); } }); scalarTypes.put("int#oct", new ObjectCreator() { public IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) { n.strBlowAwayCommas(); return RubyNumeric.str2inum(runtime, RubyString.newStringShared(runtime, ds.ptr.buffer, ds.ptr.start, ds.len), 8, true); } }); scalarTypes.put("int#base60", new ObjectCreator() { public IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) throws java.io.UnsupportedEncodingException { long sixty = 1; long total = 0; n.strBlowAwayCommas(); int ptr = ds.ptr.start; int end = ptr + ds.len; while(end > ptr) { long bnum = 0; int colon = end - 1; while(colon >= ptr && ds.ptr.buffer[colon] != ':' ) { colon--; } bnum = Integer.parseInt(new String(ds.ptr.buffer, colon+1, end-(colon+1), "ISO-8859-1")); total += bnum * sixty; sixty *= 60; end = colon; } return runtime.newFixnum(total); } }); scalarTypes.put("float#base60", new ObjectCreator() { public IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) throws java.io.UnsupportedEncodingException { long sixty = 1; double total = 0.0; n.strBlowAwayCommas(); int ptr = ds.ptr.start; int end = ptr + ds.len; while(end > ptr) { double bnum = 0; int colon = end - 1; while(colon >= ptr && ds.ptr.buffer[colon] != ':' ) { colon--; } bnum = Double.parseDouble(new String(ds.ptr.buffer, colon+1, end-(colon+1), "ISO-8859-1")); total += bnum * sixty; sixty *= 60; end = colon; } return runtime.newFloat(total); } }); scalarTypes.put("float#nan", new ObjectCreator() { public IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) { return runtime.newFloat(Double.NaN); } }); scalarTypes.put("float#inf", new ObjectCreator() { public IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) { return runtime.newFloat(Double.POSITIVE_INFINITY); } }); scalarTypes.put("float#neginf", new ObjectCreator() { public IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) { return runtime.newFloat(Double.NEGATIVE_INFINITY); } }); scalarTypes.put("timestamp#iso8601", new ObjectCreator() { public IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) { return makeTime(runtime, ds.ptr, ds.len); } }); scalarTypes.put("timestamp#spaced", new ObjectCreator() { public IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) { return makeTime(runtime, ds.ptr, ds.len); } }); scalarTypes.put("timestamp#ymd", new ObjectCreator() { public IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) throws java.io.UnsupportedEncodingException { IRubyObject year = runtime.newFixnum(Integer.parseInt(new String(ds.ptr.buffer, 0, 4, "ISO-8859-1"))); IRubyObject mon = runtime.newFixnum(Integer.parseInt(new String(ds.ptr.buffer, 5, 2, "ISO-8859-1"))); IRubyObject day = runtime.newFixnum(Integer.parseInt(new String(ds.ptr.buffer, 8, 2, "ISO-8859-1"))); RubyKernel.require(runtime.getTopSelf(), runtime.newString("date"), Block.NULL_BLOCK); return runtime.getClass("Date").callMethod(runtime.getCurrentContext(), "new", new IRubyObject[] {year, mon, day}); } }); scalarTypes.put("str", new ObjectCreator() { public IRubyObject create(Ruby runtime, org.yecht.Node n, Data.Str ds) { return RubyString.newStringShared(runtime, ds.ptr.buffer, ds.ptr.start, ds.len); } }); } private static boolean handleScalar(Ruby runtime, org.yecht.Node n, String type_id, IRubyObject[] ref, YAMLExtra x) throws java.io.UnsupportedEncodingException { Data.Str ds = (Data.Str)n.data; ThreadContext ctx = runtime.getCurrentContext(); boolean transferred = true; IRubyObject obj = null; if(type_id == null) { obj = RubyString.newStringShared(runtime, ds.ptr.buffer, ds.ptr.start, ds.len); } else { if(ds.style == ScalarStyle.Plain && ds.len > 1 && ds.ptr.buffer[ds.ptr.start] == ':') { obj = x.DefaultResolver.callMethod(ctx, "transfer", new IRubyObject[]{runtime.newString("tag:ruby.yaml.org,2002:sym"), RubyString.newStringShared(runtime, ds.ptr.buffer, ds.ptr.start+1, ds.len-1) }); } else { ObjectCreator oc = scalarTypes.get(type_id); if(oc != null) { obj = oc.create(runtime, n, ds); } else { if(type_id.startsWith("int")) { n.strBlowAwayCommas(); obj = RubyNumeric.str2inum(runtime, RubyString.newStringShared(runtime, ds.ptr.buffer, ds.ptr.start, ds.len), 10, true); } else if(type_id.startsWith("float")) { n.strBlowAwayCommas(); obj = RubyString.newStringShared(runtime, ds.ptr.buffer, ds.ptr.start, ds.len); obj = obj.callMethod(ctx, "to_f"); } else if(type_id.startsWith("timestamp")) { obj = makeTime(runtime, ds.ptr, ds.len); } else if(type_id.startsWith("merge")) { obj = x.MergeKey.callMethod(ctx, "new"); } else if(type_id.startsWith("default")) { obj = x.DefaultKey.callMethod(ctx, "new"); } else { transferred = false; obj = RubyString.newStringShared(runtime, ds.ptr.buffer, ds.ptr.start, ds.len); } } } } ref[0] = obj; return transferred; } public static boolean handleSeq(Ruby runtime, org.yecht.Node n, String type_id, IRubyObject[] ref) { boolean transferred = type_id == null || "seq".equals(type_id); Data.Seq dl = (Data.Seq)n.data; Object[] items = dl.items; RubyArray obj = RubyArray.newArray(runtime, dl.idx); for(int i = 0; i < dl.idx; i++) { IRubyObject _obj = (IRubyObject)items[i]; if(_obj instanceof PossibleLinkNode) { ((PossibleLinkNode)_obj).addLink(new ArrayStorageLink(obj, i, _obj)); } obj.store(i, _obj); } ref[0] = obj; return transferred; } public static boolean handleMap(final Ruby runtime, org.yecht.Node n, String type_id, IRubyObject[] ref, YAMLExtra x) { boolean transferred = type_id == null || "map".equals(type_id); ThreadContext ctx = runtime.getCurrentContext(); Data.Map dm = (Data.Map)n.data; Object[] keys = dm.keys; Object[] vals = dm.values; RubyHash obj = RubyHash.newHash(runtime); RubyClass cMergeKey = x.MergeKey; RubyClass cDefaultKey = x.DefaultKey; for(int i = 0; i < dm.idx; i++) { IRubyObject k = (IRubyObject)keys[i]; IRubyObject v = (IRubyObject)vals[i]; if(null == v) { v = runtime.getNil(); } boolean skip_aset = false; if(cMergeKey.isInstance(k)) { IRubyObject tmp = null; if(!(tmp = TypeConverter.convertToTypeWithCheck(v, runtime.getHash(), "to_hash")).isNil()) { RubyHash dup = (RubyHash)v.callMethod(ctx, "dup"); dup.callMethod(ctx, "update", obj); obj = dup; skip_aset = true; } else if(!(tmp = v.checkArrayType()).isNil()) { IRubyObject end = ((RubyArray)tmp).pop(ctx); IRubyObject tmph = TypeConverter.convertToTypeWithCheck(end, runtime.getHash(), "to_hash"); if(!tmph.isNil()) { final RubyHash dup = (RubyHash)tmph.callMethod(ctx, "dup"); tmp = ((RubyArray)tmp).reverse(); ((RubyArray)tmp).append(obj); RubyEnumerable.callEach(runtime, ctx, tmp, new BlockCallback() { // syck_merge_i public IRubyObject call(ThreadContext _ctx, IRubyObject[] largs, Block blk) { IRubyObject entry = largs[0]; IRubyObject tmp = null; if(!(tmp = TypeConverter.convertToTypeWithCheck(entry, runtime.getHash(), "to_hash")).isNil()) { dup.callMethod(_ctx, "update", tmp); } return runtime.getNil(); } }); obj = dup; skip_aset = true; } } } else if(cDefaultKey.isInstance(k)) { obj.callMethod(ctx, "default=", v); skip_aset = true; } if(!skip_aset) { if(v instanceof PossibleLinkNode) { ((PossibleLinkNode)v).addLink(new HashStorageLink(obj, k, v)); } obj.fastASet(k, v); } } ref[0] = obj; return transferred; } // yaml_org_handler public static boolean orgHandler(IRubyObject self, org.yecht.Node n, IRubyObject[] ref, YAMLExtra x) { final Ruby runtime = self.getRuntime(); String type_id = n.type_id; boolean transferred = false; if(type_id != null && type_id.startsWith("tag:yaml.org,2002:")) { type_id = type_id.substring(18); } try { switch(n.kind) { case Str: transferred = handleScalar(runtime, n, type_id, ref, x); break; case Seq: transferred = handleSeq(runtime, n, type_id, ref); break; case Map: transferred = handleMap(runtime, n, type_id, ref, x); break; } } catch(java.io.UnsupportedEncodingException e) {} return transferred; } // syck_defaultresolver_node_import @JRubyMethod public static IRubyObject node_import(IRubyObject self, IRubyObject node) { // System.err.println("syck_defaultresolver_node_import()"); org.yecht.Node n = (org.yecht.Node)node.dataGetStructChecked(); IRubyObject[] _obj = new IRubyObject[]{null}; if(!orgHandler(self, n, _obj, ((Node)node).x)) { _obj[0] = self.callMethod(self.getRuntime().getCurrentContext(), "transfer", new IRubyObject[]{self.getRuntime().newString(n.type_id), _obj[0]}); } return _obj[0]; } // syck_defaultresolver_detect_implicit @JRubyMethod public static IRubyObject detect_implicit(IRubyObject self, IRubyObject val) { IRubyObject tmp = TypeConverter.convertToTypeWithCheck(val, self.getRuntime().getString(), "to_str"); if(!tmp.isNil()) { ByteList bl = ((RubyString)tmp).getByteList(); String type_id = ImplicitScanner2.matchImplicit(Pointer.create(bl.bytes, bl.begin), bl.realSize); return self.getRuntime().newString(type_id); } return RubyString.newEmptyString(self.getRuntime()); } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/DomainType.java000066400000000000000000000010741262256356000247030ustar00rootroot00000000000000package org.yecht.ruby; import org.jruby.RubyObject; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.builtin.IRubyObject; public class DomainType { // syck_domaintype_initialize @JRubyMethod public static IRubyObject initialize(IRubyObject self, IRubyObject domain, IRubyObject type_id, IRubyObject val) { ((RubyObject)self).fastSetInstanceVariable("@domain", domain); ((RubyObject)self).fastSetInstanceVariable("@type_id", type_id); ((RubyObject)self).fastSetInstanceVariable("@value", val); return self; } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/GenericResolver.java000066400000000000000000000122731262256356000257330ustar00rootroot00000000000000package org.yecht.ruby; import org.yecht.Data; import org.yecht.MapStyle; import org.yecht.MapPart; import org.yecht.SeqStyle; import org.jruby.Ruby; import org.jruby.RubyArray; import org.jruby.RubyHash; import org.jruby.RubyModule; import org.jruby.RubyObject; import org.jruby.RubyString; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.CallSite; import org.jruby.runtime.MethodIndex; public class GenericResolver { public static class Extra { public IRubyObject quote1; public IRubyObject quote2; public IRubyObject fold; public IRubyObject literal; public IRubyObject plain; public IRubyObject map; public IRubyObject seq; public IRubyObject inline; public IRubyObject Scalar; public IRubyObject Seq; public IRubyObject Map; public Ruby runtime; private final CallSite newScalarAdapter = MethodIndex.getFunctionalCallSite("new"); private final CallSite newSeqAdapter = MethodIndex.getFunctionalCallSite("new"); private final CallSite newMapAdapter = MethodIndex.getFunctionalCallSite("new"); public Extra(Ruby runtime) { quote1 = runtime.newSymbol("quote1"); quote2 = runtime.newSymbol("quote2"); fold = runtime.newSymbol("fold"); literal = runtime.newSymbol("literal"); plain = runtime.newSymbol("plain"); map = runtime.newSymbol("map"); seq = runtime.newSymbol("seq"); inline = runtime.newSymbol("inline"); Scalar = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Scalar"); Seq = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Seq"); Map = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Map"); this.runtime = runtime; } public IRubyObject scalar(IRubyObject t, org.yecht.Node n, ThreadContext ctx) { Data.Str dd = (Data.Str)n.data; IRubyObject v = RubyString.newStringShared(runtime, dd.ptr.buffer, dd.ptr.start, dd.len); IRubyObject style = runtime.getNil(); switch(dd.style) { case OneQuote: style = quote1; break; case TwoQuote: style = quote2; break; case Fold: style = fold; break; case Literal: style = literal; break; case Plain: style = plain; break; } return newScalarAdapter.call(ctx, Scalar, Scalar, t, v, style); } public IRubyObject sequence(IRubyObject t, org.yecht.Node n, ThreadContext ctx) { Data.Seq ds = (Data.Seq)n.data; Object[] items = ds.items; IRubyObject v = RubyArray.newArray(runtime, ds.idx); for(int i = 0; i < ds.idx; i++) { ((RubyArray)v).store(i, (IRubyObject)items[i]); } IRubyObject style = runtime.getNil(); if(((Data.Seq)n.data).style == SeqStyle.Inline) { style = inline; } IRubyObject obj = newSeqAdapter.call(ctx, Seq, Seq, t, v, style); ((RubyObject)obj).fastSetInstanceVariable("@kind", seq); return obj; } public IRubyObject mapping(IRubyObject t, org.yecht.Node n, ThreadContext ctx) { Data.Map dm = (Data.Map)n.data; Object[] keys = dm.keys; Object[] vals = dm.values; IRubyObject v = RubyHash.newHash(runtime); for(int i = 0; i < dm.idx; i++) { IRubyObject k3 = (IRubyObject)keys[i]; IRubyObject v3 = (IRubyObject)vals[i]; if(null == v3) { v3 = runtime.getNil(); } ((RubyHash)v).fastASet(k3, v3); } IRubyObject style = runtime.getNil(); if(((Data.Map)n.data).style == MapStyle.Inline) { style = inline; } IRubyObject obj = newMapAdapter.call(ctx, Map, Map, t, v, style); ((RubyObject)obj).fastSetInstanceVariable("@kind", map); return obj; } } // syck_genericresolver_node_import @JRubyMethod public static IRubyObject node_import(IRubyObject self, IRubyObject node) { // System.err.println("syck_genericresolver_node_import()"); Ruby runtime = self.getRuntime(); ThreadContext ctx = runtime.getCurrentContext(); org.yecht.Node n = (org.yecht.Node)node.dataGetStructChecked(); IRubyObject t = runtime.getNil(); Extra x = (Extra)self.dataGetStruct(); if(n.type_id != null) { t = runtime.newString(n.type_id); } switch(n.kind) { case Str: return x.scalar(t, n, ctx); case Seq: return x.sequence(t, n, ctx); case Map: return x.mapping(t, n, ctx); } return runtime.getNil(); } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/HashStorageLink.java000066400000000000000000000010311262256356000256510ustar00rootroot00000000000000package org.yecht.ruby; import org.jruby.RubyHash; import org.jruby.runtime.builtin.IRubyObject; class HashStorageLink extends StorageLink { final RubyHash hash; final IRubyObject key; final IRubyObject originalObject; public HashStorageLink(IRubyObject h, IRubyObject key, IRubyObject originalObject) { this.hash = (RubyHash)h; this.key = key; this.originalObject = originalObject; } public void replaceLinkWith(IRubyObject newObject) { hash.fastASet(key, newObject); } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/Map.java000066400000000000000000000105531262256356000233510ustar00rootroot00000000000000package org.yecht.ruby; import org.yecht.Data; import org.yecht.MapStyle; import org.jruby.Ruby; import org.jruby.RubyArray; import org.jruby.RubyClass; import org.jruby.RubyHash; import org.jruby.RubyObject; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.ObjectAllocator; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.util.TypeConverter; public class Map { public static final ObjectAllocator Allocator = new ObjectAllocator() { // syck_map_alloc public IRubyObject allocate(Ruby runtime, RubyClass klass) { // System.err.println("ALLOCATING MAP"); org.yecht.Node node = org.yecht.Node.allocMap(); IRubyObject obj = new Node(runtime, klass, node, (YAMLExtra)runtime.getModule("YAML").dataGetStruct()); node.id = obj; // System.err.println("syck_map_alloc() -> setting id"); return obj; } }; // syck_map_initialize @JRubyMethod public static IRubyObject initialize(IRubyObject self, IRubyObject type_id, IRubyObject val, IRubyObject style) { org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked(); Ruby runtime = self.getRuntime(); ThreadContext ctx = runtime.getCurrentContext(); Data.Map ds = (Data.Map)node.data; if(!val.isNil()) { IRubyObject hsh = TypeConverter.convertToTypeWithCheck(val, runtime.getHash(), "to_hash"); if(hsh.isNil()) { throw runtime.newTypeError("wrong argument type"); } IRubyObject keys = hsh.callMethod(ctx, "keys"); for(int i = 0; i < ((RubyArray)keys).getLength(); i++) { IRubyObject key = ((RubyArray)keys).entry(i); node.mapAdd(key, ((RubyHash)hsh).op_aref(ctx, key)); } } ((RubyObject)self).fastSetInstanceVariable("@kind", ((Node)self).x.seq); // NOT A TYPO - Syck does the same self.callMethod(ctx, "type_id=", type_id); self.callMethod(ctx, "value=", val); self.callMethod(ctx, "style=", style); return self; } // syck_map_value_set @JRubyMethod(name = "value=") public static IRubyObject value_set(IRubyObject self, IRubyObject val) { org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked(); Ruby runtime = self.getRuntime(); ThreadContext ctx = runtime.getCurrentContext(); if(!val.isNil()) { IRubyObject hsh = TypeConverter.convertToTypeWithCheck(val, runtime.getHash(), "to_hash"); if(hsh.isNil()) { throw runtime.newTypeError("wrong argument type"); } node.mapEmpty(); IRubyObject keys = hsh.callMethod(ctx, "keys"); for(int i = 0; i < ((RubyArray)keys).getLength(); i++) { IRubyObject key = ((RubyArray)keys).entry(i); node.mapAdd(key, ((RubyHash)hsh).op_aref(ctx, key)); } } ((RubyObject)self).fastSetInstanceVariable("@value", val); return val; } // syck_map_add_m @JRubyMethod public static IRubyObject add(IRubyObject self, IRubyObject key, IRubyObject val) { IRubyObject emitter = (IRubyObject)((RubyObject)self).fastGetInstanceVariable("@emitter"); org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked(); if(emitter.respondsTo("node_export")) { key = emitter.callMethod(self.getRuntime().getCurrentContext(), "node_export", key); val = emitter.callMethod(self.getRuntime().getCurrentContext(), "node_export", val); } node.mapAdd(key, val); ((RubyHash)((RubyObject)self).fastGetInstanceVariable("@value")).fastASet(key, val); return self; } // syck_map_style_set @JRubyMethod(name = "style=") public static IRubyObject style_set(IRubyObject self, IRubyObject style) { org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked(); Ruby runtime = self.getRuntime(); Data.Map ds = (Data.Map)node.data; if(style == ((Node)self).x.inline) { ds.style = MapStyle.Inline; } else { ds.style = MapStyle.None; } ((RubyObject)self).fastSetInstanceVariable("@style", style); return self; } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/Module.java000066400000000000000000000021641262256356000240600ustar00rootroot00000000000000package org.yecht.ruby; import org.yecht.Bytestring; import org.yecht.BytecodeNodeHandler; import org.yecht.Parser; import org.jruby.RubyString; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.util.ByteList; public class Module { // rb_syck_compile @JRubyMethod(name = "compile", required = 1, module = true) public static IRubyObject compile(IRubyObject self, IRubyObject port) { Parser parser = Parser.newParser(); boolean taint = YParser.assignIO(self.getRuntime(), parser, new IRubyObject[] {port}); parser.handler(new BytecodeNodeHandler()); parser.errorHandler(null); parser.implicitTyping(false); parser.taguriExpansion(false); Bytestring sav = (Bytestring)parser.parse(); int len = Bytestring.strlen(sav.buffer); ByteList bl = new ByteList(new byte[len+2], false); bl.append(sav.buffer, 0, len); bl.append('D'); bl.append('\n'); IRubyObject iro = RubyString.newStringLight(self.getRuntime(), bl); if(taint) iro.setTaint(true); return iro; } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/Node.java000066400000000000000000000077751262256356000235350ustar00rootroot00000000000000package org.yecht.ruby; import org.yecht.MapPart; import org.jruby.Ruby; import org.jruby.RubyClass; import org.jruby.RubyString; import org.jruby.RubyObject; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.ObjectAllocator; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; public class Node extends RubyObject.Data { public static final ObjectAllocator Allocator = new ObjectAllocator() { public IRubyObject allocate(Ruby runtime, RubyClass klass) { return new Node(runtime, klass, null, (YAMLExtra)runtime.getModule("YAML").dataGetStruct()); } }; public YAMLExtra x; public Node(Ruby runtime, RubyClass metaClass, Object data, YAMLExtra x) { super(runtime, metaClass, data); this.x = x; } public Node(RubyClass metaClass, Object data, YAMLExtra x) { super(metaClass, data); this.x = x; } // syck_node_init_copy @JRubyMethod public static IRubyObject initialize_copy(IRubyObject copy, IRubyObject orig) { if(copy == orig) { return copy; } if(orig.getClass() != RubyObject.class) { throw copy.getRuntime().newTypeError("wrong argument type"); } org.yecht.Node orig_n = (org.yecht.Node)orig.dataGetStructChecked(); org.yecht.Node copy_n = (org.yecht.Node)copy.dataGetStructChecked(); copy_n.id = orig_n.id; copy_n.kind = orig_n.kind; copy_n.type_id = orig_n.type_id; copy_n.anchor = orig_n.anchor; copy_n.data = orig_n.data.copy(); return copy; } // syck_node_type_id_set @JRubyMethod(name = "type_id=") public static IRubyObject set_type_id(IRubyObject self, IRubyObject type_id) { org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked(); if(!type_id.isNil()) { node.type_id = type_id.convertToString().toString(); } ((RubyObject)self).fastSetInstanceVariable("@type_id", type_id); return type_id; } // syck_node_transform @JRubyMethod public static IRubyObject transform(IRubyObject self) { // System.err.println("syck_node_transform()"); Ruby runtime = self.getRuntime(); ThreadContext ctx = runtime.getCurrentContext(); org.yecht.Node orig_n = (org.yecht.Node)self.dataGetStructChecked(); YAMLExtra x = ((Node)self).x; IRubyObject t = new Node(runtime, self.getType(), null, x); org.yecht.Node n = null; switch(orig_n.kind) { case Map: n = org.yecht.Node.allocMap(); t.dataWrapStruct(n); org.yecht.Data.Map dm = (org.yecht.Data.Map)orig_n.data; for(int i=0; i < dm.idx; i++) { IRubyObject k = ((IRubyObject)orig_n.mapRead(MapPart.Key, i)).callMethod(ctx, "transform"); IRubyObject v = ((IRubyObject)orig_n.mapRead(MapPart.Value, i)).callMethod(ctx, "transform"); n.mapAdd(k, v); } break; case Seq: n = org.yecht.Node.allocSeq(); t.dataWrapStruct(n); org.yecht.Data.Seq ds = (org.yecht.Data.Seq)orig_n.data; for(int i=0; i < ds.idx; i++) { IRubyObject itm = ((IRubyObject)orig_n.seqRead(i)).callMethod(ctx, "transform"); n.seqAdd(itm); } break; case Str: org.yecht.Data.Str dss = (org.yecht.Data.Str)orig_n.data; n = org.yecht.Node.newStr(dss.ptr, dss.len, dss.style); t.dataWrapStruct(n); break; } if(orig_n.type_id != null) { n.type_id = orig_n.type_id; } if(orig_n.anchor != null) { n.anchor = orig_n.anchor; } n.id = t; // System.err.println("syck_node_transform(), setting id of object on: " + n); IRubyObject result = x.DefaultResolver.callMethod(ctx, "node_import", t); return result; } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/ObjectStorageLink.java000066400000000000000000000010551262256356000262020ustar00rootroot00000000000000package org.yecht.ruby; import org.jruby.runtime.builtin.IRubyObject; class ObjectStorageLink extends StorageLink { final IRubyObject obj; final String ivarName; final IRubyObject originalObject; public ObjectStorageLink(IRubyObject obj, String ivarName, IRubyObject originalObject) { this.obj = obj; this.ivarName = ivarName; this.originalObject = originalObject; } public void replaceLinkWith(IRubyObject newObject) { obj.getInstanceVariables().setInstanceVariable(ivarName, newObject); } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/Out.java000066400000000000000000000062561262256356000234100ustar00rootroot00000000000000package org.yecht.ruby; import org.yecht.Emitter; import org.jruby.Ruby; import org.jruby.RubyArray; import org.jruby.RubyHash; import org.jruby.RubyModule; import org.jruby.RubyObject; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.Block; import org.jruby.runtime.BlockCallback; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; public class Out { // syck_out_mark public static void outMark(IRubyObject emitter, IRubyObject node) { Emitter emitterPtr = (Emitter)emitter.dataGetStructChecked(); YEmitter.Extra bonus = (YEmitter.Extra)emitterPtr.bonus; ((RubyObject)node).fastSetInstanceVariable("@emitter", emitter); if(!bonus.oid.isNil()) { ((RubyHash)bonus.data).fastASet(bonus.oid, node); } } // syck_out_initialize @JRubyMethod public static IRubyObject initialize(IRubyObject self, IRubyObject emitter) { ((RubyObject)self).fastSetInstanceVariable("@emitter", emitter); return self; } // syck_out_map @JRubyMethod(required = 1, optional = 1, frame = true) public static IRubyObject map(IRubyObject self, IRubyObject[] args, Block block) { Ruby runtime = self.getRuntime(); ThreadContext ctx = runtime.getCurrentContext(); IRubyObject type_id = args[0]; IRubyObject style = args.length == 1 ? runtime.getNil() : args[1]; IRubyObject map = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Map").callMethod(ctx, "new", new IRubyObject[]{type_id, RubyHash.newHash(runtime), style}); outMark((IRubyObject)((RubyObject)self).fastGetInstanceVariable("@emitter"), map); block.yield(ctx, map); return map; } // syck_out_seq @JRubyMethod(required = 1, optional = 1, frame = true) public static IRubyObject seq(IRubyObject self, IRubyObject[] args, Block block) { Ruby runtime = self.getRuntime(); ThreadContext ctx = runtime.getCurrentContext(); IRubyObject type_id = args[0]; IRubyObject style = args.length == 1 ? runtime.getNil() : args[1]; IRubyObject seq = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Seq").callMethod(ctx, "new", new IRubyObject[]{type_id, RubyArray.newArray(runtime), style}); outMark((IRubyObject)((RubyObject)self).fastGetInstanceVariable("@emitter"), seq); block.yield(ctx, seq); return seq; } // syck_out_scalar @JRubyMethod(required = 2, optional = 1, frame = true) public static IRubyObject scalar(IRubyObject self, IRubyObject[] args, Block block) { Ruby runtime = self.getRuntime(); ThreadContext ctx = runtime.getCurrentContext(); IRubyObject type_id = args[0]; IRubyObject str = args[1]; IRubyObject style = args.length == 2 ? runtime.getNil() : args[2]; IRubyObject scalar = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Scalar").callMethod(ctx, "new", new IRubyObject[]{type_id, str, style}); outMark((IRubyObject)((RubyObject)self).fastGetInstanceVariable("@emitter"), scalar); return scalar; } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/PossibleLinkNode.java000066400000000000000000000003711262256356000260350ustar00rootroot00000000000000package org.yecht.ruby; import java.util.List; import org.jruby.runtime.builtin.IRubyObject; public interface PossibleLinkNode { List getLinks(); void addLink(StorageLink link); void replaceLinks(IRubyObject newObject); } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/PrivateType.java000066400000000000000000000007431262256356000251100ustar00rootroot00000000000000package org.yecht.ruby; import org.jruby.RubyObject; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.builtin.IRubyObject; public class PrivateType { // syck_privatetype_initialize @JRubyMethod public static IRubyObject initialize(IRubyObject self, IRubyObject type_id, IRubyObject val) { ((RubyObject)self).fastSetInstanceVariable("@type_id", type_id); ((RubyObject)self).fastSetInstanceVariable("@value", val); return self; } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/Resolver.java000066400000000000000000000305021262256356000244310ustar00rootroot00000000000000package org.yecht.ruby; import java.util.List; import org.yecht.Data; import org.yecht.ImplicitScanner; import org.yecht.MapPart; import org.jruby.Ruby; import org.jruby.RubyArray; import org.jruby.RubyClass; import org.jruby.RubyEnumerable; import org.jruby.RubyHash; import org.jruby.RubyModule; import org.jruby.RubyNumeric; import org.jruby.RubyObject; import org.jruby.RubyString; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.Block; import org.jruby.runtime.BlockCallback; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.util.TypeConverter; public class Resolver { // syck_const_find public static IRubyObject const_find(IRubyObject self, IRubyObject const_name) { RubyModule tclass = self.getRuntime().getObject(); RubyArray tparts = ((RubyString)const_name).split(self.getRuntime().getCurrentContext(), self.getRuntime().newString("::")); for(int i=0; i < tparts.getLength(); i++) { String tpart = tparts.entry(i).toString(); try { tclass = (RubyModule)tclass.getConstant(tpart); } catch(Exception e) { return self.getRuntime().getNil(); } } return tclass; } // syck_resolver_initialize @JRubyMethod public static IRubyObject initialize(IRubyObject self) { ((RubyObject)self).fastSetInstanceVariable("@tags", RubyHash.newHash(self.getRuntime())); return self; } // syck_resolver_add_type @JRubyMethod public static IRubyObject add_type(IRubyObject self, IRubyObject taguri, IRubyObject cls) { IRubyObject tags = self.callMethod(self.getRuntime().getCurrentContext(), "tags"); ((RubyHash)tags).fastASet(taguri, cls); return self.getRuntime().getNil(); } // syck_resolver_use_types_at @JRubyMethod public static IRubyObject use_types_at(IRubyObject self, IRubyObject hsh) { ((RubyObject)self).fastSetInstanceVariable("@tags", hsh); return self.getRuntime().getNil(); } // syck_resolver_detect_implicit @JRubyMethod public static IRubyObject detect_implicit(IRubyObject self, IRubyObject val) { return RubyString.newEmptyString(self.getRuntime()); } // syck_resolver_transfer @JRubyMethod public static IRubyObject transfer(IRubyObject self, IRubyObject type, IRubyObject val) { final Ruby runtime = self.getRuntime(); ThreadContext ctx = runtime.getCurrentContext(); if(type.isNil() || type.convertToString().getByteList().realSize == 0) { type = self.callMethod(ctx, "detect_implicit", val); } if(!(type.isNil() || type.convertToString().getByteList().realSize == 0)) { IRubyObject colon = runtime.newString(":"); IRubyObject tags = self.callMethod(ctx, "tags"); IRubyObject target_class = ((RubyHash)tags).op_aref(ctx, type); IRubyObject subclass = target_class; IRubyObject obj = runtime.getNil(); if(target_class.isNil()) { RubyArray subclass_parts = runtime.newArray(); RubyArray parts = ((RubyString)type).split(ctx, colon); while(parts.getLength() > 1) { subclass_parts.unshift(parts.pop(ctx)); IRubyObject partial = parts.join(ctx, colon); target_class = ((RubyHash)tags).op_aref(ctx, partial); if(target_class.isNil()) { ((RubyString)partial).append(colon); target_class = ((RubyHash)tags).op_aref(ctx, partial); } if(!target_class.isNil()) { subclass = target_class; if(subclass_parts.getLength() > 0 && target_class.respondsTo("yaml_tag_subclasses?") && target_class.callMethod(ctx, "yaml_tag_subclasses?").isTrue()) { subclass = subclass_parts.join(ctx, colon); subclass = target_class.callMethod(ctx, "yaml_tag_read_class", subclass); IRubyObject subclass_v = const_find(self, subclass); if(subclass_v != runtime.getNil()) { subclass = subclass_v; } else if(target_class == runtime.getObject() && subclass_v == runtime.getNil()) { target_class = ((RubyModule)runtime.getModule("YAML")).getConstant("Object"); type = subclass; subclass = target_class; } else { throw runtime.newTypeError("invalid subclass"); } } break; } } } if(target_class.respondsTo("call")) { obj = target_class.callMethod(ctx, "call", new IRubyObject[]{type, val}); } else { if(target_class.respondsTo("yaml_new")) { obj = target_class.callMethod(ctx, "yaml_new", new IRubyObject[]{subclass, type, val}); } else if(!target_class.isNil()) { if(subclass == runtime.getBignum()) { obj = RubyNumeric.str2inum(runtime, val.convertToString(), 10); } else { obj = ((RubyClass)subclass).allocate(); } if(obj.respondsTo("yaml_initialize")) { obj.callMethod(ctx, "yaml_initialize", new IRubyObject[]{type, val}); } else if(!obj.isNil() && val instanceof RubyHash) { final IRubyObject _obj = obj; final IRubyObject _val = val; RubyEnumerable.callEach(runtime, ctx, val, new BlockCallback() { public IRubyObject call(ThreadContext _ctx, IRubyObject[] largs, Block blk) { IRubyObject ivname = ((RubyArray)largs[0]).entry(0); String ivn = "@" + ivname.convertToString().toString(); IRubyObject valueToSet = ((RubyArray)largs[0]).entry(1); if(valueToSet instanceof PossibleLinkNode) { List sls = ((PossibleLinkNode)valueToSet).getLinks(); for(int i=0, j=sls.size(); i " + obj); if(n.id != null && !obj.isNil()) { if(n.id instanceof PossibleLinkNode) { ((PossibleLinkNode)n.id).replaceLinks(obj); } n.id = obj; // System.err.println(" -- LoadHandler, setting id, yay!"); } if(bonus.taint) { ((RubyObject)obj).taint(runtime.getCurrentContext()); } if(bonus.proc != null) { bonus.proc.callMethod(runtime.getCurrentContext(), "call", obj); } ((RubyHash)bonus.data).fastASet(((RubyHash)bonus.data).rb_size(), obj); // System.err.println(" -> rb_syck_load_handler=" + n.id); return obj; } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/RubyOutputHandler.java000066400000000000000000000015541262256356000262750ustar00rootroot00000000000000package org.yecht.ruby; import org.yecht.Emitter; import org.yecht.OutputHandler; import org.jruby.Ruby; import org.jruby.RubyString; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.util.ByteList; public class RubyOutputHandler implements OutputHandler { private Ruby runtime; public RubyOutputHandler(Ruby runtime) { this.runtime = runtime; } // rb_syck_output_handler public void handle(Emitter emitter, byte[] str, int len) { YEmitter.Extra bonus = (YEmitter.Extra)emitter.bonus; IRubyObject dest = bonus.port; if(dest instanceof RubyString) { ((RubyString)dest).cat(new ByteList(str, 0, len, false)); } else { dest.callMethod(runtime.getCurrentContext(), "write", RubyString.newStringShared(runtime, str, 0, len)); } } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/Scalar.java000066400000000000000000000062001262256356000240330ustar00rootroot00000000000000package org.yecht.ruby; import org.yecht.Data; import org.yecht.Pointer; import org.yecht.ScalarStyle; import org.jruby.Ruby; import org.jruby.RubyClass; import org.jruby.RubyObject; import org.jruby.RubyString; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.ObjectAllocator; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.util.ByteList; public class Scalar { public static final ObjectAllocator Allocator = new ObjectAllocator() { // syck_scalar_alloc public IRubyObject allocate(Ruby runtime, RubyClass klass) { // System.err.println("ALLOCATING SCALAR"); org.yecht.Node node = org.yecht.Node.allocStr(); IRubyObject obj = new Node(runtime, klass, node, (YAMLExtra)runtime.getModule("YAML").dataGetStruct()); node.id = obj; // System.err.println("syck_scalar_alloc() -> setting id: " + node.id); return obj; } }; // syck_scalar_initialize @JRubyMethod public static IRubyObject initialize(IRubyObject self, IRubyObject type_id, IRubyObject val, IRubyObject style) { Ruby runtime = self.getRuntime(); ThreadContext ctx = runtime.getCurrentContext(); ((RubyObject)self).fastSetInstanceVariable("@kind", ((Node)self).x.scalar); self.callMethod(ctx, "type_id=", type_id); self.callMethod(ctx, "value=", val); self.callMethod(ctx, "style=", style); return self; } // syck_scalar_style_set @JRubyMethod(name = "style=") public static IRubyObject style_set(IRubyObject self, IRubyObject style) { YAMLExtra x = ((Node)self).x; Ruby runtime = self.getRuntime(); Data.Str ds = (Data.Str)((org.yecht.Node)self.dataGetStructChecked()).data; if(style.isNil()) { ds.style = ScalarStyle.None; } else if(style == x.quote1) { ds.style = ScalarStyle.OneQuote; } else if(style == x.quote2) { ds.style = ScalarStyle.TwoQuote; } else if(style == x.fold) { ds.style = ScalarStyle.Fold; } else if(style == x.literal) { ds.style = ScalarStyle.Literal; } else if(style == x.plain) { ds.style = ScalarStyle.Plain; } ((RubyObject)self).fastSetInstanceVariable("@style", style); return self; } // syck_scalar_value_set @JRubyMethod(name = "value=") public static IRubyObject value_set(IRubyObject self, IRubyObject val) { org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked(); Ruby runtime = self.getRuntime(); Data.Str ds = (Data.Str)node.data; val = val.convertToString(); ByteList bl = ((RubyString)val).getByteList(); byte[] bss = new byte[bl.realSize]; System.arraycopy(bl.bytes, bl.begin, bss, 0, bss.length); ds.ptr = Pointer.create(bss, 0); ds.len = bss.length; ds.style = ScalarStyle.None; ((RubyObject)self).fastSetInstanceVariable("@value", val); return val; } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/Seq.java000066400000000000000000000063351262256356000233670ustar00rootroot00000000000000package org.yecht.ruby; import org.yecht.Data; import org.yecht.SeqStyle; import org.jruby.Ruby; import org.jruby.RubyArray; import org.jruby.RubyClass; import org.jruby.RubyHash; import org.jruby.RubyObject; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.ObjectAllocator; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; public class Seq { public static final ObjectAllocator Allocator = new ObjectAllocator() { // syck_seq_alloc public IRubyObject allocate(Ruby runtime, RubyClass klass) { // System.err.println("ALLOCATING SEQ"); org.yecht.Node node = org.yecht.Node.allocSeq(); IRubyObject obj = new Node(runtime, klass, node, (YAMLExtra)runtime.getModule("YAML").dataGetStruct()); node.id = obj; // System.err.println("syck_seq_alloc() -> setting id"); return obj; } }; // syck_seq_initialize @JRubyMethod public static IRubyObject initialize(IRubyObject self, IRubyObject type_id, IRubyObject val, IRubyObject style) { Ruby runtime = self.getRuntime(); ThreadContext ctx = runtime.getCurrentContext(); ((RubyObject)self).fastSetInstanceVariable("@kind", ((Node)self).x.seq); self.callMethod(ctx, "type_id=", type_id); self.callMethod(ctx, "value=", val); self.callMethod(ctx, "style=", style); return self; } // syck_seq_value_set @JRubyMethod(name = "value=") public static IRubyObject value_set(IRubyObject self, IRubyObject val) { org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked(); Ruby runtime = self.getRuntime(); val = val.checkArrayType(); if(!val.isNil()) { node.seqEmpty(); Data.Seq ds = (Data.Seq)node.data; for(int i=0; i<((RubyArray)val).getLength(); i++) { node.seqAdd(((RubyArray)val).entry(i)); } } ((RubyObject)self).fastSetInstanceVariable("@value", val); return val; } // syck_seq_style_set @JRubyMethod(name = "style=") public static IRubyObject style_set(IRubyObject self, IRubyObject style) { org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked(); Ruby runtime = self.getRuntime(); Data.Seq ds = (Data.Seq)node.data; if(style == runtime.newSymbol("inline")) { ds.style = SeqStyle.Inline; } else { ds.style = SeqStyle.None; } ((RubyObject)self).fastSetInstanceVariable("@style", style); return self; } // syck_seq_add_m @JRubyMethod public static IRubyObject add(IRubyObject self, IRubyObject val) { IRubyObject emitter = (IRubyObject)((RubyObject)self).fastGetInstanceVariable("@emitter"); org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked(); if(emitter.respondsTo("node_export")) { val = emitter.callMethod(self.getRuntime().getCurrentContext(), "node_export", val); } node.seqAdd(val); ((RubyArray)((RubyObject)self).fastGetInstanceVariable("@value")).append(val); return self; } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/StorageLink.java000066400000000000000000000002451262256356000250530ustar00rootroot00000000000000package org.yecht.ruby; import org.jruby.runtime.builtin.IRubyObject; abstract class StorageLink { public abstract void replaceLinkWith(IRubyObject object); } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/YAMLExtra.java000066400000000000000000000061571262256356000244070ustar00rootroot00000000000000package org.yecht.ruby; import org.jruby.Ruby; import org.jruby.RubyClass; import org.jruby.RubyModule; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.runtime.CallSite; import org.jruby.runtime.MethodIndex; public class YAMLExtra { public IRubyObject quote1; public IRubyObject quote2; public IRubyObject fold; public IRubyObject literal; public IRubyObject plain; public IRubyObject map; public IRubyObject seq; public IRubyObject scalar; public IRubyObject inline; public RubyClass Scalar; public RubyClass Seq; public RubyClass Map; public IRubyObject DefaultResolver; public RubyClass Node; public RubyClass MergeKey; public RubyClass DefaultKey; public final CallSite type_id_set_ScalarAdapter = MethodIndex.getFunctionalCallSite("type_id="); public final CallSite value_set_ScalarAdapter = MethodIndex.getFunctionalCallSite("value="); public final CallSite style_set_ScalarAdapter = MethodIndex.getFunctionalCallSite("style="); public final CallSite type_id_set_MapAdapter = MethodIndex.getFunctionalCallSite("type_id="); public final CallSite value_set_MapAdapter = MethodIndex.getFunctionalCallSite("value="); public final CallSite style_set_MapAdapter = MethodIndex.getFunctionalCallSite("style="); public final CallSite type_id_set_SeqAdapter = MethodIndex.getFunctionalCallSite("type_id="); public final CallSite value_set_SeqAdapter = MethodIndex.getFunctionalCallSite("value="); public final CallSite style_set_SeqAdapter = MethodIndex.getFunctionalCallSite("style="); public final CallSite node_export_EmitterAdapter = MethodIndex.getFunctionalCallSite("node_export"); public final CallSite keys_HashAdapter = MethodIndex.getFunctionalCallSite("keys"); public Ruby runtime; public YAMLExtra(Ruby runtime) { quote1 = runtime.newSymbol("quote1"); quote2 = runtime.newSymbol("quote2"); fold = runtime.newSymbol("fold"); literal = runtime.newSymbol("literal"); plain = runtime.newSymbol("plain"); map = runtime.newSymbol("map"); seq = runtime.newSymbol("seq"); scalar = runtime.newSymbol("scalar"); inline = runtime.newSymbol("inline"); Scalar = (RubyClass)((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Scalar"); Seq = (RubyClass)((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Seq"); Map = (RubyClass)((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Map"); DefaultResolver = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("DefaultResolver"); Node = (RubyClass)((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Node"); MergeKey = (RubyClass)((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("MergeKey"); DefaultKey = (RubyClass)((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("DefaultKey"); this.runtime = runtime; } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/YEmitter.java000066400000000000000000000111111262256356000243650ustar00rootroot00000000000000package org.yecht.ruby; import org.yecht.Emitter; import org.jruby.Ruby; import org.jruby.RubyClass; import org.jruby.RubyHash; import org.jruby.RubyModule; import org.jruby.RubyNumeric; import org.jruby.RubyObject; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.Block; import org.jruby.runtime.BlockCallback; import org.jruby.runtime.ObjectAllocator; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.util.TypeConverter; public class YEmitter { public static class Extra { public IRubyObject oid; public IRubyObject data; public IRubyObject port; } public static final ObjectAllocator Allocator = new ObjectAllocator() { // syck_emitter_s_alloc public IRubyObject allocate(Ruby runtime, RubyClass klass) { // System.err.println("ALLOCATING EMITTER"); Emitter emitter = new Emitter(); emitter.bonus = new Extra(); IRubyObject pobj = runtime.newData(klass, emitter); emitter.handler(new RubyEmitterHandler(runtime)); emitter.outputHandler(new RubyOutputHandler(runtime)); ((RubyObject)pobj).fastSetInstanceVariable("@out", ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Out").callMethod(runtime.getCurrentContext(), "new", pobj)); return pobj; } }; // syck_emitter_set_resolver @JRubyMethod public static IRubyObject set_resolver(IRubyObject self, IRubyObject resolver) { ((RubyObject)self).fastSetInstanceVariable("@resolver", resolver); return self; } // syck_emitter_node_export @JRubyMethod public static IRubyObject node_export(IRubyObject self, IRubyObject node) { return node.callMethod(self.getRuntime().getCurrentContext(), "to_yaml", self); } // syck_emitter_reset @JRubyMethod(name = {"initialize", "reset"}, optional = 1) public static IRubyObject reset(IRubyObject self, IRubyObject[] args) { Ruby runtime = self.getRuntime(); ThreadContext ctx = runtime.getCurrentContext(); Emitter emitter = (Emitter)self.dataGetStructChecked(); Extra bonus = (Extra)emitter.bonus; bonus.oid = runtime.getNil(); bonus.port = runtime.newString(""); bonus.data = RubyHash.newHash(runtime); IRubyObject options = null; IRubyObject tmp; if(args.length == 1) { options = args[0]; if(!(tmp = options.checkStringType()).isNil()) { bonus.port = tmp; } else if(options.respondsTo("write")) { bonus.port = options; } else { options = TypeConverter.convertToTypeWithCheck(options, runtime.getHash(), "to_hash"); ((RubyObject)self).fastSetInstanceVariable("@options", options); } } else { options = RubyHash.newHash(runtime); ((RubyObject)self).fastSetInstanceVariable("@options", options); } emitter.headless = false; ((RubyObject)self).fastSetInstanceVariable("@level", runtime.newFixnum(0)); ((RubyObject)self).fastSetInstanceVariable("@resolver", runtime.getNil()); return self; } // syck_emitter_emit @JRubyMethod(optional = 1, frame = true) public static IRubyObject emit(IRubyObject self, IRubyObject[] _oid, Block proc) { Ruby runtime = self.getRuntime(); int level = RubyNumeric.fix2int((IRubyObject)((RubyObject)self).fastGetInstanceVariable("@level")) + 1; ((RubyObject)self).fastSetInstanceVariable("@level", runtime.newFixnum(level)); ThreadContext ctx = runtime.getCurrentContext(); Emitter emitter = (Emitter)self.dataGetStructChecked(); Extra bonus = (Extra)emitter.bonus; IRubyObject oid = _oid.length == 0 ? runtime.getNil() : _oid[0]; bonus.oid = oid; IRubyObject symple; if(!oid.isNil() && bonus.data.callMethod(ctx, "has_key?", oid).isTrue()) { symple = ((RubyHash)bonus.data).op_aref(ctx, oid); } else { symple = proc.yield(ctx, (IRubyObject)((RubyObject)self).fastGetInstanceVariable("@out")); } emitter.markNode(symple); level--; ((RubyObject)self).fastSetInstanceVariable("@level", runtime.newFixnum(level)); if(level == 0) { emitter.emit(symple); emitter.flush(0); return bonus.port; } return symple; } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/YObject.java000066400000000000000000000014271262256356000241730ustar00rootroot00000000000000package org.yecht.ruby; import org.jruby.RubyObject; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.builtin.IRubyObject; public class YObject { // syck_yobject_initialize @JRubyMethod public static IRubyObject initialize(IRubyObject self, IRubyObject klass, IRubyObject ivars) { ((RubyObject)self).fastSetInstanceVariable("@class", klass); ((RubyObject)self).fastSetInstanceVariable("@ivars", ivars); return self; } // syck_yobject_initialize @JRubyMethod public static IRubyObject yaml_initialize(IRubyObject self, IRubyObject klass, IRubyObject ivars) { ((RubyObject)self).fastSetInstanceVariable("@class", klass); ((RubyObject)self).fastSetInstanceVariable("@ivars", ivars); return self; } } yecht-yecht-1.1/ext/ruby/src/java/org/yecht/ruby/YParser.java000066400000000000000000000162771262256356000242320ustar00rootroot00000000000000package org.yecht.ruby; import org.yecht.Parser; import org.yecht.ParserInput; import org.yecht.Pointer; import org.jruby.Ruby; import org.jruby.RubyClass; import org.jruby.RubyHash; import org.jruby.RubyModule; import org.jruby.RubyNumeric; import org.jruby.RubyObject; import org.jruby.RubyString; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.Block; import org.jruby.runtime.BlockCallback; import org.jruby.runtime.ObjectAllocator; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.util.ByteList; public class YParser { public static class Extra { public IRubyObject data; public IRubyObject proc; public IRubyObject resolver; public boolean taint; } public static final ObjectAllocator Allocator = new ObjectAllocator() { // syck_parser_s_alloc public IRubyObject allocate(Ruby runtime, RubyClass klass) { // System.err.println("ALLOCATING PARSER"); Parser parser = Parser.newParser(); parser.bonus = new Extra(); IRubyObject pobj = runtime.newData(klass, parser); parser.setRootOnError(runtime.getNil()); return pobj; } }; // syck_parser_assign_io public static boolean assignIO(Ruby runtime, Parser parser, IRubyObject[] pport) { boolean taint = true; IRubyObject tmp, port = pport[0]; if(!(tmp = port.checkStringType()).isNil()) { taint = port.isTaint(); port = tmp; ByteList bl = ((RubyString)port).getByteList(); parser.str(Pointer.create(bl.bytes, bl.begin), bl.realSize, null); } else if(port.respondsTo("read")) { if(port.respondsTo("binmode")) { port.callMethod(runtime.getCurrentContext(), "binmode"); } parser.str(Pointer.empty(), 0, new RubyIoStrRead(port)); } else { throw runtime.newTypeError("instance of IO needed"); } pport[0] = port; return taint; } // syck_set_model public static void setModel(IRubyObject p, IRubyObject input, IRubyObject model) { Ruby runtime = p.getRuntime(); Parser parser = (Parser)p.dataGetStructChecked(); parser.handler(new RubyLoadHandler(runtime, ((YAMLExtra)runtime.getModule("YAML").dataGetStruct()))); if(model == runtime.newSymbol("Generic")) { p.callMethod(runtime.getCurrentContext(), "set_resolver", ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("GenericResolver")); } parser.implicitTyping(true); parser.taguriExpansion(true); if(input.isNil()) { input = (IRubyObject)((RubyObject)p).fastGetInstanceVariable("@input"); } if(input == runtime.newSymbol("bytecode")) { parser.setInputType(ParserInput.Bytecode_UTF8); } else { parser.setInputType(ParserInput.YAML_UTF8); } parser.errorHandler(new RubyErrHandler(runtime)); parser.badAnchorHandler(new RubyBadAnchorHandler(runtime)); } @JRubyMethod(optional = 1) public static IRubyObject initialize(IRubyObject self, IRubyObject[] args) { IRubyObject options = null; if(args.length == 0) { options = RubyHash.newHash(self.getRuntime()); } else { options = args[0].convertToHash(); } ((RubyObject)self).fastSetInstanceVariable("@options", options); ((RubyObject)self).fastSetInstanceVariable("@input", self.getRuntime().getNil()); ((RubyObject)self).fastSetInstanceVariable("@resolver", self.getRuntime().getNil()); return self; } // syck_parser_bufsize_set @JRubyMethod(name="bufsize=") public static IRubyObject bufsize_set(IRubyObject self, IRubyObject size) { if(size.respondsTo("to_i")) { int n = RubyNumeric.fix2int(size.callMethod(self.getRuntime().getCurrentContext(), "to_i")); Parser p = (Parser)self.dataGetStructChecked(); p.bufsize = n; } return self; } // syck_parser_bufsize_get @JRubyMethod public static IRubyObject bufsize(IRubyObject self) { Parser p = (Parser)self.dataGetStructChecked(); return self.getRuntime().newFixnum(p.bufsize); } // syck_parser_load @JRubyMethod(required = 1, optional = 1) public static IRubyObject load(IRubyObject self, IRubyObject[] args) { Ruby runtime = self.getRuntime(); ThreadContext ctx = runtime.getCurrentContext(); IRubyObject port = args[0]; IRubyObject proc = null; if(args.length > 1) { proc = args[1]; } else { proc = runtime.getNil(); } IRubyObject input = ((RubyHash)self.callMethod(ctx, "options")).op_aref(ctx, runtime.newSymbol("input")); IRubyObject model = ((RubyHash)self.callMethod(ctx, "options")).op_aref(ctx, runtime.newSymbol("Model")); Parser parser = (Parser)self.dataGetStructChecked(); setModel(self, input, model); Extra bonus = (Extra)parser.bonus; bonus.taint = assignIO(runtime, parser, new IRubyObject[]{port}); parser.setRootOnError(runtime.getNil()); bonus.data = RubyHash.newHash(runtime); bonus.resolver = self.callMethod(ctx, "resolver"); // System.err.println("Parser resolver is : " + bonus.resolver); if(proc.isNil()) { bonus.proc = null; } else { bonus.proc = proc; } IRubyObject result = (IRubyObject)parser.parse(); if(result == null) { result = runtime.getFalse(); } return result; } // syck_parser_load_documents @JRubyMethod(frame=true) public static IRubyObject load_documents(IRubyObject self, IRubyObject port, Block proc) { Ruby runtime = self.getRuntime(); ThreadContext ctx = runtime.getCurrentContext(); IRubyObject input = ((RubyHash)self.callMethod(ctx, "options")).op_aref(ctx, runtime.newSymbol("input")); IRubyObject model = ((RubyHash)self.callMethod(ctx, "options")).op_aref(ctx, runtime.newSymbol("Model")); Parser parser = (Parser)self.dataGetStructChecked(); setModel(self, input, model); Extra bonus = (Extra)parser.bonus; bonus.taint = assignIO(runtime, parser, new IRubyObject[]{port}); parser.setRootOnError(runtime.getNil()); bonus.resolver = self.callMethod(ctx, "resolver"); bonus.proc = null; while(true) { bonus.data = RubyHash.newHash(runtime); IRubyObject v = (IRubyObject)parser.parse(); if(parser.eof) { return runtime.getNil(); } if(v == null) { v = runtime.getFalse(); } proc.yield(ctx, v); } } // syck_parser_set_resolver @JRubyMethod public static IRubyObject set_resolver(IRubyObject self, IRubyObject resolver) { ((RubyObject)self).fastSetInstanceVariable("@resolver", resolver); return self; } } yecht-yecht-1.1/ext/ruby/tests/000077500000000000000000000000001262256356000165335ustar00rootroot00000000000000yecht-yecht-1.1/ext/ruby/tests/basic.rb000066400000000000000000001367111262256356000201520ustar00rootroot00000000000000# vim:sw=4:ts=4 # $Id$ # require 'runit/testcase' require 'runit/cui/testrunner' require 'yaml' # [ruby-core:01946] module YAML_Tests StructTest = Struct::new( :c ) end class YAML_Unit_Tests < RUNIT::TestCase # # Convert between YAML and the object to verify correct parsing and # emitting # def assert_to_yaml( obj, yaml ) assert_equal( obj, YAML::load( yaml ) ) assert_equal( obj, YAML::parse( yaml ).transform ) assert_equal( obj, YAML::load( obj.to_yaml ) ) assert_equal( obj, YAML::parse( obj.to_yaml ).transform ) assert_equal( obj, YAML::load( obj.to_yaml( :UseVersion => true, :UseHeader => true, :SortKeys => true ) ) ) # yb = YAML::Parser.new # yb.resolver = YAML.resolver # yb.input = :bytecode # assert_equal( obj, yb.load( YAML::Yecht::compile( yaml ) ) ) end # # Test bytecode parser # def assert_bytecode( obj, yaml ) yp = YAML::Parser.new yp.input = :bytecode assert_equal( obj, yp.load( yaml ) ) end # # Test parser only # def assert_parse_only( obj, yaml ) assert_equal( obj, YAML::load( yaml ) ) assert_equal( obj, YAML::parse( yaml ).transform ) yp = YAML::Parser.new yp.input = :bytecode assert_equal( obj, yp.load( YAML::Yecht::compile( yaml ) ) ) end def assert_path_segments( path, segments ) YAML::YPath.each_path( path ) { |choice| assert_equal( choice.segments, segments.shift ) } assert_equal( segments.length, 0, "Some segments leftover: #{ segments.inspect }" ) end # # Make a time with the time zone # def mktime( year, mon, day, hour, min, sec, usec, zone = "Z" ) usec = usec.to_s.to_f * 1000000 val = Time::utc( year.to_i, mon.to_i, day.to_i, hour.to_i, min.to_i, sec.to_i, usec ) if zone != "Z" hour = zone[0,3].to_i * 3600 min = zone[3,2].to_i * 60 ofs = (hour + min) val = Time.at( val.to_f - ofs ) end return val end # # Tests modified from 00basic.t in YAML.pm # def test_basic_map # Simple map map = { 'one' => 'foo', 'three' => 'baz', 'two' => 'bar' } assert_to_yaml( map, < 'simple string', 2 => 42, 3 => '1 Single Quoted String', 4 => 'YAML\'s Double "Quoted" String', 5 => "A block\n with several\n lines.\n", 6 => "A \"chomped\" block", 7 => "A folded\n string\n" } assert_to_yaml( basic, < A folded string EOY ) assert_bytecode( basic, "D\nM\nS1\nSsimple string\nS2\nS42\nS3\nS1 Single Quoted String\nS4\nSYAML's Double \"Quoted\" String\n" + "S5\nSA block\nN\nC with several\nN\nC lines.\nN\nS6\nSA \"chomped\" block\nS7\nSA folded\nN\nC string\nN\nE\n" ) end # # Test the specification examples # - Many examples have been changes because of whitespace problems that # caused the two to be inequivalent, or keys to be sorted wrong # def test_spec_simple_implicit_sequence # Simple implicit sequence seq = [ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ] assert_to_yaml( seq, < 65, 'avg' => 0.278, 'rbi' => 147 } assert_to_yaml( map, < [ 'Boston Red Sox', 'Detroit Tigers', 'New York Yankees' ], 'national' => [ 'New York Mets', 'Chicago Cubs', 'Atlanta Braves' ] } assert_to_yaml( nest, < 'Mark McGwire', 'hr' => 65, 'avg' => 0.278}, {'name' => 'Sammy Sosa', 'hr' => 63, 'avg' => 0.288} ] assert_to_yaml( nest, < { 'hr' => 65, 'avg' => 0.278 }, 'Sammy Sosa' => { 'hr' => 63, 'avg' => 0.288 } } assert_to_yaml( map, < [ 'Mark McGwire', 'Sammy Sosa' ], 'rbi' => [ 'Sammy Sosa', 'Ken Griffey' ] } assert_to_yaml( nest, < [ 'Mark McGwire', 'Sammy Sosa' ], 'rbi' => [ 'Sammy Sosa', 'Ken Griffey' ] } assert_to_yaml( anc1, <"EDI", "departure"=>"LAX", "fareref"=>"DOGMA", "currency"=>"GBP"}, {"arrival"=>"MEL", "departure"=>"SYD", "fareref"=>"MADF", "currency"=>"AUD"}, {"arrival"=>"MCO", "departure"=>"JFK", "fareref"=>"DFSF", "currency"=>"USD"}] assert_to_yaml( anc2, <["fareref", "currency", "departure", "arrival"], "FARES"=>[{"arrival"=>"EDI", "departure"=>"LAX", "fareref"=>"DOGMA", "currency"=>"GBP"}, {"arrival"=>"MEL", "departure"=>"SYD", "fareref"=>"MADF", "currency"=>"AUD"}, {"arrival"=>"MCO", "departure"=>"JFK", "fareref"=>"DFSF", "currency"=>"USD"}]} assert_to_yaml( anc3, < [ Date.new( 2001, 7, 23 ) ], [ 'New York Yankees', 'Atlanta Braves' ] => [ Date.new( 2001, 7, 2 ), Date.new( 2001, 8, 12 ), Date.new( 2001, 8, 14 ) ] } assert_to_yaml( complex, < [ Date.new( 2001, 7, 2 ), Date.new( 2001, 8, 12 ), Date.new( 2001, 8, 14 ) ], [ 'Detroit Tigers', 'Chicago Cubs' ] => [ Date.new( 2001, 7, 23 ) ] }, < 34843, 'date' => Date.new( 2001, 1, 23 ), 'bill-to' => 'Chris Dumars', 'product' => [ { 'item' => 'Super Hoop', 'quantity' => 1 }, { 'item' => 'Basketball', 'quantity' => 4 }, { 'item' => 'Big Shoes', 'quantity' => 1 } ] } assert_to_yaml( seq, < nil }, [ { 'five' => [ 'six' ] } ], [ 'seven' ] ], [ 'eight', 'nine' ] ] assert_to_yaml( seq, < Mark McGwire's year was crippled by a knee injury. EOY # Force a few elaborate folded blocks assert_to_yaml( [ < ruby -ropen-uri -e 'eval(open("http://go.hobix.com/").read)' STR1 Ok, so the idea here is that one whole weblahhg is contained in a single directory. What is stored in the directory?
  hobix.yaml <- configuration

  entries/   <- edit and organize
                your news items,
                articles and so on.

  skel/      <- contains your
                templates

  htdocs/    <- html is created here,
                store all your images here,
                this is your viewable
                websyht

  lib/       <- extra hobix libraries
                (plugins) go here
One weblahhg can be shared with many authors. In the @hobix.yaml@ file, you can store information about each author, as well as information about others who contribute to your websyht. You also have a file of your own, a configuration file called @.hobixrc@, which contains a list of the weblahhgs you belong to. h2. Pull One From the Sky If you would like to create your own weblahhg from scratch:
  hobix create blahhg
You will be prompted for a full path where the new weblahhg can be created. Don't worry if the directory doesn't yet exist, Hobix will take care of clearing a path for it. Once you give it the path, Hobix will create all the necessary directories, as well as the @hobix.yaml@. You should also have a set of sample templates to get you started. In fact, if you want to generate the default site:
  hobix regen blahhg
h2. Joining Hands With Others To join an existing weblahhg:
  hobix add other-blahhg /path/to/other-blahhg/hobix.yaml
You don't need to be on a weblahhg's author list to join the weblahhg. You just need permissions to edit the file. h2. Leaving in a Cloud of Keystrokes To remove a weblahhg from your configuration:
  hobix del other-blahhg
Please don't be afraid to edit your configuration file yourself, should the commandline not suit your style. See, here's my @.hobixrc@:
  --- 
  weblogs: 
    hobix: /usr/local/www/hobix.com/www/hobix.yaml
    why: /usr/local/www/whytheluckystiff.net/www/hobix.yaml
  username: why
  use editor: true
That's a YAML file. Very simple to edit. You can manually edit your information, safely add or edit your weblogs, and save back to your @.hobixrc@. Enough then. Time to trick out your new Hoblahhg. You will be guided through an automatic installation (or upgrade) of Hobix. STR2 NOW BUNKING together: the ruby and yaml scripts up at http://go.hobix.com/. Hey ,, the life and unity we feel is tree-mending-US!! Try:
  ruby -ropen-uri -e'eval open("http://go.hobix.com/").read'
No longer are curtains dropping ON the actors' arms !! No longer are swift currents ON the actors' legs !! The actors have a bottomless cereal container, witness. STR3 --- - |+ Here's what you're going to need: * Ruby 1.8.0 or higher. ** Linux/FreeBSD: "Get the latest, please.":http://ruby-lang.org/en/20020102.html ** Windows: "Installer for Windows.":http://rubyinstaller.sourceforge.net/ ** Mac: "OSX disk image.":http://homepage.mac.com/discord/Ruby/ * Once Ruby is installed, open a command prompt and type:
    ruby -ropen-uri -e 'eval(open("http://go.hobix.com/").read)'
  
- | Ok, so the idea here is that one whole weblahhg is contained in a single directory. What is stored in the directory?
    hobix.yaml <- configuration

    entries/   <- edit and organize
                  your news items,
                  articles and so on.

    skel/      <- contains your
                  templates

    htdocs/    <- html is created here,
                  store all your images here,
                  this is your viewable
                  websyht

    lib/       <- extra hobix libraries
                  (plugins) go here
  
One weblahhg can be shared with many authors. In the @hobix.yaml@ file, you can store information about each author, as well as information about others who contribute to your websyht. You also have a file of your own, a configuration file called @.hobixrc@, which contains a list of the weblahhgs you belong to. h2. Pull One From the Sky If you would like to create your own weblahhg from scratch:
    hobix create blahhg
  
You will be prompted for a full path where the new weblahhg can be created. Don't worry if the directory doesn't yet exist, Hobix will take care of clearing a path for it. Once you give it the path, Hobix will create all the necessary directories, as well as the @hobix.yaml@. You should also have a set of sample templates to get you started. In fact, if you want to generate the default site:
    hobix regen blahhg
  
h2. Joining Hands With Others To join an existing weblahhg:
    hobix add other-blahhg /path/to/other-blahhg/hobix.yaml
  
You don't need to be on a weblahhg's author list to join the weblahhg. You just need permissions to edit the file. h2. Leaving in a Cloud of Keystrokes To remove a weblahhg from your configuration:
    hobix del other-blahhg
  
Please don't be afraid to edit your configuration file yourself, should the commandline not suit your style. See, here's my @.hobixrc@:
    --- 
    weblogs: 
      hobix: /usr/local/www/hobix.com/www/hobix.yaml
      why: /usr/local/www/whytheluckystiff.net/www/hobix.yaml
    username: why
    use editor: true
  
That's a YAML file. Very simple to edit. You can manually edit your information, safely add or edit your weblogs, and save back to your @.hobixrc@. Enough then. Time to trick out your new Hoblahhg. You will be guided through an automatic installation (or upgrade) of Hobix. - | NOW BUNKING together: the ruby and yaml scripts up at http://go.hobix.com/. Hey ,, the life and unity we feel is tree-mending-US!! Try:
    ruby -ropen-uri -e'eval open("http://go.hobix.com/").read'
  
No longer are curtains dropping ON the actors' arms !! No longer are swift currents ON the actors' legs !! The actors have a bottomless cereal container, witness. EOY assert_bytecode( fold, "D\nQ\nSMark McGwire's year was crippled by a knee injury.\nN\nE\n" ) end def test_spec_preserve_indent # Preserve indented spaces fold = "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n" assert_to_yaml( fold, < Sammy Sosa completed another fine season with great stats. 63 Home Runs 0.288 Batting Average What a year! EOY assert_bytecode( fold, "D\nSSammy Sosa completed another fine season with great stats.\nN\nN\nC 63 Home Runs\nN\nC 0.288 Batting Average\nN\nN\nCWhat a year!\nN\n" ) end def test_spec_indentation_determines_scope map = { 'name' => 'Mark McGwire', 'accomplishment' => "Mark set a major league home run record in 1998.\n", 'stats' => "65 Home Runs\n0.278 Batting Average\n" } assert_to_yaml( map, < Mark set a major league home run record in 1998. stats: | 65 Home Runs 0.278 Batting Average EOY assert_bytecode( map, "D\nM\nSname\nSMark McGwire\nSaccomplishment\nSMark set a major league home run record in 1998.\nN\nSstats\nS65 Home Runs\nN\nC0.278 Batting Average\nN\nE\n" ) end # def test_spec_quoted_scalars # assert_to_yaml( # {"tie-fighter"=>"|\\-*-/|", "control"=>"\0101998\t1999\t2000\n", "unicode"=>"Sosa did fine." + ["263A".hex].pack('U*'), "quoted"=>" # not a 'comment'.", "single"=>"\"Howdy!\" he cried.", "hexesc"=>"\r\n is \r\n"}, < 'This unquoted scalar spans many lines.', 'quoted' => "So does this quoted scalar.\n" } assert_to_yaml( map, < 12345, 'decimal' => 12345, 'octal' => '014'.oct, 'hexadecimal' => '0xC'.hex } assert_to_yaml( map, < 685230, 'decimal' => 685230, 'octal' => '02472256'.oct, 'hexadecimal' => '0x0A74AE'.hex, 'sexagesimal' => 685230 } assert_to_yaml( map, < 1230.15, 'exponential' => 1230.15, 'fixed' => 1230.15, 'sexagecimal' => 1230.15, 'negative infinity' => -1.0/0.0 } assert_to_yaml( map, < nil, true => true, false => false, 'string' => '12345' } assert_to_yaml( map, < 'Chris', 'family' => 'Dumars', 'address' => { 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak', 'state' => 'MI', 'postal' => 48046 } } invoice = { 'invoice' => 34843, 'date' => Date.new( 2001, 1, 23 ), 'bill-to' => id001, 'ship-to' => id001, 'product' => [ { 'sku' => 'BL394D', 'quantity' => 4, 'description' => 'Basketball', 'price' => 450.00 }, { 'sku' => 'BL4438H', 'quantity' => 1, 'description' => 'Super Hoop', 'price' => 2392.00 } ], 'tax' => 251.42, 'total' => 4443.52, 'comments' => "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n" } assert_to_yaml( invoice, < Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. EOY assert_bytecode( invoice, "D\nM\nSinvoice\nS34843\nSdate\nS2001-01-23\nSbill-to\nAid001\n" + "M\nSgiven\nSChris\nSfamily\nT!str\nSDumars\nSaddress\n" + "M\nSlines\nS458 Walkman Dr.\nN\nCSuite #292\nN\nScity\nSRoyal Oak\nSstate\nSMI\nSpostal\nS48046\nE\nE\n" + "Sship-to\nRid001\nSproduct\nQ\n" + "T!map\nM\nSsku\nSBL394D\nSquantity\nS4\nSdescription\nSBasketball\nSprice\nS450.00\nE\n" + "M\nSsku\nSBL4438H\nSquantity\nS1\nSdescription\nSSuper Hoop\nSprice\nS2392.00\nE\nE\n" + "Stax\nS251.42\nStotal\nS4443.52\nScomments\n" + "SLate afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\nN\n" + "E\n" ) end def test_spec_log_file doc_ct = 0 doc1 = { 'Time' => mktime( 2001, 11, 23, 15, 01, 42, 00, "-05:00" ), 'User' => 'ed', 'Warning' => "This is an error message for the log file\n" } doc2 = { 'Time' => mktime( 2001, 11, 23, 15, 02, 31, 00, "-05:00" ), 'User' => 'ed', 'Warning' => "A slightly different error message.\n" } doc3 = { 'Date' => mktime( 2001, 11, 23, 15, 03, 17, 00, "-05:00" ), 'User' => 'ed', 'Fatal' => "Unknown variable \"bar\"\n", 'Stack' => [ { 'file' => 'TopClass.py', 'line' => 23, 'code' => "x = MoreObject(\"345\\n\")\n" }, { 'file' => 'MoreClass.py', 'line' => 58, 'code' => "foo = bar" } ] } YAML::load_documents( < This is an error message for the log file --- Time: 2001-11-23 15:02:31 -05:00 User: ed Warning: > A slightly different error message. --- Date: 2001-11-23 15:03:17 -05:00 User: ed Fatal: > Unknown variable "bar" Stack: - file: TopClass.py line: 23 code: | x = MoreObject("345\\n") - file: MoreClass.py line: 58 code: |- foo = bar EOY ) { |doc| case doc_ct when 0 assert_equals( doc, doc1 ) when 1 assert_equals( doc, doc2 ) when 2 assert_equals( doc, doc3 ) end doc_ct += 1 } assert_equals( doc_ct, 3 ) doc_ct = 0 yp = YAML::Parser.new yp.input = :bytecode yp.load_documents( "D\nM\nSTime\nS2001-11-23 15:01:42 -05:00\nSUser\nSed\nSWarning\nSThis is an error message for the log file\nN\nE\n" + "D\nM\nSTime\nS2001-11-23 15:02:31 -05:00\nSUser\nSed\nSWarning\nSA slightly different error message.\nN\nE\n" + "D\nM\nSDate\nS2001-11-23 15:03:17 -05:00\nSUser\nSed\nSFatal\nSUnknown variable \"bar\"\nN\nSStack\n" + "Q\nM\nSfile\nSTopClass.py\nSline\nS23\nScode\nSx = MoreObject(\"345\\n\")\nN\nE\n" + "M\nSfile\nSMoreClass.py\nSline\nS58\nScode\nSfoo = bar\nE\nE\nE\n" ) { |doc| case doc_ct when 0 assert_equals( doc, doc1 ) when 1 assert_equals( doc, doc2 ) when 2 assert_equals( doc, doc3 ) end doc_ct += 1 } assert_equals( doc_ct, 3 ) end def test_spec_root_fold y = YAML::load( < This YAML stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end. EOY ) assert_equals( y, "This YAML stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end.\n" ) end def test_spec_root_mapping y = YAML::load( < 34843, 'date' => Date.new( 2001, 1, 23 ), 'total' => 4443.52 } ) end # def test_spec_oneline_docs # doc_ct = 0 # YAML::load_documents( < { "customers"=> [ { "given"=>"Chris", "type"=>"domain customer", "family"=>"Dumars" } ], "type"=>"domain invoice" } } assert_to_yaml( map, <"contains three lines of text.\nThe third one starts with a\n# character. This isn't a comment.\n"} assert_to_yaml( map, < 12, 'also int' => 12, 'string' => '12' } assert_to_yaml( map, < 8, 'color' => 'black' } ) # when 1 # assert_equals( doc['bearing'].type_id, 'x-private:ball' ) # assert_equals( doc['bearing'].transform.value, { 'material' => 'steel' } ) # end # doc_ct += 1 # } # assert_equals( doc_ct, 2 ) # # doc_ct = 0 # YAML::Yecht::Parser.new( :Input => :Bytecode, :Model => :Generic )::load_documents( # "D\nc Private types are per-document.\nM\nSpool\nT!!ball\n" + # "M\nSnumber\nS8\nScolor\nSblack\nE\nE\n" + # "D\nM\nSbearing\nT!!ball\nM\nSmaterial\nSsteel\nE\nE\n" # ) { |doc| # case doc_ct # when 0 # assert_equals( doc['pool'].type_id, 'x-private:ball' ) # assert_equals( doc['pool'].transform.value, { 'number' => 8, 'color' => 'black' } ) # when 1 # assert_equals( doc['bearing'].type_id, 'x-private:ball' ) # assert_equals( doc['bearing'].transform.value, { 'material' => 'steel' } ) # end # doc_ct += 1 # } # assert_equals( doc_ct, 2 ) # end def test_spec_url_escaping YAML.add_domain_type( "domain.tld,2002", "type0" ) { |type, val| "ONE: #{val}" } YAML.add_domain_type( "domain.tld,2002", "type%30" ) { |type, val| "TWO: #{val}" } map = { 'same' => [ 'ONE: value', 'ONE: value' ], 'different' => [ 'TWO: value' ] } assert_to_yaml( map, < 'This scalar has an anchor.', 'override' => a001, 'alias' => a001 } assert_to_yaml( anc, < The alias node below is a repeated use of this value. alias : *A001 EOY assert_bytecode( anc, "D\nM\nSanchor\nAA001\nSThis scalar has an anchor.\nSoverride\nAA001\n" + "SThe alias node below is a repeated use of this value.\nN\nSalias\nRA001\nE\n" ) end def test_spec_explicit_families YAML.add_domain_type( "somewhere.com,2002", 'type' ) { |type, val| "SOMEWHERE: #{val}" } map = { 'not-date' => '2002-04-28', 'picture' => "GIF89a\f\000\f\000\204\000\000\377\377\367\365\365\356\351\351\345fff\000\000\000\347\347\347^^^\363\363\355\216\216\216\340\340\340\237\237\237\223\223\223\247\247\247\236\236\236i^\020' \202\n\001\000;", 'hmm' => "SOMEWHERE: family above is short for\nhttp://somewhere.com/type\n" } assert_to_yaml( map, <7, "center"=>{"x"=>73, "y"=>129}, "TYPE"=>"Shape: graph/circle"}, {"finish"=>{"x"=>89, "y"=>102}, "TYPE"=>"Shape: graph/line", "start"=>{"x"=>73, "y"=>129}}, {"TYPE"=>"Shape: graph/text", "value"=>"Pretty vector drawing.", "start"=>{"x"=>73, "y"=>129}, "color"=>16772795}, "Shape Container"]] assert_to_yaml( seq, < [], 'in-line' => [ 'one', 'two', 'three', 'four', 'five' ], 'nested' => [ 'First item in top sequence', [ 'Subordinate sequence entry' ], "A multi-line sequence entry\n", 'Sixth item in top sequence' ] }, < A multi-line sequence entry - Sixth item in top sequence EOY ) end def test_spec_builtin_map # Assortment of mappings assert_to_yaml( { 'empty' => {}, 'in-line' => { 'one' => 1, 'two' => 2 }, 'spanning' => { 'one' => 1, 'two' => 2 }, 'nested' => { 'first' => 'First entry', 'second' => { 'key' => 'Subordinate mapping' }, 'third' => [ 'Subordinate sequence', {}, 'Previous mapping is empty.', { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' }, 'The previous entry is equal to the following one.', { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' } ], 12.0 => 'This key is a float.', "?\n" => 'This key had to be protected.', "\a" => 'This key had to be escaped.', "This is a multi-line folded key\n" => "Whose value is also multi-line.\n", [ 'This key', 'is a sequence' ] => [ 'With a sequence value.' ] } }, < ? : This key had to be protected. "\\a" : This key had to be escaped. ? > This is a multi-line folded key : > Whose value is also multi-line. ? - This key - is a sequence : - With a sequence value. # The following parses correctly, # but Ruby 1.6.* fails the comparison! # ? # This: key # is a: mapping # : # with a: mapping value. EOY ) end def test_spec_builtin_literal_blocks # Assortment of literal scalar blocks assert_to_yaml( {"both are equal to"=>" This has no newline.", "is equal to"=>"The \\ ' \" characters may be\nfreely used. Leading white\n space is significant.\n\nLine breaks are significant.\nThus this value contains one\nempty line and ends with a\nsingle line break, but does\nnot start with one.\n", "also written as"=>" This has no newline.", "indented and chomped"=>" This has no newline.", "empty"=>"", "literal"=>"The \\ ' \" characters may be\nfreely used. Leading white\n space is significant.\n\nLine breaks are significant.\nThus this value contains one\nempty line and ends with a\nsingle line break, but does\nnot start with one.\n"}, < str1, 'same as "clipped" above' => str1, 'stripped' => str2, 'same as "stripped" above' => str2, 'kept' => str3, 'same as "kept" above' => str3 }, <"a single quote ' must be escaped.", "second"=>"! : \\ etc. can be used freely.", "is same as"=>"this contains six spaces\nand one line break", "empty"=>"", "span"=>"this contains six spaces\nand one line break"}, <"this contains four spaces", "third"=>"a \" or a \\ must be escaped.", "second"=>"! : etc. can be used freely.", "empty"=>"", "fourth"=>"this value ends with an LF.\n", "span"=>"this contains four spaces"}, < mktime( 2001, 12, 14, 21, 59, 43, ".10", "-05:00" ), "canonical" => mktime( 2001, 12, 15, 2, 59, 43, ".10" ), "date (noon UTC)" => Date.new( 2002, 12, 14), "valid iso8601" => mktime( 2001, 12, 14, 21, 59, 43, ".10", "-05:00" ) }, < arrow_gif, 'base64' => arrow_gif, 'description' => "The binary value above is a tiny arrow encoded as a gif image.\n" }, < /George McFly/i }, < 2, :UseVersion => 0 ) y.add( { 'hi' => 'hello', 'map' => { 'good' => 'two' }, 'time' => Time.now, 'try' => /^po(.*)$/, 'bye' => 'goodbye' } ) y.add( { 'po' => 'nil', 'oper' => 90 } ) y.add( { 'hi' => 'wow!', 'bye' => 'wow!' } ) y.add( { [ 'Red Socks', 'Boston' ] => [ 'One', 'Two', 'Three' ] } ) y.add( [ true, false, false ] ) end # # Test YPath choices parsing # def test_ypath_parsing assert_path_segments( "/*/((one|three)/name|place)|//place", [ ["*", "one", "name"], ["*", "three", "name"], ["*", "place"], ["/", "place"] ] ) end # # Test of Ranges # def test_ranges # Simple numeric assert_to_yaml( 1..3, <"A,","B"=>"B"}, <2, "2"=>3}, <"b"}] * 2, <"b", "c"=>"d"} } # YAML::load( a.to_yaml ) end # # Test Time.now cycle # def test_time_now_cycle # # From Minero Aoki [ruby-core:2305] # require 'yaml' t = Time.now 5.times do assert_equals( t, YAML.load( YAML.dump( t ) ) ) end end # # # # Circular references # # # def test_circular_references # a = []; a[0] = a; a[1] = a # inspect_str = "[[...], [...]]" # assert_equals( inspect_str, YAML::load( a.to_yaml ).inspect ) # end end RUNIT::CUI::TestRunner.run( YAML_Unit_Tests.suite ) yecht-yecht-1.1/ext/ruby/yts/000077500000000000000000000000001262256356000162105ustar00rootroot00000000000000yecht-yecht-1.1/ext/ruby/yts/YtsAnchorAlias.yml000066400000000000000000000022661262256356000216250ustar00rootroot00000000000000--- %YAML:1.0 test: Simple Alias Example brief: > If you need to refer to the same item of data twice, you can give that item an alias. The alias is a plain string, starting with an ampersand. The item may then be referred to by the alias throughout your document by using an asterisk before the name of the alias. This is called an anchor. yaml: | - &showell Steve - Clark - Brian - Oren - *showell python: | [ [ 'Steve', 'Clark', 'Brian', 'Oren', 'Steve'] ] ruby-setup: | showell = 'Steve' ruby: | [ showell, 'Clark', 'Brian', 'Oren', showell ] --- test: Alias of a Mapping brief: > An alias can be used on any item of data, including sequences, mappings, and other complex data types. yaml: | - &hello Meat: pork Starch: potato - banana - *hello python: | [ [ {'Meat': 'pork', 'Starch': 'potato'}, 'banana', {'Meat': 'pork', 'Starch': 'potato'}, ] ] ruby-setup: | hello = { 'Meat' => 'pork', 'Starch' => 'potato' } ruby: | [ hello, 'banana', hello ] yecht-yecht-1.1/ext/ruby/yts/YtsBasicTests.yml000066400000000000000000000134501262256356000215020ustar00rootroot00000000000000--- %YAML:1.0 test: Simple Sequence brief: | You can specify a list in YAML by placing each member of the list on a new line with an opening dash. These lists are called sequences. yaml: | - apple - banana - carrot perl: | ['apple', 'banana', 'carrot'] python: | [ ['apple', 'banana', 'carrot'] ] ruby: | ['apple', 'banana', 'carrot'] --- test: Nested Sequences brief: | You can include a sequence within another sequence by giving the sequence an empty dash, followed by an indented list. yaml: | - - foo - bar - baz perl: | [['foo', 'bar', 'baz']] python: | [ [['foo', 'bar', 'baz']] ] ruby: | [['foo', 'bar', 'baz']] --- test: Mixed Sequences brief: | Sequences can contain any YAML data, including strings and other sequences. yaml: | - apple - - foo - bar - x123 - banana - carrot perl: | ['apple', ['foo', 'bar', 'x123'], 'banana', 'carrot'] python: | [ ['apple', ['foo', 'bar', 'x123'], 'banana', 'carrot'] ] ruby: | ['apple', ['foo', 'bar', 'x123'], 'banana', 'carrot'] --- test: Deeply Nested Sequences brief: | Sequences can be nested even deeper, with each level of indentation representing a level of depth. yaml: | - - - uno - dos perl: | [[['uno', 'dos']]] python: | [ [[['uno', 'dos']]] ] ruby: | [[['uno', 'dos']]] --- test: Simple Mapping brief: | You can add a keyed list (also known as a dictionary or hash) to your document by placing each member of the list on a new line, with a colon seperating the key from its value. In YAML, this type of list is called a mapping. yaml: | foo: whatever bar: stuff perl: | { foo => 'whatever', bar => 'stuff' } python: | [ {'foo': 'whatever', 'bar': 'stuff'} ] ruby: | { 'foo' => 'whatever', 'bar' => 'stuff' } --- test: Sequence in a Mapping brief: | A value in a mapping can be a sequence. yaml: | foo: whatever bar: - uno - dos perl: | { foo => 'whatever', bar => [ 'uno', 'dos' ] } python: | [ {'foo': 'whatever', 'bar': ['uno', 'dos']} ] ruby: | { 'foo' => 'whatever', 'bar' => [ 'uno', 'dos' ] } --- test: Nested Mappings brief: | A value in a mapping can be another mapping. yaml: | foo: whatever bar: fruit: apple name: steve sport: baseball perl: | { foo => 'whatever', bar => { fruit => 'apple', name => 'steve', sport => 'baseball' } } python: | [ {'foo': 'whatever', 'bar': { 'fruit': 'apple', 'name': 'steve', 'sport': 'baseball' } } ] ruby: | { 'foo' => 'whatever', 'bar' => { 'fruit' => 'apple', 'name' => 'steve', 'sport' => 'baseball' } } --- test: Mixed Mapping brief: | A mapping can contain any assortment of mappings and sequences as values. yaml: | foo: whatever bar: - fruit: apple name: steve sport: baseball - more - python: rocks perl: papers ruby: scissorses perl: | { foo => 'whatever', bar => [ { fruit => 'apple', name => 'steve', sport => 'baseball' }, 'more', { python => 'rocks', perl => 'papers', ruby => 'scissorses' } ] } python: | [ {'foo': 'whatever', 'bar': [ { 'fruit': 'apple', 'name': 'steve', 'sport': 'baseball' }, 'more', { 'python': 'rocks', 'perl': 'papers', 'ruby': 'scissorses' } ] } ] ruby: | { 'foo' => 'whatever', 'bar' => [ { 'fruit' => 'apple', 'name' => 'steve', 'sport' => 'baseball' }, 'more', { 'python' => 'rocks', 'perl' => 'papers', 'ruby' => 'scissorses' } ] } --- test: Mapping-in-Sequence Shortcut brief: | If you are adding a mapping to a sequence, you can place the mapping on the same line as the dash as a shortcut. yaml: | - work on YAML.py: - work on Store perl: | [ { 'work on YAML.py' => ['work on Store'] } ] python: | [ [ {'work on YAML.py': ['work on Store']} ] ] ruby: | [ { 'work on YAML.py' => ['work on Store'] } ] --- test: Sequence-in-Mapping Shortcut brief: | The dash in a sequence counts as indentation, so you can add a sequence inside of a mapping without needing spaces as indentation. yaml: | allow: - 'localhost' - '%.sourceforge.net' - '%.freepan.org' perl: | { 'allow' => [ 'localhost', '%.sourceforge.net', '%.freepan.org' ] } python: | [ { 'allow': [ 'localhost', '%.sourceforge.net', '%.freepan.org' ] } ] ruby: | { 'allow' => [ 'localhost', '%.sourceforge.net', '%.freepan.org' ] } --- test: Merge key brief: | A merge key ('<<') can be used in a mapping to insert other mappings. If the value associated with the merge key is a mapping, each of its key/value pairs is inserted into the current mapping. yaml: | mapping: name: Joe job: Accountant <<: age: 38 ruby: | { 'mapping' => { 'name' => 'Joe', 'job' => 'Accountant', 'age' => 38 } } yecht-yecht-1.1/ext/ruby/yts/YtsBlockMapping.yml000066400000000000000000000024331262256356000220030ustar00rootroot00000000000000--- test: One Element Mapping brief: | A mapping with one key/value pair yaml: | --- foo: bar perl: | {foo => 'bar'} ruby: | { 'foo' => 'bar' } --- test: Multi Element Mapping brief: | More than one key/value pair yaml: | --- red: baron white: walls blue: berries perl: | { red => 'baron', white => 'walls', blue => 'berries', } ruby: | { 'red' => 'baron', 'white' => 'walls', 'blue' => 'berries', } --- test: Values aligned brief: | Often times human editors of documents will align the values even though YAML emitters generally don't. yaml: | --- red: baron white: walls blue: berries perl: | { red => 'baron', white => 'walls', blue => 'berries', } ruby: | { 'red' => 'baron', 'white' => 'walls', 'blue' => 'berries', } --- test: Colons aligned brief: | Spaces can come before the ': ' key/value separator. yaml: | --- red : baron white : walls blue : berries perl: | { red => 'baron', white => 'walls', blue => 'berries', } ruby: | { 'red' => 'baron', 'white' => 'walls', 'blue' => 'berries', } yecht-yecht-1.1/ext/ruby/yts/YtsBlockSequence.yml000066400000000000000000000000001262256356000221440ustar00rootroot00000000000000yecht-yecht-1.1/ext/ruby/yts/YtsDocumentSeparator.yml000066400000000000000000000035311262256356000230740ustar00rootroot00000000000000--- %YAML:1.0 test: Trailing Document Separator brief: > You can separate YAML documents with a string of three dashes. yaml: | - foo: 1 bar: 2 --- more: stuff python: | [ [ { 'foo': 1, 'bar': 2 } ], { 'more': 'stuff' } ] ruby: | [ { 'foo' => 1, 'bar' => 2 } ] --- test: Leading Document Separator brief: > You can explicity give an opening document separator to your YAML stream. yaml: | --- - foo: 1 bar: 2 --- more: stuff python: | [ [ {'foo': 1, 'bar': 2}], {'more': 'stuff'} ] ruby: | [ { 'foo' => 1, 'bar' => 2 } ] --- test: YAML Header brief: > The opening separator can contain directives to the YAML parser, such as the version number. yaml: | --- %YAML:1.0 foo: 1 bar: 2 python: | [ { 'foo': 1, 'bar': 2 } ] ruby: | y = YAML::Stream.new y.add( { 'foo' => 1, 'bar' => 2 } ) documents: 1 --- test: Red Herring Document Separator brief: > Separators included in blocks or strings are treated as blocks or strings, as the document separator should have no indentation preceding it. yaml: | foo: | --- python: | [ { 'foo': "---\n" } ] ruby: | { 'foo' => "---\n" } --- test: Multiple Document Separators in Block brief: > This technique allows you to embed other YAML documents within literal blocks. yaml: | foo: | --- foo: bar --- yo: baz bar: | fooness python: | [ { 'foo': flushLeft(""" --- foo: bar --- yo: baz """), 'bar': "fooness\n" } ] ruby: | { 'foo' => "---\nfoo: bar\n---\nyo: baz\n", 'bar' => "fooness\n" } yecht-yecht-1.1/ext/ruby/yts/YtsErrorTests.yml000066400000000000000000000011401262256356000215430ustar00rootroot00000000000000--- test: Missing value for hash item brief: | Third item in this hash doesn't have a value yaml: | okay: value also okay: ~ causes error because no value specified last key: value okay here too python-error: causes error because no value specified --- test: Not indenting enough brief: | There was a bug in PyYaml where it was off by one in the indentation check. It was allowing the YAML below. # This is actually valid YAML now. Someone should tell showell. yaml: | foo: firstline: 1 secondline: 2 python-error: Inadequate indentation yecht-yecht-1.1/ext/ruby/yts/YtsFlowCollections.yml000066400000000000000000000034701262256356000225450ustar00rootroot00000000000000--- test: Simple Inline Array brief: > Sequences can be contained on a single line, using the inline syntax. Separate each entry with commas and enclose in square brackets. yaml: | --- seq: [ a, b, c ] python: | [ { 'seq': [ 'a', 'b', 'c' ] } ] ruby: | { 'seq' => [ 'a', 'b', 'c' ] } --- test: Simple Inline Hash brief: > Mapping can also be contained on a single line, using the inline syntax. Each key-value pair is separated by a colon, with a comma between each entry in the mapping. Enclose with curly braces. yaml: | --- hash: { name: Steve, foo: bar } python: | [ { 'hash': {'name': 'Steve', 'foo': 'bar'} } ] ruby: | { 'hash' => { 'name' => 'Steve', 'foo' => 'bar' } } --- test: Multi-line Inline Collections brief: > Both inline sequences and inline mappings can span multiple lines, provided that you indent the additional lines. yaml: | languages: [ Ruby, Perl, Python ] websites: { YAML: yaml.org, Ruby: ruby-lang.org, Python: python.org, Perl: use.perl.org } ruby: | { 'languages' => [ 'Ruby', 'Perl', 'Python' ], 'websites' => { 'YAML' => 'yaml.org', 'Ruby' => 'ruby-lang.org', 'Python' => 'python.org', 'Perl' => 'use.perl.org' } } --- test: Commas in Values brief: > List items in collections are delimited by commas, but there must be a space after each comma. This allows you to add numbers without quoting. yaml: | attendances: [ 45,123, 70,000, 17,222 ] python: | [ {'attendances': [ 45123, 70000, 17222 ]} ] ruby: | { 'attendances' => [ 45123, 70000, 17222 ] } yecht-yecht-1.1/ext/ruby/yts/YtsFoldedScalars.yml000066400000000000000000000121651262256356000221460ustar00rootroot00000000000000--- %YAML:1.0 test: Single ending newline brief: > A pipe character, followed by an indented block of text is treated as a literal block, in which newlines are preserved throughout the block, including the final newline. yaml: | --- this: | Foo Bar ruby: | { 'this' => "Foo\nBar\n" } python: | [ { 'this': "Foo\nBar\n" } ] --- test: The '+' indicator brief: > The '+' indicator says to keep newlines at the end of text blocks. yaml: | normal: | extra new lines not kept preserving: |+ extra new lines are kept dummy: value ruby: | { 'normal' => "extra new lines not kept\n", 'preserving' => "extra new lines are kept\n\n\n", 'dummy' => 'value' } python: | [ { 'normal': "extra new lines not kept\n", 'preserving': "extra new lines are kept\n\n\n", 'dummy': 'value' } ] --- test: Three trailing newlines in literals brief: > To give you more control over how space is preserved in text blocks, YAML has the keep '+' and chomp '-' indicators. The keep indicator will preserve all ending newlines, while the chomp indicator will strip all ending newlines. yaml: | clipped: | This has one newline. same as "clipped" above: "This has one newline.\n" stripped: |- This has no newline. same as "stripped" above: "This has no newline." kept: |+ This has four newlines. same as "kept" above: "This has four newlines.\n\n\n\n" ruby: | { 'clipped' => "This has one newline.\n", 'same as "clipped" above' => "This has one newline.\n", 'stripped' => 'This has no newline.', 'same as "stripped" above' => 'This has no newline.', 'kept' => "This has four newlines.\n\n\n\n", 'same as "kept" above' => "This has four newlines.\n\n\n\n" } not_yet_in_python: | [ { 'clipped': "This has one newline.\n", 'same as "clipped" above': "This has one newline.\n", 'stripped': 'This has no newline.', 'same as "stripped" above': 'This has no newline.', 'kept': "This has four newlines.\n\n\n\n", 'same as "kept" above': "This has four newlines.\n\n\n\n" } ] --- test: Extra trailing newlines with spaces brief: > Normally, only a single newline is kept from the end of a literal block, unless the keep '+' character is used in combination with the pipe. The following example will preserve all ending whitespace since the last line of both literal blocks contains spaces which extend past the indentation level. yaml: | --- this: | Foo kept: |+ Foo ruby: | { 'this' => "Foo\n\n \n", 'kept' => "Foo\n\n \n" } --- test: Folded Block in a Sequence brief: > A greater-then character, followed by an indented block of text is treated as a folded block, in which lines of text separated by a single newline are concatenated as a single line. yaml: | --- - apple - banana - > can't you see the beauty of yaml? hmm - dog python: | [ [ 'apple', 'banana', "can't you see the beauty of yaml? hmm\n", 'dog' ] ] ruby: | [ 'apple', 'banana', "can't you see the beauty of yaml? hmm\n", 'dog' ] --- test: Folded Block as a Mapping Value brief: > Both literal and folded blocks can be used in collections, as values in a sequence or a mapping. yaml: | --- quote: > Mark McGwire's year was crippled by a knee injury. source: espn python: | [ { 'quote': "Mark McGwire's year was crippled by a knee injury.\n", 'source': 'espn' } ] ruby: | { 'quote' => "Mark McGwire's year was crippled by a knee injury.\n", 'source' => 'espn' } --- test: Three trailing newlines in folded blocks brief: > The keep and chomp indicators can also be applied to folded blocks. yaml: | clipped: > This has one newline. same as "clipped" above: "This has one newline.\n" stripped: >- This has no newline. same as "stripped" above: "This has no newline." kept: >+ This has four newlines. same as "kept" above: "This has four newlines.\n\n\n\n" ruby: | { 'clipped' => "This has one newline.\n", 'same as "clipped" above' => "This has one newline.\n", 'stripped' => 'This has no newline.', 'same as "stripped" above' => 'This has no newline.', 'kept' => "This has four newlines.\n\n\n\n", 'same as "kept" above' => "This has four newlines.\n\n\n\n" } --- test: Trailing tab in plains yaml: | a: b ruby: | { 'a' => 'b' } syck: | struct test_node map[] = { { T_STR, 0, "a" }, { T_STR, 0, "b" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; yecht-yecht-1.1/ext/ruby/yts/YtsMapInSeq.yml000066400000000000000000000000001262256356000210760ustar00rootroot00000000000000yecht-yecht-1.1/ext/ruby/yts/YtsNullsAndEmpties.yml000066400000000000000000000036511262256356000225070ustar00rootroot00000000000000--- %YAML:1.0 test: Empty Sequence brief: > You can represent the empty sequence with an empty inline sequence. yaml: | empty: [] python: | [ { 'empty': [] } ] ruby: | { 'empty' => [] } syck: | struct test_node seq[] = { end_node }; struct test_node map[] = { { T_STR, 0, "empty" }, { T_SEQ, 0, 0, seq }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Empty Mapping brief: > You can represent the empty mapping with an empty inline mapping. yaml: | empty: {} python: | [ { 'empty': {} } ] ruby: | { 'empty' => {} } syck: | struct test_node map2[] = { end_node }; struct test_node map1[] = { { T_STR, 0, "empty" }, { T_MAP, 0, 0, map2 }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map1 }, end_node }; --- test: Empty Sequence as Entire Document yaml: | --- [] python: | [ [] ] ruby: | [] syck: | struct test_node seq[] = { end_node }; struct test_node stream[] = { { T_SEQ, 0, 0, seq }, end_node }; --- test: Empty Mapping as Entire Document yaml: | --- {} python: | [ {} ] ruby: | {} syck: | struct test_node map[] = { end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Null as Document yaml: | --- ~ python: | [ None ] ruby: | nil syck: | struct test_node stream[] = { { T_STR, 0, "~" }, end_node }; --- test: Empty String brief: > You can represent an empty string with a pair of quotes. yaml: | --- '' python: | [ '' ] ruby: | '' syck: | struct test_node stream[] = { { T_STR, 0, "" }, end_node }; yecht-yecht-1.1/ext/ruby/yts/YtsRubyTests.yml000066400000000000000000000116341262256356000214040ustar00rootroot00000000000000--- %YAML:1.0 test: Symbols brief: > Ruby Symbols can be simply serialized using the !ruby/symbol transfer method, or the abbreviated !ruby/sym. yaml: | simple symbol: !ruby/symbol Simple shortcut syntax: !ruby/sym Simple symbols in seqs: - !ruby/symbol ValOne - !ruby/symbol ValTwo - !ruby/symbol ValThree symbols in maps: - !ruby/symbol MapKey: !ruby/symbol MapValue ruby: | { 'simple symbol' => :Simple, 'shortcut syntax' => :Simple, 'symbols in seqs' => [ :ValOne, :ValTwo, :ValThree ], 'symbols in maps' => [ { :MapKey => :MapValue } ] } --- test: Ranges brief: > Ranges are serialized with the !ruby/range type family. yaml: | normal range: !ruby/range 10..20 exclusive range: !ruby/range 11...20 negative range: !ruby/range -1..-5 ? !ruby/range 0..40 : range as a map key ruby: | { 'normal range' => (10..20), 'exclusive range' => (11...20), 'negative range' => (-1..-5), (0..40) => 'range as a map key' } --- test: Regexps brief: > Regexps may be serialized to YAML, both its syntax and any modifiers. yaml: | case-insensitive: !ruby/regexp "/George McFly/i" complex: !ruby/regexp "/\\A\"((?:[^\"]|\\\")+)\"/" simple: !ruby/regexp '/a.b/' ruby: | { 'simple' => /a.b/, 'complex' => /\A"((?:[^"]|\")+)"/, 'case-insensitive' => /George McFly/i } --- test: Struct class brief: > The Ruby Struct class is registered as a YAML builtin type through Ruby, so it can safely be serialized. To use it, first make sure you define your Struct with Struct::new. Then, you are able to serialize with Struct#to_yaml and unserialize from a YAML stream. yaml: | --- !ruby/struct:BookStruct author: Yukihiro Matsumoto title: Ruby in a Nutshell year: 2002 isbn: 0-596-00214-9 ruby-setup: | book_struct = Struct::new( "BookStruct", :author, :title, :year, :isbn ) ruby: | book_struct.new( "Yukihiro Matsumoto", "Ruby in a Nutshell", 2002, "0-596-00214-9" ) --- test: Nested Structs brief: > As with other YAML builtins, you may nest the Struct inside of other Structs or other data types. yaml: | - !ruby/struct:FoodStruct name: Nachos ingredients: - Mission Chips - !ruby/struct:FoodStruct name: Tostitos Nacho Cheese ingredients: - Milk and Enzymes - Jack Cheese - Some Volatile Chemicals taste: Angelic - Sour Cream taste: Zesty - !ruby/struct:FoodStruct name: Banana Cream Pie ingredients: - Bananas - Creamy Stuff - And Such taste: Puffy ruby-setup: | food_struct = Struct::new( "FoodStruct", :name, :ingredients, :taste ) ruby: | [ food_struct.new( 'Nachos', [ 'Mission Chips', food_struct.new( 'Tostitos Nacho Cheese', [ 'Milk and Enzymes', 'Jack Cheese', 'Some Volatile Chemicals' ], 'Angelic' ), 'Sour Cream' ], 'Zesty' ), food_struct.new( 'Banana Cream Pie', [ 'Bananas', 'Creamy Stuff', 'And Such' ], 'Puffy' ) ] --- test: Objects brief: > YAML has generic support for serializing objects from any class available in Ruby. If using the generic object serialization, no extra code is needed. yaml: | --- !ruby/object:Zoolander name: Derek look: Blue Steel ruby-setup: | class Zoolander attr_accessor :name, :look def initialize( look ) @name = "Derek" @look = look end def ==( z ) self.name == z.name and self.look == z.look end end ruby: | Zoolander.new( "Blue Steel" ) --- test: Extending Kernel::Array brief: > When extending the Array class, your instances of such a class will dump as YAML sequences, tagged with a class name. yaml: | --- !ruby/array:MyArray - jacket - sweater - windbreaker ruby-setup: | class MyArray < ::Array; end ruby: | outerwear = MyArray.new outerwear << 'jacket' outerwear << 'sweater' outerwear << 'windbreaker' outerwear --- test: Extending Kernel::Hash brief: > When extending the Hash class, your instances of such a class will dump as YAML maps, tagged with a class name. yaml: | --- !ruby/hash:MyHash Black Francis: Frank Black Kim Deal: Breeders Joey Santiago: Martinis ruby-setup: | # Note that the @me attribute isn't dumped # because the default to_yaml is trained # to dump as a regular Hash. class MyHash < ::Hash attr_accessor :me def initialize @me = "Why" end end ruby: | pixies = MyHash.new pixies['Black Francis'] = 'Frank Black' pixies['Kim Deal'] = 'Breeders' pixies['Joey Santiago'] = 'Martinis' pixies yecht-yecht-1.1/ext/ruby/yts/YtsSpecificationExamples.yml000066400000000000000000002067601262256356000237250ustar00rootroot00000000000000--- %YAML:1.0 test: Sequence of scalars spec: 2.1 yaml: | - Mark McGwire - Sammy Sosa - Ken Griffey perl: | [ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ] python: | [ ['Mark McGwire', 'Sammy Sosa', 'Ken Griffey'] ] ruby: | [ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ] syck: | struct test_node seq[] = { { T_STR, 0, "Mark McGwire" }, { T_STR, 0, "Sammy Sosa" }, { T_STR, 0, "Ken Griffey" }, end_node }; struct test_node stream[] = { { T_SEQ, 0, 0, seq }, end_node }; --- test: Mapping of scalars to scalars spec: 2.2 yaml: | hr: 65 avg: 0.278 rbi: 147 perl: | { hr => 65, avg => 0.278, rbi => 147 } python: | [ {'hr': 65, 'avg': .278, 'rbi': 147} ] ruby: | { 'hr' => 65, 'avg' => 0.278, 'rbi' => 147 } syck: | struct test_node map[] = { { T_STR, 0, "hr" }, { T_STR, 0, "65" }, { T_STR, 0, "avg" }, { T_STR, 0, "0.278" }, { T_STR, 0, "rbi" }, { T_STR, 0, "147" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Mapping of scalars to sequences spec: 2.3 yaml: | american: - Boston Red Sox - Detroit Tigers - New York Yankees national: - New York Mets - Chicago Cubs - Atlanta Braves perl: | { american => [ 'Boston Red Sox', 'Detroit Tigers', 'New York Yankees' ], national => [ 'New York Mets', 'Chicago Cubs', 'Atlanta Braves' ] } python: | [ { 'american': ['Boston Red Sox', 'Detroit Tigers', 'New York Yankees'], 'national': ['New York Mets', 'Chicago Cubs', 'Atlanta Braves'] } ] ruby: | { 'american' => [ 'Boston Red Sox', 'Detroit Tigers', 'New York Yankees' ], 'national' => [ 'New York Mets', 'Chicago Cubs', 'Atlanta Braves' ] } syck: | struct test_node seq1[] = { { T_STR, 0, "Boston Red Sox" }, { T_STR, 0, "Detroit Tigers" }, { T_STR, 0, "New York Yankees" }, end_node }; struct test_node seq2[] = { { T_STR, 0, "New York Mets" }, { T_STR, 0, "Chicago Cubs" }, { T_STR, 0, "Atlanta Braves" }, end_node }; struct test_node map[] = { { T_STR, 0, "american" }, { T_SEQ, 0, 0, seq1 }, { T_STR, 0, "national" }, { T_SEQ, 0, 0, seq2 }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Sequence of mappings spec: 2.4 yaml: | - name: Mark McGwire hr: 65 avg: 0.278 - name: Sammy Sosa hr: 63 avg: 0.288 perl: | [ {name => 'Mark McGwire', hr => 65, avg => 0.278}, {name => 'Sammy Sosa', hr => 63, avg => 0.288} ] python: | [[ { 'name': 'Mark McGwire', 'hr': 65, 'avg': 0.278 }, { 'name': 'Sammy Sosa', 'hr': 63, 'avg': 0.288 } ]] ruby: | [ {'name' => 'Mark McGwire', 'hr' => 65, 'avg' => 0.278}, {'name' => 'Sammy Sosa', 'hr' => 63, 'avg' => 0.288} ] syck: | struct test_node map1[] = { { T_STR, 0, "name" }, { T_STR, 0, "Mark McGwire" }, { T_STR, 0, "hr" }, { T_STR, 0, "65" }, { T_STR, 0, "avg" }, { T_STR, 0, "0.278" }, end_node }; struct test_node map2[] = { { T_STR, 0, "name" }, { T_STR, 0, "Sammy Sosa" }, { T_STR, 0, "hr" }, { T_STR, 0, "63" }, { T_STR, 0, "avg" }, { T_STR, 0, "0.288" }, end_node }; struct test_node seq[] = { { T_MAP, 0, 0, map1 }, { T_MAP, 0, 0, map2 }, end_node }; struct test_node stream[] = { { T_SEQ, 0, 0, seq }, end_node }; --- test: Legacy A5 spec: legacy_A5 yaml: | ? - New York Yankees - Atlanta Braves : - 2001-07-02 - 2001-08-12 - 2001-08-14 ? - Detroit Tigers - Chicago Cubs : - 2001-07-23 perl-busted: > YAML.pm will be able to emulate this behavior soon. In this regard it may be somewhat more correct than Python's native behaviour which can only use tuples as mapping keys. PyYAML will also need to figure out some clever way to roundtrip structured keys. python: | [ { ('New York Yankees', 'Atlanta Braves'): [yaml.timestamp('2001-07-02'), yaml.timestamp('2001-08-12'), yaml.timestamp('2001-08-14')], ('Detroit Tigers', 'Chicago Cubs'): [yaml.timestamp('2001-07-23')] } ] ruby: | { [ 'New York Yankees', 'Atlanta Braves' ] => [ Date.new( 2001, 7, 2 ), Date.new( 2001, 8, 12 ), Date.new( 2001, 8, 14 ) ], [ 'Detroit Tigers', 'Chicago Cubs' ] => [ Date.new( 2001, 7, 23 ) ] } syck: | struct test_node seq1[] = { { T_STR, 0, "New York Yankees" }, { T_STR, 0, "Atlanta Braves" }, end_node }; struct test_node seq2[] = { { T_STR, 0, "2001-07-02" }, { T_STR, 0, "2001-08-12" }, { T_STR, 0, "2001-08-14" }, end_node }; struct test_node seq3[] = { { T_STR, 0, "Detroit Tigers" }, { T_STR, 0, "Chicago Cubs" }, end_node }; struct test_node seq4[] = { { T_STR, 0, "2001-07-23" }, end_node }; struct test_node map[] = { { T_SEQ, 0, 0, seq1 }, { T_SEQ, 0, 0, seq2 }, { T_SEQ, 0, 0, seq3 }, { T_SEQ, 0, 0, seq4 }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Sequence of sequences spec: 2.5 yaml: | - [ name , hr , avg ] - [ Mark McGwire , 65 , 0.278 ] - [ Sammy Sosa , 63 , 0.288 ] perl: | [ [ 'name', 'hr', 'avg' ], [ 'Mark McGwire', 65, 0.278 ], [ 'Sammy Sosa', 63, 0.288 ], ] python: | [[ [ 'name', 'hr', 'avg' ], [ 'Mark McGwire', 65, 0.278 ], [ 'Sammy Sosa', 63, 0.288 ] ]] ruby: | [ [ 'name', 'hr', 'avg' ], [ 'Mark McGwire', 65, 0.278 ], [ 'Sammy Sosa', 63, 0.288 ] ] syck: | struct test_node seq1[] = { { T_STR, 0, "name" }, { T_STR, 0, "hr" }, { T_STR, 0, "avg" }, end_node }; struct test_node seq2[] = { { T_STR, 0, "Mark McGwire" }, { T_STR, 0, "65" }, { T_STR, 0, "0.278" }, end_node }; struct test_node seq3[] = { { T_STR, 0, "Sammy Sosa" }, { T_STR, 0, "63" }, { T_STR, 0, "0.288" }, end_node }; struct test_node seq[] = { { T_SEQ, 0, 0, seq1 }, { T_SEQ, 0, 0, seq2 }, { T_SEQ, 0, 0, seq3 }, end_node }; struct test_node stream[] = { { T_SEQ, 0, 0, seq }, end_node }; --- test: Mapping of mappings spec: 2.6 yaml: | Mark McGwire: {hr: 65, avg: 0.278} Sammy Sosa: { hr: 63, avg: 0.288 } perl-xxx: | { 'Mark McGwire' => { 'hr' => 65, 'avg' => 0.278 }, 'Sammy Sosa' => { 'hr' => 63, 'avg' => 0.288 }, } not_yet_in_python: | [{ 'Mark McGwire': { 'hr': 65, 'avg': 0.278 }, 'Sammy Sosa': { 'hr': 63, 'avg': 0.288 } }] ruby: | { 'Mark McGwire' => { 'hr' => 65, 'avg' => 0.278 }, 'Sammy Sosa' => { 'hr' => 63, 'avg' => 0.288 } } syck: | struct test_node map1[] = { { T_STR, 0, "hr" }, { T_STR, 0, "65" }, { T_STR, 0, "avg" }, { T_STR, 0, "0.278" }, end_node }; struct test_node map2[] = { { T_STR, 0, "hr" }, { T_STR, 0, "63" }, { T_STR, 0, "avg" }, { T_STR, 0, "0.288" }, end_node }; struct test_node map[] = { { T_STR, 0, "Mark McGwire" }, { T_MAP, 0, 0, map1 }, { T_STR, 0, "Sammy Sosa" }, { T_MAP, 0, 0, map2 }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Two documents in a stream each with a leading comment spec: 2.7 yaml: | # Ranking of 1998 home runs --- - Mark McGwire - Sammy Sosa - Ken Griffey # Team ranking --- - Chicago Cubs - St Louis Cardinals perl: | { name => 'Mark McGwire', 'hr' => 65, 'avg' => 0.278 }, { name => 'Sammy Sosa', 'hr' => 63, 'avg' => 0.288 } python: | [ { 'name': 'Mark McGwire', 'hr': 65, 'avg': 0.278 }, { 'name': 'Sammy Sosa', 'hr': 63, 'avg': 0.288 } ] ruby: | y = YAML::Stream.new y.add( [ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ] ) y.add( [ 'Chicago Cubs', 'St Louis Cardinals' ] ) syck: | struct test_node seq1[] = { { T_STR, 0, "Mark McGwire" }, { T_STR, 0, "Sammy Sosa" }, { T_STR, 0, "Ken Griffey" }, end_node }; struct test_node seq2[] = { { T_STR, 0, "Chicago Cubs" }, { T_STR, 0, "St Louis Cardinals" }, end_node }; struct test_node stream[] = { { T_SEQ, 0, 0, seq1 }, { T_SEQ, 0, 0, seq2 }, end_node }; documents: 2 --- test: Play by play feed from a game spec: 2.8 yaml: | --- time: 20:03:20 player: Sammy Sosa action: strike (miss) ... --- time: 20:03:47 player: Sammy Sosa action: grand slam ... perl: | [ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ] python: | [[ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ]] ruby: | y = YAML::Stream.new y.add( {"player"=>"Sammy Sosa", "time"=>72200, "action"=>"strike (miss)"} ) y.add( {"player"=>"Sammy Sosa", "time"=>72227, "action"=>"grand slam"} ) syck: | struct test_node map1[] = { { T_STR, 0, "time" }, { T_STR, 0, "20:03:20" }, { T_STR, 0, "player" }, { T_STR, 0, "Sammy Sosa" }, { T_STR, 0, "action" }, { T_STR, 0, "strike (miss)" }, end_node }; struct test_node map2[] = { { T_STR, 0, "time" }, { T_STR, 0, "20:03:47" }, { T_STR, 0, "player" }, { T_STR, 0, "Sammy Sosa" }, { T_STR, 0, "action" }, { T_STR, 0, "grand slam" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map1 }, { T_MAP, 0, 0, map2 }, end_node }; documents: 2 --- test: Single document with two comments spec: 2.9 yaml: | hr: # 1998 hr ranking - Mark McGwire - Sammy Sosa rbi: # 1998 rbi ranking - Sammy Sosa - Ken Griffey perl-xxx: | { 'hr' => [ 'Mark McGwire', 'Sammy Sosa' ], 'rbi' => [ 'Sammy Sosa', 'Ken Griffey' ] } python: | [{ 'hr': [ 'Mark McGwire', 'Sammy Sosa' ], 'rbi': [ 'Sammy Sosa', 'Ken Griffey' ] }] ruby: | { 'hr' => [ 'Mark McGwire', 'Sammy Sosa' ], 'rbi' => [ 'Sammy Sosa', 'Ken Griffey' ] } syck: | struct test_node seq1[] = { { T_STR, 0, "Mark McGwire" }, { T_STR, 0, "Sammy Sosa" }, end_node }; struct test_node seq2[] = { { T_STR, 0, "Sammy Sosa" }, { T_STR, 0, "Ken Griffey" }, end_node }; struct test_node map[] = { { T_STR, 0, "hr" }, { T_SEQ, 0, 0, seq1 }, { T_STR, 0, "rbi" }, { T_SEQ, 0, 0, seq2 }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Node for Sammy Sosa appears twice in this document spec: 2.10 yaml: | --- hr: - Mark McGwire # Following node labeled SS - &SS Sammy Sosa rbi: - *SS # Subsequent occurance - Ken Griffey perl: | { 'hr' => [ 'Mark McGwire', 'Sammy Sosa' ], 'rbi' => [ 'Sammy Sosa', 'Ken Griffey' ] } python: | [{ 'hr': [ 'Mark McGwire', 'Sammy Sosa' ], 'rbi': [ 'Sammy Sosa', 'Ken Griffey' ] }] ruby: | { 'hr' => [ 'Mark McGwire', 'Sammy Sosa' ], 'rbi' => [ 'Sammy Sosa', 'Ken Griffey' ] } syck: | struct test_node seq1[] = { { T_STR, 0, "Mark McGwire" }, { T_STR, 0, "Sammy Sosa" }, end_node }; struct test_node seq2[] = { { T_STR, 0, "Sammy Sosa" }, { T_STR, 0, "Ken Griffey" }, end_node }; struct test_node map[] = { { T_STR, 0, "hr" }, { T_SEQ, 0, 0, seq1 }, { T_STR, 0, "rbi" }, { T_SEQ, 0, 0, seq2 }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Mapping between sequences spec: 2.11 yaml: | ? # PLAY SCHEDULE - Detroit Tigers - Chicago Cubs : - 2001-07-23 ? [ New York Yankees, Atlanta Braves ] : [ 2001-07-02, 2001-08-12, 2001-08-14 ] ruby: | { [ 'Detroit Tigers', 'Chicago Cubs' ] => [ Date.new( 2001, 7, 23 ) ], [ 'New York Yankees', 'Atlanta Braves' ] => [ Date.new( 2001, 7, 2 ), Date.new( 2001, 8, 12 ), Date.new( 2001, 8, 14 ) ] } syck: | struct test_node seq1[] = { { T_STR, 0, "New York Yankees" }, { T_STR, 0, "Atlanta Braves" }, end_node }; struct test_node seq2[] = { { T_STR, 0, "2001-07-02" }, { T_STR, 0, "2001-08-12" }, { T_STR, 0, "2001-08-14" }, end_node }; struct test_node seq3[] = { { T_STR, 0, "Detroit Tigers" }, { T_STR, 0, "Chicago Cubs" }, end_node }; struct test_node seq4[] = { { T_STR, 0, "2001-07-23" }, end_node }; struct test_node map[] = { { T_SEQ, 0, 0, seq3 }, { T_SEQ, 0, 0, seq4 }, { T_SEQ, 0, 0, seq1 }, { T_SEQ, 0, 0, seq2 }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Sequence key shortcut spec: 2.12 yaml: | --- # products purchased - item : Super Hoop quantity: 1 - item : Basketball quantity: 4 - item : Big Shoes quantity: 1 perl: | [ { item => 'Super Hoop', quantity => 1 }, { item => 'Basketball', quantity => 4 }, { item => 'Big Shoes', quantity => 1 } ] ruby: | [ { 'item' => 'Super Hoop', 'quantity' => 1 }, { 'item' => 'Basketball', 'quantity' => 4 }, { 'item' => 'Big Shoes', 'quantity' => 1 } ] python: | [ { 'item': 'Super Hoop', 'quantity': 1 }, { 'item': 'Basketball', 'quantity': 4 }, { 'item': 'Big Shoes', 'quantity': 1 } ] syck: | struct test_node map1[] = { { T_STR, 0, "item" }, { T_STR, 0, "Super Hoop" }, { T_STR, 0, "quantity" }, { T_STR, 0, "1" }, end_node }; struct test_node map2[] = { { T_STR, 0, "item" }, { T_STR, 0, "Basketball" }, { T_STR, 0, "quantity" }, { T_STR, 0, "4" }, end_node }; struct test_node map3[] = { { T_STR, 0, "item" }, { T_STR, 0, "Big Shoes" }, { T_STR, 0, "quantity" }, { T_STR, 0, "1" }, end_node }; struct test_node seq[] = { { T_MAP, 0, 0, map1 }, { T_MAP, 0, 0, map2 }, { T_MAP, 0, 0, map3 }, end_node }; struct test_node stream[] = { { T_SEQ, 0, 0, seq }, end_node }; --- test: Literal perserves newlines spec: 2.13 yaml: | # ASCII Art --- | \//||\/|| // || ||_ perl: | "\\//||\\/||\n// || ||_\n" ruby: | "\\//||\\/||\n// || ||_\n" python: | [ flushLeft( """ \//||\/|| // || ||_ """ ) ] syck: | struct test_node stream[] = { { T_STR, 0, "\\//||\\/||\n// || ||_\n" }, end_node }; --- test: Folded treats newlines as a space spec: 2.14 yaml: | --- Mark McGwire's year was crippled by a knee injury. perl: | "Mark McGwire's year was crippled by a knee injury." ruby: | "Mark McGwire's year was crippled by a knee injury." python: | [ "Mark McGwire's year was crippled by a knee injury." ] syck: | struct test_node stream[] = { { T_STR, 0, "Mark McGwire's year was crippled by a knee injury." }, end_node }; --- test: Newlines preserved for indented and blank lines spec: 2.15 yaml: | --- > Sammy Sosa completed another fine season with great stats. 63 Home Runs 0.288 Batting Average What a year! perl: | "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n" ruby: | "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n" python: | [ flushLeft( """ Sammy Sosa completed another fine season with great stats. 63 Home Runs 0.288 Batting Average What a year! """ ) ] syck: | struct test_node stream[] = { { T_STR, 0, "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n" }, end_node }; --- test: Indentation determines scope spec: 2.16 yaml: | name: Mark McGwire accomplishment: > Mark set a major league home run record in 1998. stats: | 65 Home Runs 0.278 Batting Average perl: | { name => 'Mark McGwire', accomplishment => "Mark set a major league home run record in 1998.\n", stats => "65 Home Runs\n0.278 Batting Average\n" } ruby: | { 'name' => 'Mark McGwire', 'accomplishment' => "Mark set a major league home run record in 1998.\n", 'stats' => "65 Home Runs\n0.278 Batting Average\n" } python: | [ { 'name': 'Mark McGwire', 'accomplishment': 'Mark set a major league home run record in 1998.\n', 'stats': "65 Home Runs\n0.278 Batting Average\n" } ] syck: | struct test_node map[] = { { T_STR, 0, "name" }, { T_STR, 0, "Mark McGwire" }, { T_STR, 0, "accomplishment" }, { T_STR, 0, "Mark set a major league home run record in 1998.\n" }, { T_STR, 0, "stats" }, { T_STR, 0, "65 Home Runs\n0.278 Batting Average\n" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Quoted scalars spec: 2.17 yaml: | unicode: "Sosa did fine.\u263A" control: "\b1998\t1999\t2000\n" hexesc: "\x0D\x0A is \r\n" single: '"Howdy!" he cried.' quoted: ' # not a ''comment''.' tie-fighter: '|\-*-/|' perl-not-working: | { unicode => "Sosa did fine.\x{263A}", control => "\x081998\t1999\t2000\n", hexesc => "\r\n is \r\n", single => '"Howdy!" he cried.', quoted => " # not a 'comment'.", "tie-fighter" => '|\\-*-/|', } ruby: | { "tie-fighter" => "|\\-*-/|", "control"=>"\0101998\t1999\t2000\n", "unicode"=>"Sosa did fine." + ["263A".hex ].pack('U*'), "quoted"=>" # not a 'comment'.", "single"=>"\"Howdy!\" he cried.", "hexesc"=>"\r\n is \r\n" } python: | [ { 'unicode': u"Sosa did fine.\u263A", 'control': "\b1998\t1999\t2000\n", 'hexesc': "\x0D\x0A is \r\n", 'single': '"Howdy!" he cried.', 'quoted': ' # not a \'comment\'.', 'tie-fighter': '|\-*-/|', } ] --- test: Multiline flow scalars spec: 2.18 yaml: | plain: This unquoted scalar spans many lines. quoted: "So does this quoted scalar.\n" perl-not-working: | { plain => 'This unquoted scalar spans many lines.', quoted => "So does this quoted scalar.\n" } ruby: | { 'plain' => 'This unquoted scalar spans many lines.', 'quoted' => "So does this quoted scalar.\n" } python: | [ { 'plain': 'This unquoted scalar spans many lines.', 'quoted': 'So does this quoted scalar.\n' } ] syck: | struct test_node map[] = { { T_STR, 0, "plain" }, { T_STR, 0, "This unquoted scalar spans many lines." }, { T_STR, 0, "quoted" }, { T_STR, 0, "So does this quoted scalar.\n" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Integers spec: 2.19 yaml: | canonical: 12345 decimal: +12,345 sexagecimal: 3:25:45 octal: 014 hexadecimal: 0xC perl: | { canonical => 12345, decimal => 12345, octal => oct("014"), hexadecimal => hex("0xC"), } ruby: | { 'canonical' => 12345, 'decimal' => 12345, 'sexagecimal' => 12345, 'octal' => '014'.oct, 'hexadecimal' => '0xC'.hex } python: | [ { 'canonical': 12345, 'decimal': 12345, 'octal': 014, 'hexadecimal': 0xC } ] syck: | struct test_node map[] = { { T_STR, 0, "canonical" }, { T_STR, 0, "12345" }, { T_STR, 0, "decimal" }, { T_STR, 0, "+12,345" }, { T_STR, 0, "sexagecimal" }, { T_STR, 0, "3:25:45" }, { T_STR, 0, "octal" }, { T_STR, 0, "014" }, { T_STR, 0, "hexadecimal" }, { T_STR, 0, "0xC" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- # FIX: spec shows parens around -inf and NaN test: Floating point spec: 2.20 yaml: | canonical: 1.23015e+3 exponential: 12.3015e+02 sexagecimal: 20:30.15 fixed: 1,230.15 negative infinity: -.inf not a number: .NaN perl: | { 'canonical' => 1230.15, 'exponential' => 1230.15, 'fixed' => 1230.15, 'negative infinity' => "-.inf", 'not a number' => ".NaN", } ruby: | { 'canonical' => 1230.15, 'exponential' => 1230.15, 'sexagecimal' => 1230.15, 'fixed' => 1230.15, 'negative infinity' => -1.0/0.0, 'not a number' => 0.0/0.0 } if obj_y['not a number'].nan? # NaN comparison doesn't work right against 0.0/0.0 obj_r['not a number'] = obj_y['not a number'] end python: | [ { 'canonical': 1.23015e+3, 'exponential': 1.23015e+3, 'fixed': 1230.15, 'negative infinity': '-.inf', 'not a number': '.NaN', } ] syck: | struct test_node map[] = { { T_STR, 0, "canonical" }, { T_STR, 0, "1.23015e+3" }, { T_STR, 0, "exponential" }, { T_STR, 0, "12.3015e+02" }, { T_STR, 0, "sexagecimal" }, { T_STR, 0, "20:30.15" }, { T_STR, 0, "fixed" }, { T_STR, 0, "1,230.15" }, { T_STR, 0, "negative infinity" }, { T_STR, 0, "-.inf" }, { T_STR, 0, "not a number" }, { T_STR, 0, ".NaN" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Miscellaneous spec: 2.21 yaml: | null: ~ true: y false: n string: '12345' perl: | { null => undef, true => 1, false => 0, string => "12345" } ruby: | { nil => nil, true => true, false => false, 'string' => '12345' } python: | [ { 'null': None, 'true': 1, 'false': 0, 'string': '12345', } ] syck: | struct test_node map[] = { { T_STR, 0, "null" }, { T_STR, 0, "~" }, { T_STR, 0, "true" }, { T_STR, 0, "y" }, { T_STR, 0, "false" }, { T_STR, 0, "n" }, { T_STR, 0, "string" }, { T_STR, 0, "12345" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Timestamps spec: 2.22 yaml: | canonical: 2001-12-15T02:59:43.1Z iso8601: 2001-12-14t21:59:43.10-05:00 spaced: 2001-12-14 21:59:43.10 -05:00 date: 2002-12-14 # Time is noon UTC perl: | { canonical => "2001-12-15T02:59:43.1Z", iso8601 => "2001-12-14t21:59:43.10-05:00", spaced => "2001-12-14 21:59:43.10 -05:00", date => "2002-12-14", } ruby: | { 'canonical' => YAML::mktime( 2001, 12, 15, 2, 59, 43, 0.10 ), 'iso8601' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ), 'spaced' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ), 'date' => Date.new( 2002, 12, 14 ) } syck: | struct test_node map[] = { { T_STR, 0, "canonical" }, { T_STR, 0, "2001-12-15T02:59:43.1Z" }, { T_STR, 0, "iso8601" }, { T_STR, 0, "2001-12-14t21:59:43.10-05:00" }, { T_STR, 0, "spaced" }, { T_STR, 0, "2001-12-14 21:59:43.10 -05:00" }, { T_STR, 0, "date" }, { T_STR, 0, "2002-12-14" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: legacy Timestamps test spec: legacy D4 yaml: | canonical: 2001-12-15T02:59:43.00Z iso8601: 2001-02-28t21:59:43.00-05:00 spaced: 2001-12-14 21:59:43.00 -05:00 date: 2002-12-14 python: | [ { 'canonical': yaml.timestamp('2001-12-15T02:59:43.00Z'), 'iso8601': yaml.timestamp('2001-03-01T02:59:43.00Z'), 'spaced': yaml.timestamp('2001-12-15T02:59:43.00Z'), 'date': yaml.timestamp('2002-12-14T00:00:00.00Z') } ] ruby: | { 'canonical' => Time::utc( 2001, 12, 15, 2, 59, 43, 0 ), 'iso8601' => YAML::mktime( 2001, 2, 28, 21, 59, 43, 0, "-05:00" ), 'spaced' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0, "-05:00" ), 'date' => Date.new( 2002, 12, 14 ) } syck: | struct test_node map[] = { { T_STR, 0, "canonical" }, { T_STR, 0, "2001-12-15T02:59:43.00Z" }, { T_STR, 0, "iso8601" }, { T_STR, 0, "2001-02-28t21:59:43.00-05:00" }, { T_STR, 0, "spaced" }, { T_STR, 0, "2001-12-14 21:59:43.00 -05:00" }, { T_STR, 0, "date" }, { T_STR, 0, "2002-12-14" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Various explicit families spec: 2.23 yaml: | not-date: !str 2002-04-28 picture: !binary | R0lGODlhDAAMAIQAAP//9/X 17unp5WZmZgAAAOfn515eXv Pz7Y6OjuDg4J+fn5OTk6enp 56enmleECcgggoBADs= application specific tag: !!something | The semantics of the tag above may be different for different documents. ruby-setup: | YAML.add_private_type( "something" ) do |type, val| "SOMETHING: #{val}" end ruby: | { 'not-date' => '2002-04-28', 'picture' => "GIF89a\f\000\f\000\204\000\000\377\377\367\365\365\356\351\351\345fff\000\000\000\347\347\347^^^\363\363\355\216\216\216\340\340\340\237\237\237\223\223\223\247\247\247\236\236\236i^\020' \202\n\001\000;", 'application specific tag' => "SOMETHING: The semantics of the tag\nabove may be different for\ndifferent documents.\n" } syck: | struct test_node map[] = { { T_STR, 0, "not-date" }, { T_STR, "tag:yaml.org,2002:str", "2002-04-28" }, { T_STR, 0, "picture" }, { T_STR, "tag:yaml.org,2002:binary", "R0lGODlhDAAMAIQAAP//9/X\n17unp5WZmZgAAAOfn515eXv\nPz7Y6OjuDg4J+fn5OTk6enp\n56enmleECcgggoBADs=\n" }, { T_STR, 0, "application specific tag" }, { T_STR, "x-private:something", "The semantics of the tag\nabove may be different for\ndifferent documents.\n" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Application specific family spec: 2.24 yaml: | # Establish a tag prefix --- !clarkevans.com,2002/graph/^shape # Use the prefix: shorthand for # !clarkevans.com,2002/graph/circle - !^circle center: &ORIGIN {x: 73, 'y': 129} radius: 7 - !^line # !clarkevans.com,2002/graph/line start: *ORIGIN finish: { x: 89, 'y': 102 } - !^label start: *ORIGIN color: 0xFFEEBB value: Pretty vector drawing. ruby-setup: | YAML.add_domain_type( "clarkevans.com,2002", 'graph/shape' ) { |type, val| if Array === val val << "Shape Container" val else raise YAML::Error, "Invalid graph of class #{ val.class }: " + val.inspect end } one_shape_proc = Proc.new { |type, val| scheme, domain, type = type.split( /:/, 3 ) if val.is_a? ::Hash val['TYPE'] = "Shape: #{type}" val else raise YAML::Error, "Invalid graph of class #{ val.class }: " + val.inspect end } YAML.add_domain_type( "clarkevans.com,2002", 'graph/circle', &one_shape_proc ) YAML.add_domain_type( "clarkevans.com,2002", 'graph/line', &one_shape_proc ) YAML.add_domain_type( "clarkevans.com,2002", 'graph/label', &one_shape_proc ) ruby: | [ { "radius" => 7, "center"=> { "x" => 73, "y" => 129 }, "TYPE" => "Shape: graph/circle" }, { "finish" => { "x" => 89, "y" => 102 }, "TYPE" => "Shape: graph/line", "start" => { "x" => 73, "y" => 129 } }, { "TYPE" => "Shape: graph/label", "value" => "Pretty vector drawing.", "start" => { "x" => 73, "y" => 129 }, "color" => 16772795 }, "Shape Container" ] syck: | struct test_node point1[] = { { T_STR, 0, "x" }, { T_STR, 0, "73" }, { T_STR, 0, "y" }, { T_STR, 0, "129" }, end_node }; struct test_node point2[] = { { T_STR, 0, "x" }, { T_STR, 0, "89" }, { T_STR, 0, "y" }, { T_STR, 0, "102" }, end_node }; struct test_node map1[] = { { T_STR, 0, "center" }, { T_MAP, 0, 0, point1 }, { T_STR, 0, "radius" }, { T_STR, 0, "7" }, end_node }; struct test_node map2[] = { { T_STR, 0, "start" }, { T_MAP, 0, 0, point1 }, { T_STR, 0, "finish" }, { T_MAP, 0, 0, point2 }, end_node }; struct test_node map3[] = { { T_STR, 0, "start" }, { T_MAP, 0, 0, point1 }, { T_STR, 0, "color" }, { T_STR, 0, "0xFFEEBB" }, { T_STR, 0, "value" }, { T_STR, 0, "Pretty vector drawing." }, end_node }; struct test_node seq[] = { { T_MAP, "tag:clarkevans.com,2002:graph/circle", 0, map1 }, { T_MAP, "tag:clarkevans.com,2002:graph/line", 0, map2 }, { T_MAP, "tag:clarkevans.com,2002:graph/label", 0, map3 }, end_node }; struct test_node stream[] = { { T_SEQ, "tag:clarkevans.com,2002:graph/shape", 0, seq }, end_node }; # --- # test: Unordered set # spec: 2.25 # yaml: | # # sets are represented as a # # mapping where each key is # # associated with the empty string # --- !set # ? Mark McGwire # ? Sammy Sosa # ? Ken Griff --- test: Ordered mappings spec: 2.26 yaml: | # ordered maps are represented as # a sequence of mappings, with # each mapping having one key --- !omap - Mark McGwire: 65 - Sammy Sosa: 63 - Ken Griffy: 58 ruby: | YAML::Omap[ 'Mark McGwire', 65, 'Sammy Sosa', 63, 'Ken Griffy', 58 ] syck: | struct test_node map1[] = { { T_STR, 0, "Mark McGwire" }, { T_STR, 0, "65" }, end_node }; struct test_node map2[] = { { T_STR, 0, "Sammy Sosa" }, { T_STR, 0, "63" }, end_node }; struct test_node map3[] = { { T_STR, 0, "Ken Griffy" }, { T_STR, 0, "58" }, end_node }; struct test_node seq[] = { { T_MAP, 0, 0, map1 }, { T_MAP, 0, 0, map2 }, { T_MAP, 0, 0, map3 }, end_node }; struct test_node stream[] = { { T_SEQ, "tag:yaml.org,2002:omap", 0, seq }, end_node }; --- test: Invoice spec: 2.27 yaml: | --- !clarkevans.com,2002/^invoice invoice: 34843 date : 2001-01-23 bill-to: &id001 given : Chris family : Dumars address: lines: | 458 Walkman Dr. Suite #292 city : Royal Oak state : MI postal : 48046 ship-to: *id001 product: - sku : BL394D quantity : 4 description : Basketball price : 450.00 - sku : BL4438H quantity : 1 description : Super Hoop price : 2392.00 tax : 251.42 total: 4443.52 comments: > Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. ruby-setup: | YAML.add_domain_type( "clarkevans.com,2002", "invoice" ) { |type, val| val } id001 = { 'given' => 'Chris', 'family' => 'Dumars', 'address' => { 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak', 'state' => 'MI', 'postal' => 48046 } } ruby: | { 'invoice' => 34843, 'date' => Date.new( 2001, 1, 23 ), 'bill-to' => id001, 'ship-to' => id001, 'product' => [ { 'sku' => 'BL394D', 'quantity' => 4, 'description' => 'Basketball', 'price' => 450.00 }, { 'sku' => 'BL4438H', 'quantity' => 1, 'description' => 'Super Hoop', 'price' => 2392.00 } ], 'tax' => 251.42, 'total' => 4443.52, 'comments' => "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n" } syck: | struct test_node prod1[] = { { T_STR, 0, "sku" }, { T_STR, 0, "BL394D" }, { T_STR, 0, "quantity" }, { T_STR, 0, "4" }, { T_STR, 0, "description" }, { T_STR, 0, "Basketball" }, { T_STR, 0, "price" }, { T_STR, 0, "450.00" }, end_node }; struct test_node prod2[] = { { T_STR, 0, "sku" }, { T_STR, 0, "BL4438H" }, { T_STR, 0, "quantity" }, { T_STR, 0, "1" }, { T_STR, 0, "description" }, { T_STR, 0, "Super Hoop" }, { T_STR, 0, "price" }, { T_STR, 0, "2392.00" }, end_node }; struct test_node products[] = { { T_MAP, 0, 0, prod1 }, { T_MAP, 0, 0, prod2 }, end_node }; struct test_node address[] = { { T_STR, 0, "lines" }, { T_STR, 0, "458 Walkman Dr.\nSuite #292\n" }, { T_STR, 0, "city" }, { T_STR, 0, "Royal Oak" }, { T_STR, 0, "state" }, { T_STR, 0, "MI" }, { T_STR, 0, "postal" }, { T_STR, 0, "48046" }, end_node }; struct test_node id001[] = { { T_STR, 0, "given" }, { T_STR, 0, "Chris" }, { T_STR, 0, "family" }, { T_STR, 0, "Dumars" }, { T_STR, 0, "address" }, { T_MAP, 0, 0, address }, end_node }; struct test_node map[] = { { T_STR, 0, "invoice" }, { T_STR, 0, "34843" }, { T_STR, 0, "date" }, { T_STR, 0, "2001-01-23" }, { T_STR, 0, "bill-to" }, { T_MAP, 0, 0, id001 }, { T_STR, 0, "ship-to" }, { T_MAP, 0, 0, id001 }, { T_STR, 0, "product" }, { T_SEQ, 0, 0, products }, { T_STR, 0, "tax" }, { T_STR, 0, "251.42" }, { T_STR, 0, "total" }, { T_STR, 0, "4443.52" }, { T_STR, 0, "comments" }, { T_STR, 0, "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n" }, end_node }; struct test_node stream[] = { { T_MAP, "tag:clarkevans.com,2002:invoice", 0, map }, end_node }; --- test: Log file spec: 2.28 yaml: | --- Time: 2001-11-23 15:01:42 -05:00 User: ed Warning: > This is an error message for the log file --- Time: 2001-11-23 15:02:31 -05:00 User: ed Warning: > A slightly different error message. --- Date: 2001-11-23 15:03:17 -05:00 User: ed Fatal: > Unknown variable "bar" Stack: - file: TopClass.py line: 23 code: | x = MoreObject("345\n") - file: MoreClass.py line: 58 code: |- foo = bar ruby: | y = YAML::Stream.new y.add( { 'Time' => YAML::mktime( 2001, 11, 23, 15, 01, 42, 00, "-05:00" ), 'User' => 'ed', 'Warning' => "This is an error message for the log file\n" } ) y.add( { 'Time' => YAML::mktime( 2001, 11, 23, 15, 02, 31, 00, "-05:00" ), 'User' => 'ed', 'Warning' => "A slightly different error message.\n" } ) y.add( { 'Date' => YAML::mktime( 2001, 11, 23, 15, 03, 17, 00, "-05:00" ), 'User' => 'ed', 'Fatal' => "Unknown variable \"bar\"\n", 'Stack' => [ { 'file' => 'TopClass.py', 'line' => 23, 'code' => "x = MoreObject(\"345\\n\")\n" }, { 'file' => 'MoreClass.py', 'line' => 58, 'code' => "foo = bar" } ] } ) syck: | struct test_node map1[] = { { T_STR, 0, "Time" }, { T_STR, 0, "2001-11-23 15:01:42 -05:00" }, { T_STR, 0, "User" }, { T_STR, 0, "ed" }, { T_STR, 0, "Warning" }, { T_STR, 0, "This is an error message for the log file\n" }, end_node }; struct test_node map2[] = { { T_STR, 0, "Time" }, { T_STR, 0, "2001-11-23 15:02:31 -05:00" }, { T_STR, 0, "User" }, { T_STR, 0, "ed" }, { T_STR, 0, "Warning" }, { T_STR, 0, "A slightly different error message.\n" }, end_node }; struct test_node file1[] = { { T_STR, 0, "file" }, { T_STR, 0, "TopClass.py" }, { T_STR, 0, "line" }, { T_STR, 0, "23" }, { T_STR, 0, "code" }, { T_STR, 0, "x = MoreObject(\"345\\n\")\n" }, end_node }; struct test_node file2[] = { { T_STR, 0, "file" }, { T_STR, 0, "MoreClass.py" }, { T_STR, 0, "line" }, { T_STR, 0, "58" }, { T_STR, 0, "code" }, { T_STR, 0, "foo = bar" }, end_node }; struct test_node stack[] = { { T_MAP, 0, 0, file1 }, { T_MAP, 0, 0, file2 }, end_node }; struct test_node map3[] = { { T_STR, 0, "Date" }, { T_STR, 0, "2001-11-23 15:03:17 -05:00" }, { T_STR, 0, "User" }, { T_STR, 0, "ed" }, { T_STR, 0, "Fatal" }, { T_STR, 0, "Unknown variable \"bar\"\n" }, { T_STR, 0, "Stack" }, { T_SEQ, 0, 0, stack }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map1 }, { T_MAP, 0, 0, map2 }, { T_MAP, 0, 0, map3 }, end_node }; documents: 3 --- test: Throwaway comments yaml: | ### These are four throwaway comment ### ### lines (the second line is empty). ### this: | # Comments may trail lines. contains three lines of text. The third one starts with a # character. This isn't a comment. # These are three throwaway comment # lines (the first line is empty). ruby: | { 'this' => "contains three lines of text.\nThe third one starts with a\n# character. This isn't a comment.\n" } syck: | struct test_node map[] = { { T_STR, 0, "this" }, { T_STR, 0, "contains three lines of text.\nThe third one starts with a\n# character. This isn't a comment.\n" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Document with a single value yaml: | --- > This YAML stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end. ruby: | "This YAML stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end.\n" syck: | struct test_node stream[] = { { T_STR, 0, "This YAML stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end.\n" }, end_node }; --- test: Document stream yaml: | --- at: 2001-08-12 09:25:00.00 Z type: GET HTTP: '1.0' url: '/index.html' --- at: 2001-08-12 09:25:10.00 Z type: GET HTTP: '1.0' url: '/toc.html' ruby: | y = YAML::Stream.new y.add( { 'at' => Time::utc( 2001, 8, 12, 9, 25, 00 ), 'type' => 'GET', 'HTTP' => '1.0', 'url' => '/index.html' } ) y.add( { 'at' => Time::utc( 2001, 8, 12, 9, 25, 10 ), 'type' => 'GET', 'HTTP' => '1.0', 'url' => '/toc.html' } ) syck: | struct test_node map1[] = { { T_STR, 0, "at" }, { T_STR, 0, "2001-08-12 09:25:00.00 Z" }, { T_STR, 0, "type" }, { T_STR, 0, "GET" }, { T_STR, 0, "HTTP" }, { T_STR, 0, "1.0" }, { T_STR, 0, "url" }, { T_STR, 0, "/index.html" }, end_node }; struct test_node map2[] = { { T_STR, 0, "at" }, { T_STR, 0, "2001-08-12 09:25:10.00 Z" }, { T_STR, 0, "type" }, { T_STR, 0, "GET" }, { T_STR, 0, "HTTP" }, { T_STR, 0, "1.0" }, { T_STR, 0, "url" }, { T_STR, 0, "/toc.html" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map1 }, { T_MAP, 0, 0, map2 }, end_node }; documents: 2 --- test: Top level mapping yaml: | # This stream is an example of a top-level mapping. invoice : 34843 date : 2001-01-23 total : 4443.52 ruby: | { 'invoice' => 34843, 'date' => Date.new( 2001, 1, 23 ), 'total' => 4443.52 } syck: | struct test_node map[] = { { T_STR, 0, "invoice" }, { T_STR, 0, "34843" }, { T_STR, 0, "date" }, { T_STR, 0, "2001-01-23" }, { T_STR, 0, "total" }, { T_STR, 0, "4443.52" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Single-line documents yaml: | # The following is a sequence of three documents. # The first contains an empty mapping, the second # an empty sequence, and the last an empty string. --- {} --- [ ] --- '' ruby: | y = YAML::Stream.new y.add( {} ) y.add( [] ) y.add( '' ) syck: | struct test_node map[] = { end_node }; struct test_node seq[] = { end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, { T_SEQ, 0, 0, seq }, { T_STR, 0, "" }, end_node }; documents: 3 --- test: Document with pause yaml: | # A communication channel based on a YAML stream. --- sent at: 2002-06-06 11:46:25.10 Z payload: Whatever # Receiver can process this as soon as the following is sent: ... # Even if the next message is sent long after: --- sent at: 2002-06-06 12:05:53.47 Z payload: Whatever ... ruby: | y = YAML::Stream.new y.add( { 'sent at' => YAML::mktime( 2002, 6, 6, 11, 46, 25, 0.10 ), 'payload' => 'Whatever' } ) y.add( { "payload" => "Whatever", "sent at" => YAML::mktime( 2002, 6, 6, 12, 5, 53, 0.47 ) } ) syck: | struct test_node map1[] = { { T_STR, 0, "sent at" }, { T_STR, 0, "2002-06-06 11:46:25.10 Z" }, { T_STR, 0, "payload" }, { T_STR, 0, "Whatever" }, end_node }; struct test_node map2[] = { { T_STR, 0, "sent at" }, { T_STR, 0, "2002-06-06 12:05:53.47 Z" }, { T_STR, 0, "payload" }, { T_STR, 0, "Whatever" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map1 }, { T_MAP, 0, 0, map2 }, end_node }; documents: 2 --- test: Explicit typing yaml: | integer: 12 also int: ! "12" string: !str 12 ruby: | { 'integer' => 12, 'also int' => 12, 'string' => '12' } syck: | struct test_node map[] = { { T_STR, 0, "integer" }, { T_STR, "tag:yaml.org,2002:int", "12" }, { T_STR, 0, "also int" }, { T_STR, "tag:yaml.org,2002:int", "12" }, { T_STR, 0, "string" }, { T_STR, "tag:yaml.org,2002:str", "12" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Private types yaml: | # Both examples below make use of the 'x-private:ball' # type family URI, but with different semantics. --- pool: !!ball number: 8 color: black --- bearing: !!ball material: steel ruby: | y = YAML::Stream.new y.add( { 'pool' => YAML::PrivateType.new( 'ball', { 'number' => 8, 'color' => 'black' } ) } ) y.add( { 'bearing' => YAML::PrivateType.new( 'ball', { 'material' => 'steel' } ) } ) syck: | struct test_node pool[] = { { T_STR, 0, "number" }, { T_STR, 0, "8" }, { T_STR, 0, "color" }, { T_STR, 0, "black" }, end_node }; struct test_node map1[] = { { T_STR, 0, "pool" }, { T_MAP, "x-private:ball", 0, pool }, end_node }; struct test_node bearing[] = { { T_STR, 0, "material" }, { T_STR, 0, "steel" }, end_node }; struct test_node map2[] = { { T_STR, 0, "bearing" }, { T_MAP, "x-private:ball", 0, bearing }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map1 }, { T_MAP, 0, 0, map2 }, end_node }; documents: 2 --- test: Type family under yaml.org yaml: | # The URI is 'tag:yaml.org,2002:str' - !str a Unicode string python: | [ [ 'a Unicode string' ] ] ruby: | [ 'a Unicode string' ] syck: | struct test_node seq[] = { { T_STR, "tag:yaml.org,2002:str", "a Unicode string" }, end_node }; struct test_node stream[] = { { T_SEQ, 0, 0, seq }, end_node }; --- test: Type family under perl.yaml.org yaml: | # The URI is 'tag:perl.yaml.org,2002:Text::Tabs' - !perl/Text::Tabs {} ruby: | [ YAML::DomainType.new( 'perl.yaml.org,2002', 'Text::Tabs', {} ) ] syck: | struct test_node map[] = { end_node }; struct test_node seq[] = { { T_MAP, "tag:perl.yaml.org,2002:Text::Tabs", 0, map }, end_node }; struct test_node stream[] = { { T_SEQ, 0, 0, seq }, end_node }; --- test: Type family under clarkevans.com yaml: | # The URI is 'tag:clarkevans.com,2003-02:timesheet' - !clarkevans.com,2003-02/timesheet {} ruby: | [ YAML::DomainType.new( 'clarkevans.com,2003-02', 'timesheet', {} ) ] syck: | struct test_node map[] = { end_node }; struct test_node seq[] = { { T_MAP, "tag:clarkevans.com,2003-02:timesheet", 0, map }, end_node }; struct test_node stream[] = { { T_SEQ, 0, 0, seq }, end_node }; --- test: URI Escaping yaml: | same: - !domain.tld,2002/type\x30 value - !domain.tld,2002/type0 value different: # As far as the YAML parser is concerned - !domain.tld,2002/type%30 value - !domain.tld,2002/type0 value ruby-setup: | YAML.add_domain_type( "domain.tld,2002", "type0" ) { |type, val| "ONE: #{val}" } YAML.add_domain_type( "domain.tld,2002", "type%30" ) { |type, val| "TWO: #{val}" } ruby: | { 'same' => [ 'ONE: value', 'ONE: value' ], 'different' => [ 'TWO: value', 'ONE: value' ] } syck: | struct test_node same[] = { { T_STR, "tag:domain.tld,2002:type0", "value" }, { T_STR, "tag:domain.tld,2002:type0", "value" }, end_node }; struct test_node diff[] = { { T_STR, "tag:domain.tld,2002:type%30", "value" }, { T_STR, "tag:domain.tld,2002:type0", "value" }, end_node }; struct test_node map[] = { { T_STR, 0, "same" }, { T_SEQ, 0, 0, same }, { T_STR, 0, "different" }, { T_SEQ, 0, 0, diff }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: URI Prefixing yaml: | # 'tag:domain.tld,2002:invoice' is some type family. invoice: !domain.tld,2002/^invoice # 'seq' is shorthand for 'tag:yaml.org,2002:seq'. # This does not effect '^customer' below # because it is does not specify a prefix. customers: !seq # '^customer' is shorthand for the full # notation 'tag:domain.tld,2002:customer'. - !^customer given : Chris family : Dumars ruby-setup: | YAML.add_domain_type( "domain.tld,2002", /(invoice|customer)/ ) { |type, val| if val.is_a? ::Hash scheme, domain, type = type.split( /:/, 3 ) val['type'] = "domain #{type}" val else raise YAML::Error, "Not a Hash in domain.tld/invoice: " + val.inspect end } ruby: | { "invoice"=> { "customers"=> [ { "given"=>"Chris", "type"=>"domain customer", "family"=>"Dumars" } ], "type"=>"domain invoice" } } --- test: Overriding anchors yaml: | anchor : &A001 This scalar has an anchor. override : &A001 > The alias node below is a repeated use of this value. alias : *A001 ruby: | { 'anchor' => 'This scalar has an anchor.', 'override' => "The alias node below is a repeated use of this value.\n", 'alias' => "The alias node below is a repeated use of this value.\n" } syck: | struct test_node map[] = { { T_STR, 0, "anchor" }, { T_STR, 0, "This scalar has an anchor." }, { T_STR, 0, "override" }, { T_STR, 0, "The alias node below is a repeated use of this value.\n" }, { T_STR, 0, "alias" }, { T_STR, 0, "The alias node below is a repeated use of this value.\n" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Flow and block formatting yaml: | empty: [] flow: [ one, two, three # May span lines, , four, # indentation is five ] # mostly ignored. block: - First item in top sequence - - Subordinate sequence entry - > A folded sequence entry - Sixth item in top sequence ruby: | { 'empty' => [], 'flow' => [ 'one', 'two', 'three', 'four', 'five' ], 'block' => [ 'First item in top sequence', [ 'Subordinate sequence entry' ], "A folded sequence entry\n", 'Sixth item in top sequence' ] } syck: | struct test_node empty[] = { end_node }; struct test_node flow[] = { { T_STR, 0, "one" }, { T_STR, 0, "two" }, { T_STR, 0, "three" }, { T_STR, 0, "four" }, { T_STR, 0, "five" }, end_node }; struct test_node inblock[] = { { T_STR, 0, "Subordinate sequence entry" }, end_node }; struct test_node block[] = { { T_STR, 0, "First item in top sequence" }, { T_SEQ, 0, 0, inblock }, { T_STR, 0, "A folded sequence entry\n" }, { T_STR, 0, "Sixth item in top sequence" }, end_node }; struct test_node map[] = { { T_STR, 0, "empty" }, { T_SEQ, 0, 0, empty }, { T_STR, 0, "flow" }, { T_SEQ, 0, 0, flow }, { T_STR, 0, "block" }, { T_SEQ, 0, 0, block }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Complete mapping test yaml: | empty: {} flow: { one: 1, two: 2 } spanning: { one: 1, two: 2 } block: first : First entry second: key: Subordinate mapping third: - Subordinate sequence - { } - Previous mapping is empty. - A key: value pair in a sequence. A second: key:value pair. - The previous entry is equal to the following one. - A key: value pair in a sequence. A second: key:value pair. !float 12 : This key is a float. ? > ? : This key had to be protected. "\a" : This key had to be escaped. ? > This is a multi-line folded key : Whose value is also multi-line. ? this also works as a key : with a value at the next line. ? - This key - is a sequence : - With a sequence value. ? This: key is a: mapping : with a: mapping value. ruby: | { 'empty' => {}, 'flow' => { 'one' => 1, 'two' => 2 }, 'spanning' => { 'one' => 1, 'two' => 2 }, 'block' => { 'first' => 'First entry', 'second' => { 'key' => 'Subordinate mapping' }, 'third' => [ 'Subordinate sequence', {}, 'Previous mapping is empty.', { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' }, 'The previous entry is equal to the following one.', { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' } ], 12.0 => 'This key is a float.', "?\n" => 'This key had to be protected.', "\a" => 'This key had to be escaped.', "This is a multi-line folded key\n" => "Whose value is also multi-line.", 'this also works as a key' => 'with a value at the next line.', [ 'This key', 'is a sequence' ] => [ 'With a sequence value.' ] } } # Couldn't recreate map exactly, so we'll do a detailed check to be sure it's entact obj_y['block'].keys.each { |k| if Hash === k v = obj_y['block'][k] if k['This'] == 'key' and k['is a'] == 'mapping' and v['with a'] == 'mapping value.' obj_r['block'][k] = v end end } --- test: Literal explicit indentation yaml: | # Explicit indentation must # be given in all the three # following cases. leading spaces: |2 This value starts with four spaces. leading line break: |2 This value starts with a line break. leading comment indicator: |2 # first line starts with a # character. # Explicit indentation may # also be given when it is # not required. redundant: |2 This value is indented 2 spaces. ruby: | { 'leading spaces' => " This value starts with four spaces.\n", 'leading line break' => "\nThis value starts with a line break.\n", 'leading comment indicator' => "# first line starts with a\n# character.\n", 'redundant' => "This value is indented 2 spaces.\n" } --- test: Chomping and keep modifiers yaml: | clipped: | This has one newline. same as "clipped" above: "This has one newline.\n" stripped: |- This has no newline. same as "stripped" above: "This has no newline." kept: |+ This has two newlines. same as "kept" above: "This has two newlines.\n\n" ruby: | { 'clipped' => "This has one newline.\n", 'same as "clipped" above' => "This has one newline.\n", 'stripped' => 'This has no newline.', 'same as "stripped" above' => 'This has no newline.', 'kept' => "This has two newlines.\n\n", 'same as "kept" above' => "This has two newlines.\n\n" } --- test: Literal combinations yaml: | empty: | literal: | The \ ' " characters may be freely used. Leading white space is significant. Line breaks are significant. Thus this value contains one empty line and ends with a single line break, but does not start with one. is equal to: "The \\ ' \" characters may \ be\nfreely used. Leading white\n space \ is significant.\n\nLine breaks are \ significant.\nThus this value contains \ one\nempty line and ends with a\nsingle \ line break, but does\nnot start with one.\n" # Comments may follow a block # scalar value. They must be # less indented. # Modifiers may be combined in any order. indented and chomped: |2- This has no newline. also written as: |-2 This has no newline. both are equal to: " This has no newline." ruby: | { 'empty' => '', 'literal' => "The \\ ' \" characters may be\nfreely used. Leading white\n space " + "is significant.\n\nLine breaks are significant.\nThus this value contains one\n" + "empty line and ends with a\nsingle line break, but does\nnot start with one.\n", 'is equal to' => "The \\ ' \" characters may be\nfreely used. Leading white\n space " + "is significant.\n\nLine breaks are significant.\nThus this value contains one\n" + "empty line and ends with a\nsingle line break, but does\nnot start with one.\n", 'indented and chomped' => ' This has no newline.', 'also written as' => ' This has no newline.', 'both are equal to' => ' This has no newline.' } syck: | struct test_node map[] = { { T_STR, 0, "empty" }, { T_STR, 0, "" }, { T_STR, 0, "literal" }, { T_STR, 0, "The \\ ' \" characters may be\nfreely used. Leading white\n space " "is significant.\n\nLine breaks are significant.\nThus this value contains one\n" "empty line and ends with a\nsingle line break, but does\nnot start with one.\n" }, { T_STR, 0, "is equal to" }, { T_STR, 0, "The \\ ' \" characters may be\nfreely used. Leading white\n space " "is significant.\n\nLine breaks are significant.\nThus this value contains one\n" "empty line and ends with a\nsingle line break, but does\nnot start with one.\n" }, { T_STR, 0, "indented and chomped" }, { T_STR, 0, " This has no newline." }, { T_STR, 0, "also written as" }, { T_STR, 0, " This has no newline." }, { T_STR, 0, "both are equal to" }, { T_STR, 0, " This has no newline." }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Folded combinations yaml: | empty: > one paragraph: > Line feeds are converted to spaces, so this value contains no line breaks except for the final one. multiple paragraphs: >2 An empty line, either at the start or in the value: Is interpreted as a line break. Thus this value contains three line breaks. indented text: > This is a folded paragraph followed by a list: * first entry * second entry Followed by another folded paragraph, another list: * first entry * second entry And a final folded paragraph. above is equal to: | This is a folded paragraph followed by a list: * first entry * second entry Followed by another folded paragraph, another list: * first entry * second entry And a final folded paragraph. # Explicit comments may follow # but must be less indented. ruby: | { 'empty' => '', 'one paragraph' => 'Line feeds are converted to spaces, so this value' + " contains no line breaks except for the final one.\n", 'multiple paragraphs' => "\nAn empty line, either at the start or in the value:\n" + "Is interpreted as a line break. Thus this value contains three line breaks.\n", 'indented text' => "This is a folded paragraph followed by a list:\n" + " * first entry\n * second entry\nFollowed by another folded paragraph, " + "another list:\n\n * first entry\n\n * second entry\n\nAnd a final folded paragraph.\n", 'above is equal to' => "This is a folded paragraph followed by a list:\n" + " * first entry\n * second entry\nFollowed by another folded paragraph, " + "another list:\n\n * first entry\n\n * second entry\n\nAnd a final folded paragraph.\n" } --- test: Single quotes yaml: | empty: '' second: '! : \ etc. can be used freely.' third: 'a single quote '' must be escaped.' span: 'this contains six spaces and one line break' is same as: "this contains six spaces\nand one line break" ruby: | { 'empty' => '', 'second' => '! : \\ etc. can be used freely.', 'third' => "a single quote ' must be escaped.", 'span' => "this contains six spaces\nand one line break", 'is same as' => "this contains six spaces\nand one line break" } --- test: Double quotes yaml: | empty: "" second: "! : etc. can be used freely." third: "a \" or a \\ must be escaped." fourth: "this value ends with an LF.\n" span: "this contains four \ spaces" is equal to: "this contains four spaces" ruby: | { 'empty' => '', 'second' => '! : etc. can be used freely.', 'third' => 'a " or a \\ must be escaped.', 'fourth' => "this value ends with an LF.\n", 'span' => "this contains four spaces", 'is equal to' => "this contains four spaces" } --- test: Unquoted strings yaml: | first: There is no unquoted empty string. second: 12 ## This is an integer. third: !str 12 ## This is a string. span: this contains six spaces and one line break indicators: this has no comments. #:foo and bar# are both text. flow: [ can span lines, # comment like this ] note: { one-line keys: but multi-line values } ruby: | { 'first' => 'There is no unquoted empty string.', 'second' => 12, 'third' => '12', 'span' => "this contains six spaces\nand one line break", 'indicators' => "this has no comments. #:foo and bar# are both text.", 'flow' => [ 'can span lines', 'like this' ], 'note' => { 'one-line keys' => 'but multi-line values' } } --- test: Spanning sequences yaml: | # The following are equal seqs # with different identities. flow: [ one, two ] spanning: [ one, two ] block: - one - two ruby: | { 'flow' => [ 'one', 'two' ], 'spanning' => [ 'one', 'two' ], 'block' => [ 'one', 'two' ] } --- test: Flow mappings yaml: | # The following are equal maps # with different identities. flow: { one: 1, two: 2 } block: one: 1 two: 2 ruby: | { 'flow' => { 'one' => 1, 'two' => 2 }, 'block' => { 'one' => 1, 'two' => 2 } } --- test: Representations of 12 yaml: | - 12 # An integer # The following scalars # are loaded to the # string value '1' '2'. - !str 12 - '12' - "12" - "\ 1\ 2\ " # Strings containing paths and regexps can be unquoted: - /foo/bar - d:/foo/bar - foo/bar - /a.*b/ ruby: | [ 12, '12', '12', '12', '12', '/foo/bar', 'd:/foo/bar', 'foo/bar', '/a.*b/' ] --- test: "Null" yaml: | canonical: ~ english: null # This sequence has five # entries, two with values. sparse: - ~ - 2nd entry - Null - 4th entry - four: This mapping has five keys, only two with values. ruby: | { 'canonical' => nil, 'english' => nil, 'sparse' => [ nil, '2nd entry', nil, '4th entry', nil ], 'four' => 'This mapping has five keys, only two with values.' } --- test: Omap yaml: | # Explicitly typed dictionary. Bestiary: !omap - aardvark: African pig-like ant eater. Ugly. - anteater: South-American ant eater. Two species. - anaconda: South-American constrictor snake. Scary. # Etc. ruby: | { 'Bestiary' => YAML::Omap[ 'aardvark', 'African pig-like ant eater. Ugly.', 'anteater', 'South-American ant eater. Two species.', 'anaconda', 'South-American constrictor snake. Scary.' ] } --- test: Pairs yaml: | # Explicitly typed pairs. tasks: !pairs - meeting: with team. - meeting: with boss. - break: lunch. - meeting: with client. ruby: | { 'tasks' => YAML::Pairs[ 'meeting', 'with team.', 'meeting', 'with boss.', 'break', 'lunch.', 'meeting', 'with client.' ] } --- test: Set yaml: | # Explicitly typed set. baseball players: !set Mark McGwire: Sammy Sosa: Ken Griffey: ruby: | { 'baseball players' => YAML::Set[ 'Mark McGwire', nil, 'Sammy Sosa', nil, 'Ken Griffey', nil ] } --- test: Boolean yaml: | false: used as key logical: true answer: no ruby: | { false => 'used as key', 'logical' => true, 'answer' => false } --- test: Integer yaml: | canonical: 12345 decimal: +12,345 octal: 014 hexadecimal: 0xC ruby: | { 'canonical' => 12345, 'decimal' => 12345, 'octal' => 12, 'hexadecimal' => 12 } --- test: Float yaml: | canonical: 1.23015e+3 exponential: 12.3015e+02 fixed: 1,230.15 negative infinity: -.inf not a number: .NaN ruby: | { 'canonical' => 1230.15, 'exponential' => 1230.15, 'fixed' => 1230.15, 'negative infinity' => -1.0/0.0, 'not a number' => 0.0/0.0 } if obj_y['not a number'].nan? # NaN comparison doesn't work right against 0.0/0.0 obj_r['not a number'] = obj_y['not a number'] end --- test: Timestamp yaml: | canonical: 2001-12-15T02:59:43.1Z valid iso8601: 2001-12-14t21:59:43.10-05:00 space separated: 2001-12-14 21:59:43.10 -05:00 date (noon UTC): 2002-12-14 ruby: | { 'canonical' => YAML::mktime( 2001, 12, 15, 2, 59, 43, 0.10 ), 'valid iso8601' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ), 'space separated' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ), 'date (noon UTC)' => Date.new( 2002, 12, 14 ) } syck: | struct test_node map[] = { { T_STR, 0, "canonical" }, { T_STR, 0, "2001-12-15T02:59:43.1Z" }, { T_STR, 0, "valid iso8601" }, { T_STR, 0, "2001-12-14t21:59:43.10-05:00" }, { T_STR, 0, "space separated" }, { T_STR, 0, "2001-12-14 21:59:43.10 -05:00" }, { T_STR, 0, "date (noon UTC)" }, { T_STR, 0, "2002-12-14" }, end_node }; struct test_node stream[] = { { T_MAP, 0, 0, map }, end_node }; --- test: Binary yaml: | canonical: !binary "\ R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5\ OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+\ +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC\ AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=" base64: !binary | R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5 OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+ +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs= description: > The binary value above is a tiny arrow encoded as a gif image. ruby-setup: | arrow_gif = "GIF89a\f\000\f\000\204\000\000\377\377\367\365\365\356\351\351\345fff\000\000\000\347\347\347^^^\363\363\355\216\216\216\340\340\340\237\237\237\223\223\223\247\247\247\236\236\236iiiccc\243\243\243\204\204\204\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371!\376\016Made with GIMP\000,\000\000\000\000\f\000\f\000\000\005, \216\2010\236\343@\024\350i\020\304\321\212\010\034\317\200M$z\357\3770\205p\270\2601f\r\e\316\001\303\001\036\020' \202\n\001\000;" ruby: | { 'canonical' => arrow_gif, 'base64' => arrow_gif, 'description' => "The binary value above is a tiny arrow encoded as a gif image.\n" } --- test: Merge key yaml: | --- - &CENTER { x: 1, y: 2 } - &LEFT { x: 0, y: 2 } - &BIG { r: 10 } - &SMALL { r: 1 } # All the following maps are equal: - # Explicit keys x: 1 y: 2 r: 10 label: center/big - # Merge one map << : *CENTER r: 10 label: center/big - # Merge multiple maps << : [ *CENTER, *BIG ] label: center/big - # Override << : [ *BIG, *LEFT, *SMALL ] x: 1 label: center/big ruby-setup: | center = { 'x' => 1, 'y' => 2 } left = { 'x' => 0, 'y' => 2 } big = { 'r' => 10 } small = { 'r' => 1 } node1 = { 'x' => 1, 'y' => 2, 'r' => 10, 'label' => 'center/big' } node2 = center.dup node2.update( { 'r' => 10, 'label' => 'center/big' } ) node3 = big.dup node3.update( center ) node3.update( { 'label' => 'center/big' } ) node4 = small.dup node4.update( left ) node4.update( big ) node4.update( { 'x' => 1, 'label' => 'center/big' } ) ruby: | [ center, left, big, small, node1, node2, node3, node4 ] --- test: Default key yaml: | --- # Old schema link with: - library1.dll - library2.dll --- # New schema link with: - = : library1.dll version: 1.2 - = : library2.dll version: 2.3 ruby: | y = YAML::Stream.new y.add( { 'link with' => [ 'library1.dll', 'library2.dll' ] } ) obj_h = Hash[ 'version' => 1.2 ] obj_h.default = 'library1.dll' obj_h2 = Hash[ 'version' => 2.3 ] obj_h2.default = 'library2.dll' y.add( { 'link with' => [ obj_h, obj_h2 ] } ) documents: 2 --- test: Special keys yaml: | "!": These three keys "&": had to be quoted "=": and are normal strings. # NOTE: the following node should NOT be serialized this way. encoded node : !special '!' : '!type' !special|canonical '&' : 12 = : value # The proper way to serialize the above node is as follows: node : !!type &12 value ruby: | { '!' => 'These three keys', '&' => 'had to be quoted', '=' => 'and are normal strings.', 'encoded node' => YAML::PrivateType.new( 'type', 'value' ), 'node' => YAML::PrivateType.new( 'type', 'value' ) } yecht-yecht-1.1/ext/ruby/yts/YtsTypeTransfers.yml000066400000000000000000000161271262256356000222530ustar00rootroot00000000000000--- %YAML:1.0 test: Strings brief: > Any group of characters beginning with an alphabetic or numeric character is a string, unless it belongs to one of the groups below (such as an Integer or Time). yaml: | --- String ruby: | 'String' --- test: String characters brief: > A string can contain any alphabetic or numeric character, along with many punctuation characters, including the period, dash, space, quotes, exclamation, and question mark. yaml: | - What's Yaml? - It's for writing data structures in plain text. - And? - And what? That's not good enough for you? - No, I mean, "And what about Yaml?" - Oh, oh yeah. Uh.. Yaml for Ruby. ruby: | [ "What's Yaml?", "It's for writing data structures in plain text.", "And?", "And what? That's not good enough for you?", "No, I mean, \"And what about Yaml?\"", "Oh, oh yeah. Uh.. Yaml for Ruby." ] --- test: Indicators in Strings brief: > Be careful using indicators in strings. In particular, the comma, colon, and pound sign must be used carefully. yaml: | the colon followed by space is an indicator: but is a string:right here same for the pound sign: here we have it#in a string the comma can, honestly, be used in most cases: [ but not in, inline collections ] ruby: | { 'the colon followed by space is an indicator' => 'but is a string:right here', 'same for the pound sign' => 'here we have it#in a string', 'the comma can, honestly, be used in most cases' => [ 'but not in', 'inline collections' ] } --- test: Forcing Strings brief: > Any YAML type can be forced into a string using the explicit !str method. yaml: | date string: !str 2001-08-01 number string: !str 192 ruby: | { 'date string' => '2001-08-01', 'number string' => '192' } --- test: Single-quoted Strings brief: > You can also enclose your strings within single quotes, which allows use of slashes, colons, and other indicators freely. Inside single quotes, you can represent a single quote in your string by using two single quotes next to each other. yaml: | all my favorite symbols: '#:!/%.)' a few i hate: '&(*' why do i hate them?: 'it''s very hard to explain' ruby: | { 'all my favorite symbols' => '#:!/%.)', 'a few i hate' => '&(*', 'why do i hate them?' => 'it\'s very hard to explain' } --- test: Double-quoted Strings brief: > Enclosing strings in double quotes allows you to use escapings to represent ASCII and Unicode characters. yaml: | i know where i want my line breaks: "one here\nand another here\n" ruby: | { 'i know where i want my line breaks' => "one here\nand another here\n" } --- test: Multi-line Quoted Strings brief: > Both single- and double-quoted strings may be carried on to new lines in your YAML document. They must be indented a step and indentation is interpreted as a single space. yaml: | i want a long string: "so i'm going to let it go on and on to other lines until i end it with a quote." ruby: | { 'i want a long string' => "so i'm going to " + "let it go on and on to other lines " + "until i end it with a quote." } --- test: Plain scalars brief: > Unquoted strings may also span multiple lines, if they are free of YAML space indicators and indented. yaml: | - My little toe is broken in two places; - I'm crazy to have skied this way; - I'm not the craziest he's seen, since there was always the German guy who skied for 3 hours on a broken shin bone (just below the kneecap); - Nevertheless, second place is respectable, and he doesn't recommend going for the record; - He's going to put my foot in plaster for a month; - This would impair my skiing ability somewhat for the duration, as can be imagined. ruby: | [ "My little toe is broken in two places;", "I'm crazy to have skied this way;", "I'm not the craziest he's seen, since there was always " + "the German guy who skied for 3 hours on a broken shin " + "bone (just below the kneecap);", "Nevertheless, second place is respectable, and he doesn't " + "recommend going for the record;", "He's going to put my foot in plaster for a month;", "This would impair my skiing ability somewhat for the duration, " + "as can be imagined." ] --- test: 'Null' brief: > You can use the tilde '~' character for a null value. yaml: | name: Mr. Show hosted by: Bob and David date of next season: ~ ruby: | { 'name' => 'Mr. Show', 'hosted by' => 'Bob and David', 'date of next season' => nil } --- test: Boolean brief: > You can use 'true' and 'false' for boolean values. yaml: | Is Gus a Liar?: true Do I rely on Gus for Sustenance?: false ruby: | { 'Is Gus a Liar?' => true, 'Do I rely on Gus for Sustenance?' => false } --- test: Integers brief: > An integer is a series of numbers, optionally starting with a positive or negative sign. Integers may also contain commas for readability. yaml: | zero: 0 simple: 12 one-thousand: 1,000 negative one-thousand: -1,000 ruby: | { 'zero' => 0, 'simple' => 12, 'one-thousand' => 1000, 'negative one-thousand' => -1000 } python: | [ { 'zero': 0, 'simple': 12, 'one-thousand': 1000, 'negative one-thousand': -1000, } ] --- test: Integers as Map Keys brief: > An integer can be used a dictionary key. yaml: | 1: one 2: two 3: three python: | [ { 1: 'one', 2: 'two', 3: 'three', } ] ruby: | { 1 => 'one', 2 => 'two', 3 => 'three' } --- test: Floats brief: > Floats are represented by numbers with decimals, allowing for scientific notation, as well as positive and negative infinity and "not a number." yaml: | a simple float: 2.00 larger float: 1,000.09 scientific notation: 1.00009e+3 ruby: | { 'a simple float' => 2.0, 'larger float' => 1000.09, 'scientific notation' => 1000.09 } --- test: Time brief: > You can represent timestamps by using ISO8601 format, or a variation which allows spaces between the date, time and time zone. yaml: | iso8601: 2001-12-14t21:59:43.10-05:00 space seperated: 2001-12-14 21:59:43.10 -05:00 ruby: | { 'iso8601' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ), 'space seperated' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ) } --- test: Date brief: > A date can be represented by its year, month and day in ISO8601 order. yaml: | --- 1976-07-31 ruby: | Date.new( 1976, 7, 31 ) yecht-yecht-1.1/ext/ruby/yts/YtsYpath.yml000066400000000000000000000056301262256356000205240ustar00rootroot00000000000000data: apple: red ypath: / expected: - / --- data: apple: red ypath: . expected: - / --- data: apple: red ypath: /* expected: - /apple --- data: apple: red lemon: yellow ypath: /* expected: - /apple - /lemon unordered: 1 --- data: fruit: banana: yellow vegetable: carrot: orange ypath: //. expected: - / - /fruit - /fruit/banana - /vegetable - /vegetable/carrot unordered: 1 --- data: one: two: xxx ypath: //two/.. expected: - /one --- data: apple: red ypath: /apple expected: - /apple --- data: apple: red lemon: yellow ypath: /"lemon" expected: - /lemon --- data: apple: red lemon: yellow ypath: /'lemon' expected: - /lemon --- data: apple: red lemon: yellow ypath: /lemon expected: - /lemon --- data: - apple - lemon ypath: /0 expected: - /0 --- data: apple: red lemon: yellow ypath: /orange expected: [] --- data: apple: red ypath: ./. expected: - / --- data: fruit: banana: yellow vegetable: carrot: orange ypath: /fruit/banana expected: - /fruit/banana --- data: fruit: banana: yellow vegetable: carrot: orange ypath: fruit/banana expected: - /fruit/banana --- data: names: - Steve Howell - Clark Evans ypath: /names/0 expected: - /names/0 --- data: names: - first: Clark last: Evans - first: Steve last: Howell ypath: /names/1/first expected: - /names/1/first --- data: names: - first: Clark last: Evans - first: Steve last: Howell ypath: /names/*/first expected: - /names/0/first - /names/1/first --- data: names: python-heads: - first: Clark last: Evans - first: Steve last: Howell perl-heads: - first: Brian last: Ingerson ypath: names//first expected: - /names/python-heads/0/first - /names/python-heads/1/first - /names/perl-heads/0/first --- data: task: - name: wake foo: bar - name: eat task: - name: veggies - name: meats - name: sleep ypath: //task expected: - /task - /task/1/task --- data: - one: name: xxx - two: name: yyy - three: name: zzz ypath: /*/one/name|//three/name expected: - /0/one/name - /2/three/name --- data: apple: red ypath: .|/apple|apple|/|. expected: - / - /apple --- data: - one: name: xxx - two: name: yyy - three: name: zzz ypath: /*/(one|three)/name expected: - /0/one/name - /2/three/name --- data: - one: xxx - two: yyy - one: zzz ypath: /*[one] expected: - /0 - /2 --- data: - food: Hamburger calories: 900 - food: Fries calories: 650 - food: Soft Drink calories: 350 ypath: //food[.=Fries] expected: - /1/food yecht-yecht-1.1/ext/ruby/yts/cookbook.rb000066400000000000000000000065571262256356000203600ustar00rootroot00000000000000# vim:sw=4:ts=4 # $Id$ # # Cookbook Generator for YamlTestingSuite # require 'erb/erbl' require 'yaml' ytsFiles = [ [ 'YtsBasicTests.yml', { 'name' => 'Collections', 'doc' => [] } ], [ 'YtsFlowCollections.yml', { 'name' => 'Inline Collections', 'doc' => [] } ], [ 'YtsTypeTransfers.yml', { 'name' => 'Basic Types', 'doc' => [] } ], [ 'YtsFoldedScalars.yml', { 'name' => 'Blocks', 'doc' => [] } ], [ 'YtsAnchorAlias.yml', { 'name' => 'Aliases and Anchors', 'doc' => [] } ], [ 'YtsDocumentSeparator.yml', { 'name' => 'Documents', 'doc' => [] } ], [ 'YtsRubyTests.yml', { 'name' => 'YAML For Ruby', 'doc' => [] } ] # [ 'YtsSpecificationExamples.yml', { # 'name' => 'Examples from the Specification', # 'doc' => [] # } ] ] ytsFiles.each do |yt| yt[1]['doc'] = YAML::load_stream( File.open( yt[0] ) ) yt[1]['href'] = yt[1]['name'].downcase.gsub( /\s+/, '_' ) end erb = ERbLight.new( <
    <% ytsFiles.each do |yt| %>
  • <%= yt[1]['name'] %>
  • <% if yt[1]['doc'].documents.length > 0 %>
      <% yt[1]['doc'].documents.each do |ydoc| ydoc['href'] = ydoc['test'].downcase.gsub( /\s+/, '_' ) if ydoc['test'] %>
    • <%= ydoc['test'] %>
    • <% end %>
    <% end %> <% end %>
<% ytsFiles.each do |yt| %>


<%= yt[1]['name'] %>

<% if yt[1]['doc'].documents.length > 0 yt[1]['doc'].documents.each do |ydoc| %>

<%= ydoc['test'] %>

Brief

<%= ydoc['brief'] %>

Yaml

 <%= ydoc['test'].gsub( ' ', ' ' ) if ydoc['test'] %>   
<%= ydoc['yaml'] %>

Ruby

 <%= ydoc['test'].gsub( ' ', ' ' ) if ydoc['test'] %>   
<% if ydoc.has_key?( 'ruby-setup' ) %>
<%= ydoc['ruby-setup'] %>
<% end %>
<%= ydoc['ruby'] %>
<% end end %> <% end %> TMPL ) puts erb.result yecht-yecht-1.1/ext/ruby/yts/index.yml000066400000000000000000000003041262256356000200370ustar00rootroot00000000000000- YtsBasicTests - YtsBlockMapping - YtsFlowCollections - YtsTypeTransfers - YtsFoldedScalars - YtsAnchorAlias - YtsDocumentSeparator - YtsNullsAndEmpties - YtsRubyTests - YtsSpecificationExamples yecht-yecht-1.1/ext/ruby/yts/yts.rb000066400000000000000000000107611262256356000173610ustar00rootroot00000000000000# vim:sw=4:ts=4 # $Id$ # require 'yaml' module YAML # # Make a time with the time zone # def YAML::mktime( year, mon, day, hour, min, sec, usec, zone = "Z" ) usec = usec.to_s.to_f * 1000000 val = Time::utc( year.to_i, mon.to_i, day.to_i, hour.to_i, min.to_i, sec.to_i, usec ) if zone != "Z" hour = zone[0,3].to_i * 3600 min = zone[3,2].to_i * 60 ofs = (hour + min) val = Time.at( val.to_f - ofs ) end return val end class Stream def ==( doc ) self.documents == doc.documents end end class PrivateType def ==( pt ) self.type_id == pt.type_id and self.value == pt.value end end class DomainType def ==( dt ) self.domain == dt.domain and self.type_id == dt.type_id and self.value == dt.value end end class SpecialHash def ==( h ) if h.is_a? SpecialHash self.default == h.default and not self.keys.detect { |k| self[k] != h[k] } else false end end def inspect "{SpecialHash: @default=#{@default} @hash=#{super}}" end end end header = " %YAML:1.0" YAML::load( File.read( "index.yml" ) ).each do |yst| YAML.load_documents( File.read( yst + ".yml" ) ) do |ydoc| # # Test the document # reason = nil success = 'no' round_trip = 'no' round_out = nil interval = nil if ydoc.has_key?( 'ruby' ) obj_r = nil obj_y = nil begin eval( ydoc['ruby-setup'] ) if ydoc.has_key?( 'ruby-setup' ) time = Time.now ydoc['yaml'].gsub!( / +$/, '' ) if ydoc.has_key?( 'documents' ) obj_y = YAML::load_stream( ydoc['yaml'] ) else obj_y = YAML::load( ydoc['yaml'] ) end interval = Time.now - time eval( "obj_r = #{ydoc['ruby']}" ) if obj_r == obj_y success = 'yes' # Attempt round trip unless ydoc['no-round-trip'].is_a?( Array ) and ydoc['no-round-trip'].include?( 'ruby' ) obj_y2 = nil begin if obj_y.is_a? YAML::Stream round_out = obj_y.emit obj_y2 = YAML::load_stream( round_out ) else round_out = obj_y.to_yaml obj_y2 = YAML::load( round_out ) end rescue YAML::Error => e reason = e.to_s end obj_y = obj_y2 eval( "obj_r = #{ydoc['ruby']}" ) if obj_r == obj_y round_trip = 'yes' else reason = 'Expected <' + obj_r.inspect + '>, but was <' + obj_y2.inspect + '>' end else end else reason = 'Expected <' + obj_r.inspect + '>, but was <' + obj_y.inspect + '>' end rescue Exception => e reason = e.to_s end else reason = 'No Ruby parse information available in the test document.' end # # Print out YAML result # puts <, but was <' + paths.inspect + '>' end rescue YAML::Error => e reason = e.to_s end puts <jay. . */ . protected static final short[] yyLhs = { yyLhs . }, yyLen = { yyLen . }, yyDefRed = { yyDefRed . }, yyDgoto = { yyDgoto . }, yySindex = { yySindex . }, yyRindex = { yyRindex . }, yyGindex = { yyGindex . }, yyTable = { yyTable . }, yyCheck = { yyCheck . }; . . /** maps symbol value to printable name. . @see #yyExpecting . */ . protected static final String[] yyNames = { yyNames-strings . }; . . . /** must be implemented by a scanner object to supply input to the parser. . Nested for convenience, does not depend on parser class. . */ . public interface yyInput { . . /** move on to next token. . @return false if positioned beyond tokens. . @throws IOException on input error. . */ . boolean advance () throws java.io.IOException; . . /** classifies current token. . Should not be called if {@link #advance()} returned false. . @return current %token or single character. . */ . int token (); . . /** associated with current token. . Should not be called if {@link #advance()} returned false. . @return value for {@link #token()}. . */ . Object value (); . } . . /** the generated parser, with debugging messages. . Maintains a dynamic state and value stack. . @param yyLex scanner. . @param yydebug debug message writer implementing yyDebug, or null. . @return result of the last reduction, if any. . */ . public Object yyparse (yyInput yyLex, Object yydebug) . throws java.io.IOException { t this.yydebug = (jay.yydebug.yyDebug)yydebug; . return yyparse(yyLex); . } . . /** initial size and increment of the state/value stack [default 256]. . This is not final so that it can be overwritten outside of invocations . of {@link #yyparse}. . */ . protected int yyMax; . . /** executed at the beginning of a reduce action. . Used as $$ = yyDefault($1), prior to the user-specified action, if any. . Can be overwritten to provide deep copy, etc. . @param first value for $1, or null. . @return first. . */ . protected Object yyDefault (Object first) { . return first; . } . . /** the generated parser. . Maintains a dynamic state and value stack. . @param yyLex scanner. . @return result of the last reduction, if any. . */ . public Object yyparse (yyInput yyLex) throws java.io.IOException { . if (yyMax <= 0) yyMax = 256; // initial size . int yyState = 0, yyStates[] = new int[yyMax]; // state stack . Object yyVal = null, yyVals[] = new Object[yyMax]; // value stack . int yyToken = -1; // current input . int yyErrorFlag = 0; // #tokens to shift . local ## %{ ... %} after the first %% . yyLoop: for (int yyTop = 0;; ++ yyTop) { . if (yyTop >= yyStates.length) { // dynamically increase . int[] i = new int[yyStates.length+yyMax]; . System.arraycopy(yyStates, 0, i, 0, yyStates.length); . yyStates = i; . Object[] o = new Object[yyVals.length+yyMax]; . System.arraycopy(yyVals, 0, o, 0, yyVals.length); . yyVals = o; . } . yyStates[yyTop] = yyState; . yyVals[yyTop] = yyVal; . . yyDiscarded: for (;;) { // discarding a token does not change stack . int yyN; . if ((yyN = yyDefRed[yyState]) == 0) { // else [default] reduce (yyN) . if (yyToken < 0) { . yyToken = yyLex.advance() ? yyLex.token() : 0; . } . if ((yyN = yySindex[yyState]) != 0 && (yyN += yyToken) >= 0 . && yyN < yyTable.length && yyCheck[yyN] == yyToken) { . yyState = yyTable[yyN]; // shift to yyN . yyVal = yyLex.value(); . yyToken = -1; . if (yyErrorFlag > 0) -- yyErrorFlag; . continue yyLoop; . } . if ((yyN = yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0 . && yyN < yyTable.length && yyCheck[yyN] == yyToken) . yyN = yyTable[yyN]; // reduce (yyN) . else . switch (yyErrorFlag) { . . case 0: . yyerror("syntax error"); . . case 1: case 2: . yyErrorFlag = 3; . do { . if ((yyN = yySindex[yyStates[yyTop]]) != 0 . && (yyN += yyErrorCode) >= 0 && yyN < yyTable.length . && yyCheck[yyN] == yyErrorCode) { . yyState = yyTable[yyN]; . yyVal = yyLex.value(); . continue yyLoop; . } . } while (-- yyTop >= 0); . yyerror("irrecoverable syntax error"); . . case 3: . if (yyToken == 0) { . yyerror("irrecoverable syntax error at end-of-file"); . } . yyToken = -1; . continue yyDiscarded; // leave stack alone . } . } . int yyV = yyTop + 1-yyLen[yyN]; . yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]); . switch (yyN) { .// ACTIONS_BEGIN actions ## code from the actions within the grammar .// ACTIONS_END . } . yyTop -= yyLen[yyN]; . yyState = yyStates[yyTop]; . int yyM = yyLhs[yyN]; . if (yyState == 0 && yyM == 0) { . yyState = yyFinal; . if (yyToken < 0) { . yyToken = yyLex.advance() ? yyLex.token() : 0; . } . if (yyToken == 0) { . return yyVal; . } . continue yyLoop; . } . if ((yyN = yyGindex[yyM]) != 0 && (yyN += yyState) >= 0 . && yyN < yyTable.length && yyCheck[yyN] == yyState) . yyState = yyTable[yyN]; . else . yyState = yyDgoto[yyM]; . continue yyLoop; . } . } . } . .// ACTION_BODIES epilog ## text following second %% yecht-yecht-1.1/pom.xml000066400000000000000000000052301262256356000151250ustar00rootroot00000000000000 4.0.0 org.jruby yecht 1.1 jar yecht https://github.com/jruby/yecht org.sonatype.oss oss-parent 7 scm:git:https://github.com/jruby/yecht.git scm:git:git@github.com:jruby/yecht https://github.com/jruby/yecht ${basedir}/src/main org.codehaus.mojo build-helper-maven-plugin 1.8 add-ext initialize add-source ${basedir}/ext/ruby/src/java maven-jar-plugin for jruby package jar jruby yaml/** okay/** *rb ext/ruby/lib **/*rb UTF-8 junit junit 3.8.1 test org.jruby jruby-core 1.7.22 provided yecht-yecht-1.1/src/000077500000000000000000000000001262256356000143775ustar00rootroot00000000000000yecht-yecht-1.1/src/main/000077500000000000000000000000001262256356000153235ustar00rootroot00000000000000yecht-yecht-1.1/src/main/org/000077500000000000000000000000001262256356000161125ustar00rootroot00000000000000yecht-yecht-1.1/src/main/org/yecht/000077500000000000000000000000001262256356000172265ustar00rootroot00000000000000yecht-yecht-1.1/src/main/org/yecht/BadAnchorHandler.java000066400000000000000000000011701262256356000232070ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public interface BadAnchorHandler { Node handle(Parser p, String anchor); public static class Default implements BadAnchorHandler { public Node handle(Parser p, String anchor) { // System.err.println("existing anchors: " + p.anchors); System.err.println("Bad anchor at [Line " + p.linect + ", Col " + (p.cursor - p.lineptr) + "]: " + anchor); return null; } } }// BadAnchorHandler yecht-yecht-1.1/src/main/org/yecht/Base64.java000066400000000000000000000060501262256356000211160ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public class Base64 { private final static byte[] b64_table = BytecodeNodeHandler.bytes("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); // syck_base64enc public static byte[] enc(Pointer _s, final int _len) { int len = _len; int i = 0; byte padding = (byte)'='; byte[] buff = new byte[1 + (len*4)/3 + 6]; byte[] sb = _s.buffer; int s = _s.start; while(len >= 3) { buff[i++] = b64_table[077 & (sb[s] >> 2)]; buff[i++] = b64_table[077 & (((sb[s] << 4) & 060) | ((sb[s+1] >> 4) & 017))]; buff[i++] = b64_table[077 & (((sb[s+1] << 2) & 074) | ((sb[s+2] >> 6) & 03))]; buff[i++] = b64_table[077 & sb[s+2]]; s += 3; len -= 3; } if(len == 2) { buff[i++] = b64_table[077 & (sb[s] >> 2)]; buff[i++] = b64_table[077 & (((sb[s] << 4) & 060) | ((sb[s+1] >> 4) & 017))]; buff[i++] = b64_table[077 & (((sb[s+1] << 2) & 074) | ((0 >> 6) & 03))]; buff[i++] = padding; } else if(len == 1) { buff[i++] = b64_table[077 & (sb[s] >> 2)]; buff[i++] = b64_table[077 & (((sb[s] << 4) & 060) | ((0 >> 4) & 017))]; buff[i++] = padding; buff[i++] = padding; } buff[i++] = '\n'; buff[i] = 0; return buff; } private final static int[] b64_xtable = new int[256]; static { for(int i = 0; i < 256; i++) { b64_xtable[i] = -1; } for(int i = 0; i < 64; i++) { b64_xtable[(int)b64_table[i]] = i; } } // syck_base64dec public static byte[] dec(Pointer _s, final int _len) { int len = _len; byte[] sb = _s.buffer; int s = _s.start; int a = -1,b = -1,c = 0,d; byte[] ptrb = new byte[len]; System.arraycopy(sb, s, ptrb, 0, len); int ptr = 0; int end = 0; int send = s + len; while(s < send) { while(sb[s] == '\r' || sb[s] == '\n') { s++; } if((a = b64_xtable[(int)sb[s+0]]) == -1) break; if((b = b64_xtable[(int)sb[s+1]]) == -1) break; if((c = b64_xtable[(int)sb[s+2]]) == -1) break; if((d = b64_xtable[(int)sb[s+3]]) == -1) break; ptrb[end++] = (byte)((a << 2) | (b >> 4)); ptrb[end++] = (byte)((b << 4) | (c >> 2)); ptrb[end++] = (byte)((c << 6) | d); s += 4; } if(a != -1 && b != -1) { if(s + 2 < send && sb[s+2] == '=') ptrb[end++] = (byte)((a << 2) | (b >> 4)); if(c != -1 && s + 3 < send && sb[s+3] == '=') { ptrb[end++] = (byte)((a << 2) | (b >> 4)); ptrb[end++] = (byte)((b << 4) | (c >> 2)); } } ptrb[end] = '\0'; return ptrb; } }// Base64 yecht-yecht-1.1/src/main/org/yecht/BytecodeNodeHandler.java000066400000000000000000000052701262256356000237370ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public class BytecodeNodeHandler implements NodeHandler { public static byte[] bytes(String s) { try { return s.getBytes("ISO-8859-1"); } catch(Exception e) { return null; } } // syck_yaml2byte_handler public Object handle(Parser p, Node n) { Bytestring val = new Bytestring(); if(n.anchor != null) { val.append(YAML.BYTE_ANCHOR, bytes(n.anchor), 0, -1); } if(n.type_id != null) { if(p.taguri_expansion) { val.append(YAML.BYTE_TRANSFER, bytes(n.type_id), 0, -1); } else { val.append(YAML.BYTE_TRANSFER, bytes("!" + n.type_id), 0, -1); } } switch(n.kind) { case Str: { byte nextcode = YAML.BYTE_SCALAR; Data.Str dd = (Data.Str)n.data; byte[] buf = dd.ptr.buffer; int start = dd.ptr.start; int finish = start + dd.len - 1; int current = start; byte ch; while(true) { ch = buf[current]; if('\n' == ch || 0 == ch || current > finish) { if(current >= start) { val.append(nextcode, buf, start, current); nextcode = YAML.BYTE_CONTINUE; } start = current + 1; if(current > finish) { break; } else if('\n' == ch ) { val.append(YAML.BYTE_NEWLINE,null,0,-1); } else if(0 == ch) { val.append(YAML.BYTE_NULLCHAR,null,0,-1); } } current += 1; } break; } case Seq: { val.append(YAML.BYTE_SEQUENCE,null,0,-1); Data.Seq dd = (Data.Seq)n.data; for(int i = 0; i < dd.idx; i++) { val.extend((Bytestring)n.seqRead(i)); } val.append(YAML.BYTE_END_BRANCH,null,0,-1); break; } case Map: { val.append(YAML.BYTE_MAPPING,null,0,-1); Data.Map dd = (Data.Map)n.data; for(int i = 0; i < dd.idx; i++) { val.extend((Bytestring)n.mapRead(MapPart.Key, i)); val.extend((Bytestring)n.mapRead(MapPart.Value, i)); } val.append(YAML.BYTE_END_BRANCH,null,0,-1); break; } } return val; } }// BytecodeNodeHandler yecht-yecht-1.1/src/main/org/yecht/BytecodeScanner.java000066400000000000000000001032001262256356000231350ustar00rootroot00000000000000/* Generated by re2j 0.13.6.dev on Mon Jul 27 17:41:42 2009 */ package org.yecht; import java.io.IOException; // Equivalent to bytecode.re public class BytecodeScanner implements DefaultYAMLParser.yyInput { public final static int QUOTELEN = 128; private Parser parser; private Object lval; private int currentToken = -1; public BytecodeScanner(Parser parser) { this.parser = parser; } public Object value() { return lval; } public int token() { return currentToken; } public boolean advance() throws java.io.IOException { currentToken = real_yylex(); return currentToken == 0 ? false : true; } private void YYPOS(int n) { parser.cursor = parser.token + n; } private void FORCE_NEXT_TOKEN(int n) { parser.force_token = n; } private void CHK_NL(int ptr) { if(parser.buffer.buffer[ptr - 1] == '\n' && ptr > parser.linectptr) { parser.lineptr = ptr; parser.linect++; parser.linectptr = parser.lineptr; } } private boolean ADD_BYTE_LEVEL(Level lvl, int len, LevelStatus s) { switch(lvl.status) { case seq: lvl.ncount++; parser.addLevel(len, LevelStatus.open); YYPOS(0); return true; case map: lvl.ncount++; parser.addLevel(len, s); return false; case open: lvl.status = s; return false; default: parser.addLevel(len, s); return false; } } private final static int Start = 1; private final static int Document = 2; private final static int Directive = 3; private final static int Comment = 4; private final static int Scalar = 5; private final static int Scalar2 = 6; private final static int ScalarEnd = 7; private static class QuotedString { public int idx = 0; public int capa = 100; public byte[] str; public QuotedString() { str = new byte[100]; } public void cat(char l) { cat((byte)l); } public void cat(byte l) { if(idx + 1 >= capa) { capa += QUOTELEN; str = YAML.realloc(str, capa); } str[idx++] = l; str[idx] = 0; } } // sycklex_bytecode_utf8 private int real_yylex() throws IOException { Level lvl = null; QuotedString q = null; int tok = -1; if(parser.cursor == -1) { parser.read(); } if(parser.force_token != 0) { int t = parser.force_token; parser.force_token = 0; return t; } int mainLoopGoto = Start; lvl = parser.currentLevel(); if(lvl.status == LevelStatus.doc) { mainLoopGoto = Document; } parser.token = parser.cursor; { int gotoPoint = -1; byte yych = (byte) 0; gotoNext: while(gotoPoint != -2) { int currentGoto = gotoPoint; gotoPoint = -2; switch(currentGoto) { case -1: if ((parser.limit - parser.cursor) < 3) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case 0x00: {gotoPoint = 2; continue gotoNext;} case 'D': {gotoPoint = 3; continue gotoNext;} default: {gotoPoint = 5; continue gotoNext;} } case 2: parser.cursor = parser.marker; {gotoPoint = 4; continue gotoNext;} case 3: yych = parser.buffer.buffer[(parser.marker = ++parser.cursor)]; switch (yych) { case '\n': {gotoPoint = 6; continue gotoNext;} case '\r': {gotoPoint = 8; continue gotoNext;} default: {gotoPoint = 4; continue gotoNext;} } case 4: { YYPOS(0); mainLoopGoto = Document; } case 5: yych = parser.buffer.buffer[++parser.cursor]; {gotoPoint = 4; continue gotoNext;} case 6: ++parser.cursor; { if(lvl.status == LevelStatus.header) { CHK_NL(parser.cursor); mainLoopGoto = Directive; } else { if(lvl.spaces > -1) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } YYPOS(0); return 0; } } case 8: ++parser.cursor; switch ((yych = parser.buffer.buffer[parser.cursor])) { case '\n': {gotoPoint = 6; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } } } } do { gotoSomething: while(true) { switch(mainLoopGoto) { case Start: { } case Document: { lvl = parser.currentLevel(); if(lvl.status == LevelStatus.header) { lvl.status = LevelStatus.doc; } parser.token = parser.cursor; int gotoPoint = -1; byte yych = (byte) 0; gotoNext: while(gotoPoint != -2) { int currentGoto = gotoPoint; gotoPoint = -2; switch(currentGoto) { case -1: if ((parser.limit - parser.cursor) < 3) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case 0x00: {gotoPoint = 30; continue gotoNext;} case '\n': {gotoPoint = 27; continue gotoNext;} case '\r': {gotoPoint = 29; continue gotoNext;} case 'A': {gotoPoint = 19; continue gotoNext;} case 'D': {gotoPoint = 12; continue gotoNext;} case 'E': {gotoPoint = 16; continue gotoNext;} case 'M': {gotoPoint = 14; continue gotoNext;} case 'P': {gotoPoint = 13; continue gotoNext;} case 'Q': {gotoPoint = 15; continue gotoNext;} case 'R': {gotoPoint = 21; continue gotoNext;} case 'S': {gotoPoint = 17; continue gotoNext;} case 'T': {gotoPoint = 23; continue gotoNext;} case 'c': {gotoPoint = 25; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 11: case 12: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 41; continue gotoNext;} case '\r': {gotoPoint = 44; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 13: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 41; continue gotoNext;} case '\r': {gotoPoint = 43; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 14: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 38; continue gotoNext;} case '\r': {gotoPoint = 40; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 15: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 35; continue gotoNext;} case '\r': {gotoPoint = 37; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 16: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 32; continue gotoNext;} case '\r': {gotoPoint = 34; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 17: ++parser.cursor; { if(ADD_BYTE_LEVEL(lvl, lvl.spaces + 1, LevelStatus.str)) { return '-'; } mainLoopGoto = Scalar; break gotoSomething; } case 19: ++parser.cursor; { if(ADD_BYTE_LEVEL(lvl, lvl.spaces + 1, LevelStatus.open)) { return '-'; } lval = getInline(); parser.removeAnchor((String)lval); CHK_NL(parser.cursor); return DefaultYAMLParser.YAML_ANCHOR; } case 21: ++parser.cursor; { if(ADD_BYTE_LEVEL(lvl, lvl.spaces + 1, LevelStatus.str)) { return '-'; } lval = getInline(); parser.popLevel(); if( parser.buffer.buffer[parser.cursor - 1] == '\n') parser.cursor--; return DefaultYAMLParser.YAML_ALIAS; } case 23: ++parser.cursor; { if(ADD_BYTE_LEVEL(lvl, lvl.spaces + 1, LevelStatus.open)) { return '-'; } String qstr = getInline(); CHK_NL(parser.cursor); if(qstr.charAt(0) == '!' ) { int qidx = qstr.length(); if(qidx == 1) { return DefaultYAMLParser.YAML_ITRANSFER; } lvl = parser.currentLevel(); /* * URL Prefixing */ if(qstr.charAt(1) == '^') { lval = lvl.domain + qstr.substring(2); } else { int carat = qstr.indexOf('^'); if(carat != -1) { lvl.domain = qstr.substring(1, carat); lval = lvl.domain + qstr.substring(carat + 1); } else { lval = qstr.substring(1); } } return DefaultYAMLParser.YAML_TRANSFER; } lval = qstr; return DefaultYAMLParser.YAML_TAGURI; } case 25: ++parser.cursor; { mainLoopGoto = Comment; break gotoSomething; } case 27: ++parser.cursor; { CHK_NL(parser.cursor); if(lvl.status == LevelStatus.seq) { return DefaultYAMLParser.YAML_INDENT; } else if(lvl.status == LevelStatus.map) { if(lvl.ncount % 2 == 1) return ':'; else return DefaultYAMLParser.YAML_INDENT; } mainLoopGoto = Document; break gotoSomething; } case 29: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 27; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 30: ++parser.cursor; { if(lvl.spaces > -1) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } YYPOS(0); return 0; } case 32: ++parser.cursor; { if(lvl.status == LevelStatus.seq && lvl.ncount == 0) { lvl.ncount++; YYPOS(0); FORCE_NEXT_TOKEN( ']' ); return '['; } else if(lvl.status == LevelStatus.map && lvl.ncount == 0) { lvl.ncount++; YYPOS(0); FORCE_NEXT_TOKEN( '}' ); return '{'; } parser.popLevel(); lvl = parser.currentLevel(); if(lvl.status == LevelStatus.seq) { FORCE_NEXT_TOKEN(DefaultYAMLParser.YAML_INDENT); } else if(lvl.status == LevelStatus.map) { if(lvl.ncount % 2 == 1) { FORCE_NEXT_TOKEN(':'); } else { FORCE_NEXT_TOKEN(DefaultYAMLParser.YAML_INDENT); } } CHK_NL(parser.cursor); return DefaultYAMLParser.YAML_IEND; } case 34: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 32; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 35: ++parser.cursor; { boolean complex = false; if(lvl.ncount % 2 == 0 && ( lvl.status == LevelStatus.map || lvl.status == LevelStatus.seq)) { complex = true; } if(ADD_BYTE_LEVEL(lvl, lvl.spaces + 1, LevelStatus.seq)) { return '-'; } CHK_NL(parser.cursor); if(complex) { FORCE_NEXT_TOKEN( DefaultYAMLParser.YAML_IOPEN ); return '?'; } return DefaultYAMLParser.YAML_IOPEN; } case 37: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 35; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 38: ++parser.cursor; { boolean complex = false; if(lvl.ncount % 2 == 0 && ( lvl.status == LevelStatus.map || lvl.status == LevelStatus.seq)) { complex = true; } if(ADD_BYTE_LEVEL(lvl, lvl.spaces + 1, LevelStatus.map)) { return '-'; } CHK_NL(parser.cursor); if(complex) { FORCE_NEXT_TOKEN( DefaultYAMLParser.YAML_IOPEN ); return '?'; } return DefaultYAMLParser.YAML_IOPEN; } case 40: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 38; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 41: ++parser.cursor; { if(lvl.spaces > -1) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } YYPOS(0); return 0; } case 43: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 41; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 44: ++parser.cursor; switch ((yych = parser.buffer.buffer[parser.cursor])) { case '\n': {gotoPoint = 41; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } } } } case Directive: { parser.token = parser.cursor; int gotoPoint = -1; byte yych = (byte) 0; gotoNext: while(gotoPoint != -2) { int currentGoto = gotoPoint; gotoPoint = -2; switch(currentGoto) { case -1: if ((parser.limit - parser.cursor) < 2) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case 0x00: {gotoPoint = 47; continue gotoNext;} case 'V': {gotoPoint = 48; continue gotoNext;} default: {gotoPoint = 50; continue gotoNext;} } case 47: parser.cursor = parser.marker; {gotoPoint = 49; continue gotoNext;} case 48: yych = parser.buffer.buffer[(parser.marker = ++parser.cursor)]; switch (yych) { case '.': case '/': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case ':': case ';': case '<': case '=': case '>': case '?': case '@': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '[': case '\\': case ']': case '^': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 51; continue gotoNext;} default: {gotoPoint = 49; continue gotoNext;} } case 49: { parser.cursor = parser.token; return DefaultYAMLParser.YAML_DOCSEP; } case 50: yych = parser.buffer.buffer[++parser.cursor]; {gotoPoint = 49; continue gotoNext;} case 51: ++parser.cursor; if ((parser.limit - parser.cursor) < 2) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case '.': case '/': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case ';': case '<': case '=': case '>': case '?': case '@': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '[': case '\\': case ']': case '^': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 51; continue gotoNext;} case ':': {gotoPoint = 53; continue gotoNext;} default: {gotoPoint = 47; continue gotoNext;} } case 53: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '.': case '/': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case ':': case ';': case '<': case '=': case '>': case '?': case '@': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '[': case '\\': case ']': case '^': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 54; continue gotoNext;} default: {gotoPoint = 47; continue gotoNext;} } case 54: ++parser.cursor; if ((parser.limit - parser.cursor) < 2) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case '\n': {gotoPoint = 56; continue gotoNext;} case '\r': {gotoPoint = 58; continue gotoNext;} case '.': case '/': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case ':': case ';': case '<': case '=': case '>': case '?': case '@': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '[': case '\\': case ']': case '^': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 54; continue gotoNext;} default: {gotoPoint = 47; continue gotoNext;} } case 56: ++parser.cursor; { CHK_NL(parser.cursor); mainLoopGoto = Directive; break gotoSomething; } case 58: ++parser.cursor; switch ((yych = parser.buffer.buffer[parser.cursor])) { case '\n': {gotoPoint = 56; continue gotoNext;} default: {gotoPoint = 47; continue gotoNext;} } } } } case Comment: { parser.token = parser.cursor; int gotoPoint = -1; byte yych = (byte) 0; gotoNext: while(gotoPoint != -2) { int currentGoto = gotoPoint; gotoPoint = -2; switch(currentGoto) { case -1: if ((parser.limit - parser.cursor) < 2) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case 0x00: {gotoPoint = 61; continue gotoNext;} case '\n': {gotoPoint = 62; continue gotoNext;} case '\r': {gotoPoint = 64; continue gotoNext;} default: {gotoPoint = 66; continue gotoNext;} } case 61: case 62: ++parser.cursor; case 63: { CHK_NL(parser.cursor); mainLoopGoto = Document; break gotoSomething; } case 64: ++parser.cursor; switch ((yych = parser.buffer.buffer[parser.cursor])) { case '\n': {gotoPoint = 67; continue gotoNext;} default: {gotoPoint = 65; continue gotoNext;} } case 65: { mainLoopGoto = Comment; break gotoSomething; } case 66: yych = parser.buffer.buffer[++parser.cursor]; {gotoPoint = 65; continue gotoNext;} case 67: ++parser.cursor; yych = parser.buffer.buffer[parser.cursor]; {gotoPoint = 63; continue gotoNext;} } } } case Scalar: q = new QuotedString(); q.str[0] = 0; case Scalar2: { tok = parser.cursor; int gotoPoint = -1; byte yych = (byte) 0; gotoNext: while(gotoPoint != -2) { int currentGoto = gotoPoint; gotoPoint = -2; switch(currentGoto) { case -1: if ((parser.limit - parser.cursor) < 3) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case 0x00: {gotoPoint = 74; continue gotoNext;} case '\n': {gotoPoint = 70; continue gotoNext;} case '\r': {gotoPoint = 72; continue gotoNext;} default: {gotoPoint = 76; continue gotoNext;} } case 70: ++parser.cursor; switch ((yych = parser.buffer.buffer[parser.cursor])) { case 'C': {gotoPoint = 78; continue gotoNext;} case 'N': {gotoPoint = 80; continue gotoNext;} case 'Z': {gotoPoint = 83; continue gotoNext;} default: {gotoPoint = 71; continue gotoNext;} } case 71: { parser.cursor = tok; mainLoopGoto = ScalarEnd; break gotoSomething; } case 72: ++parser.cursor; switch ((yych = parser.buffer.buffer[parser.cursor])) { case '\n': {gotoPoint = 77; continue gotoNext;} default: {gotoPoint = 73; continue gotoNext;} } case 73: { q.cat(parser.buffer.buffer[tok]); mainLoopGoto = Scalar2; break gotoSomething; } case 74: ++parser.cursor; { parser.cursor = tok; mainLoopGoto = ScalarEnd; break gotoSomething; } case 76: yych = parser.buffer.buffer[++parser.cursor]; {gotoPoint = 73; continue gotoNext;} case 77: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case 'C': {gotoPoint = 78; continue gotoNext;} case 'N': {gotoPoint = 80; continue gotoNext;} case 'Z': {gotoPoint = 83; continue gotoNext;} default: {gotoPoint = 71; continue gotoNext;} } case 78: ++parser.cursor; { CHK_NL(tok+1); mainLoopGoto = Scalar2; break gotoSomething; } case 80: ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 80; continue gotoNext;} default: {gotoPoint = 82; continue gotoNext;} } case 82: { CHK_NL(tok+1); if(tok + 2 < parser.cursor) { int count = tok + 2; int total = Integer.valueOf(new String(parser.buffer.buffer, tok + 2, parser.cursor - (tok + 2)), 10).intValue(); for(int i=0; i parser.linectptr) { parser.lineptr = ptr; parser.linect++; parser.linectptr = parser.lineptr; } } private boolean ADD_BYTE_LEVEL(Level lvl, int len, LevelStatus s) { switch(lvl.status) { case seq: lvl.ncount++; parser.addLevel(len, LevelStatus.open); YYPOS(0); return true; case map: lvl.ncount++; parser.addLevel(len, s); return false; case open: lvl.status = s; return false; default: parser.addLevel(len, s); return false; } } private final static int Start = 1; private final static int Document = 2; private final static int Directive = 3; private final static int Comment = 4; private final static int Scalar = 5; private final static int Scalar2 = 6; private final static int ScalarEnd = 7; private static class QuotedString { public int idx = 0; public int capa = 100; public byte[] str; public QuotedString() { str = new byte[100]; } public void cat(char l) { cat((byte)l); } public void cat(byte l) { if(idx + 1 >= capa) { capa += QUOTELEN; str = YAML.realloc(str, capa); } str[idx++] = l; str[idx] = 0; } } // sycklex_bytecode_utf8 private int real_yylex() throws IOException { Level lvl = null; QuotedString q = null; int tok = -1; if(parser.cursor == -1) { parser.read(); } if(parser.force_token != 0) { int t = parser.force_token; parser.force_token = 0; return t; } /*!re2j re2j:define:YYCTYPE = "byte"; re2j:define:YYCURSOR = "parser.cursor"; re2j:define:YYMARKER = "parser.marker"; re2j:define:YYLIMIT = "parser.limit"; re2j:define:YYDATA = "parser.buffer.buffer"; re2j:yyfill:parameter = 0; re2j:define:YYFILL = "parser.read()"; LF = ( "\n" | "\r\n" ) ; NULL = [\000] ; ANY = [\001-\377] ; YWORDC = [A-Za-z0-9_-] ; YWORDP = [A-Za-z0-9_-\.] ; DOC = "D" LF ; DIR = "V" YWORDP+ ":" YWORDP+ LF ; PAU = "P" LF ; MAP = "M" LF ; SEQ = "Q" LF ; END = "E" LF ; SCA = "S" ; SCC = "C" ; NNL = "N" [0-9]*; NLZ = "Z" ; ANC = "A" ; REF = "R" ; TAG = "T" ; COM = "c" ; */ int mainLoopGoto = Start; lvl = parser.currentLevel(); if(lvl.status == LevelStatus.doc) { mainLoopGoto = Document; } parser.token = parser.cursor; { /*!re2j DOC { if(lvl.status == LevelStatus.header) { CHK_NL(parser.cursor); mainLoopGoto = Directive; } else { if(lvl.spaces > -1) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } YYPOS(0); return 0; } } ANY { YYPOS(0); mainLoopGoto = Document; } */ } do { gotoSomething: while(true) { switch(mainLoopGoto) { case Start: { } case Document: { lvl = parser.currentLevel(); if(lvl.status == LevelStatus.header) { lvl.status = LevelStatus.doc; } parser.token = parser.cursor; /*!re2j DOC | PAU { if(lvl.spaces > -1) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } YYPOS(0); return 0; } MAP { boolean complex = false; if(lvl.ncount % 2 == 0 && ( lvl.status == LevelStatus.map || lvl.status == LevelStatus.seq)) { complex = true; } if(ADD_BYTE_LEVEL(lvl, lvl.spaces + 1, LevelStatus.map)) { return '-'; } CHK_NL(parser.cursor); if(complex) { FORCE_NEXT_TOKEN( DefaultYAMLParser.YAML_IOPEN ); return '?'; } return DefaultYAMLParser.YAML_IOPEN; } SEQ { boolean complex = false; if(lvl.ncount % 2 == 0 && ( lvl.status == LevelStatus.map || lvl.status == LevelStatus.seq)) { complex = true; } if(ADD_BYTE_LEVEL(lvl, lvl.spaces + 1, LevelStatus.seq)) { return '-'; } CHK_NL(parser.cursor); if(complex) { FORCE_NEXT_TOKEN( DefaultYAMLParser.YAML_IOPEN ); return '?'; } return DefaultYAMLParser.YAML_IOPEN; } END { if(lvl.status == LevelStatus.seq && lvl.ncount == 0) { lvl.ncount++; YYPOS(0); FORCE_NEXT_TOKEN( ']' ); return '['; } else if(lvl.status == LevelStatus.map && lvl.ncount == 0) { lvl.ncount++; YYPOS(0); FORCE_NEXT_TOKEN( '}' ); return '{'; } parser.popLevel(); lvl = parser.currentLevel(); if(lvl.status == LevelStatus.seq) { FORCE_NEXT_TOKEN(DefaultYAMLParser.YAML_INDENT); } else if(lvl.status == LevelStatus.map) { if(lvl.ncount % 2 == 1) { FORCE_NEXT_TOKEN(':'); } else { FORCE_NEXT_TOKEN(DefaultYAMLParser.YAML_INDENT); } } CHK_NL(parser.cursor); return DefaultYAMLParser.YAML_IEND; } SCA { if(ADD_BYTE_LEVEL(lvl, lvl.spaces + 1, LevelStatus.str)) { return '-'; } mainLoopGoto = Scalar; break gotoSomething; } ANC { if(ADD_BYTE_LEVEL(lvl, lvl.spaces + 1, LevelStatus.open)) { return '-'; } lval = getInline(); parser.removeAnchor((String)lval); CHK_NL(parser.cursor); return DefaultYAMLParser.YAML_ANCHOR; } REF { if(ADD_BYTE_LEVEL(lvl, lvl.spaces + 1, LevelStatus.str)) { return '-'; } lval = getInline(); parser.popLevel(); if( parser.buffer.buffer[parser.cursor - 1] == '\n') parser.cursor--; return DefaultYAMLParser.YAML_ALIAS; } TAG { if(ADD_BYTE_LEVEL(lvl, lvl.spaces + 1, LevelStatus.open)) { return '-'; } String qstr = getInline(); CHK_NL(parser.cursor); if(qstr.charAt(0) == '!' ) { int qidx = qstr.length(); if(qidx == 1) { return DefaultYAMLParser.YAML_ITRANSFER; } lvl = parser.currentLevel(); /* * URL Prefixing */ if(qstr.charAt(1) == '^') { lval = lvl.domain + qstr.substring(2); } else { int carat = qstr.indexOf('^'); if(carat != -1) { lvl.domain = qstr.substring(1, carat); lval = lvl.domain + qstr.substring(carat + 1); } else { lval = qstr.substring(1); } } return DefaultYAMLParser.YAML_TRANSFER; } lval = qstr; return DefaultYAMLParser.YAML_TAGURI; } COM { mainLoopGoto = Comment; break gotoSomething; } LF { CHK_NL(parser.cursor); if(lvl.status == LevelStatus.seq) { return DefaultYAMLParser.YAML_INDENT; } else if(lvl.status == LevelStatus.map) { if(lvl.ncount % 2 == 1) return ':'; else return DefaultYAMLParser.YAML_INDENT; } mainLoopGoto = Document; break gotoSomething; } NULL { if(lvl.spaces > -1) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } YYPOS(0); return 0; } */ } case Directive: { parser.token = parser.cursor; /*!re2j DIR { CHK_NL(parser.cursor); mainLoopGoto = Directive; break gotoSomething; } ANY { parser.cursor = parser.token; return DefaultYAMLParser.YAML_DOCSEP; } */ } case Comment: { parser.token = parser.cursor; /*!re2j LF { CHK_NL(parser.cursor); mainLoopGoto = Document; break gotoSomething; } ANY { mainLoopGoto = Comment; break gotoSomething; } */ } case Scalar: q = new QuotedString(); q.str[0] = 0; case Scalar2: { tok = parser.cursor; /*!re2j LF SCC { CHK_NL(tok+1); mainLoopGoto = Scalar2; break gotoSomething; } LF NNL { CHK_NL(tok+1); if(tok + 2 < parser.cursor) { int count = tok + 2; int total = Integer.valueOf(new String(parser.buffer.buffer, tok + 2, parser.cursor - (tok + 2)), 10).intValue(); for(int i=0; iOla Bini */ public class Bytestring { int hash; public byte[] buffer; int length; int remaining; boolean printed; public final static int HASH = 0xCAFECAFE; public final static int CHUNKSIZE = 64; public static int strlen(byte[] buf) { return strlen(buf, 0); } public static int strlen(byte[] buf, int start) { int stop = buf.length; for(int ix = start; ix < stop; ix++) { if(buf[ix] == 0) { return ix-start; } } return stop-start; } // bytestring_alloc public Bytestring() { hash = HASH; length = CHUNKSIZE; remaining = length; buffer = new byte[length + 1]; buffer[0] = 0; printed = false; } // bytestring_append public void append(byte code, byte[] inbuf, int start, int finish) { int length = 2; if(inbuf != null) { if(finish == -1) { finish = start + strlen(inbuf, start); } length += (finish - start); } if(length > remaining) { int grow = (length - remaining) + CHUNKSIZE; this.remaining += grow; this.length += grow; this.buffer = YAML.realloc(this.buffer, this.length+1); } int curr = this.length - this.remaining; this.buffer[curr] = code; curr++; if(inbuf != null) { while(start < finish) { buffer[curr++] = inbuf[start++]; } } buffer[curr] = '\n'; curr++; buffer[curr] = 0; this.remaining -= length; } // bytestring_extend public void extend(Bytestring ext) { if(ext.printed) { int curr = 0; while(ext.buffer[curr] != '\n') { curr++; } append(YAML.BYTE_ALIAS, ext.buffer, 1, curr); } else { ext.printed = true; int length = ext.length - ext.remaining; if(length > this.remaining) { int grow = (length - this.remaining) + CHUNKSIZE; this.remaining += grow; this.length += grow; this.buffer = YAML.realloc(this.buffer, this.length+1); } int curr = this.length - this.remaining; int from = 0; int stop = length; while(from < stop) { this.buffer[curr++] = ext.buffer[from++]; } this.buffer[curr] = 0; this.remaining -= length; } } }// Bytestring yecht-yecht-1.1/src/main/org/yecht/Data.java000066400000000000000000000041541262256356000207460ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public abstract class Data { public abstract Data copy(); public static class Map extends Data { public MapStyle style; public Object[] keys; public Object[] values; public int capa; public int idx; public String toString() { return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}"; } public Map copy() { Map m = new Map(); m.style = this.style; m.keys = new Object[this.keys.length]; System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length); m.values = new Object[this.values.length]; System.arraycopy(this.values, 0, m.values, 0, this.values.length); m.capa = this.capa; m.idx = this.idx; return m; } } public static class Seq extends Data { public SeqStyle style; public Object[] items; public int capa; public int idx; public String toString() { return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]"; } public Seq copy() { Seq m = new Seq(); m.style = this.style; m.items = new Object[this.items.length]; System.arraycopy(this.items, 0, m.items, 0, this.items.length); m.capa = this.capa; m.idx = this.idx; return m; } } public static class Str extends Data { public ScalarStyle style; public Pointer ptr; public int len; public String toString() { return "\"" + new String(ptr.buffer, ptr.start, len) + "\""; } public Str copy() { Str m = new Str(); m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start); m.len = this.len; return m; } } }// Data yecht-yecht-1.1/src/main/org/yecht/DefaultYAMLParser.java000066400000000000000000000761721262256356000233320ustar00rootroot00000000000000// created by jay 1.1.0 (c) 2002-2006 ats@cs.rit.edu // skeleton Java 1.1.0 (c) 2002-2006 ats@cs.rit.edu // line 2 "src/main/org/yecht/DefaultYAMLParser.y" package org.yecht; public class DefaultYAMLParser { // line 10 "-" // %token constants public static final int YAML_ANCHOR = 257; public static final int YAML_ALIAS = 258; public static final int YAML_TRANSFER = 259; public static final int YAML_TAGURI = 260; public static final int YAML_ITRANSFER = 261; public static final int YAML_WORD = 262; public static final int YAML_PLAIN = 263; public static final int YAML_BLOCK = 264; public static final int YAML_DOCSEP = 265; public static final int YAML_IOPEN = 266; public static final int YAML_INDENT = 267; public static final int YAML_IEND = 268; public static final int yyErrorCode = 256; /** number of final state. */ protected static final int yyFinal = 13; /** parser tables. Order is mandated by jay. */ protected static final short[] yyLhs = { //yyLhs 79 -1, 0, 0, 0, 1, 1, 4, 4, 4, 4, 4, 2, 2, 8, 8, 8, 8, 8, 8, 6, 6, 9, 10, 7, 7, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 11, 11, 17, 15, 15, 15, 15, 15, 15, 16, 16, 16, 12, 12, 18, 18, 19, 19, 13, 13, 21, 21, 21, 21, 21, 21, 23, 23, 24, 25, 22, 22, 22, 22, 20, 14, 14, 26, 26, 27, 27, }, yyLen = { //yyLen 79 2, 1, 2, 0, 1, 1, 1, 2, 2, 2, 3, 1, 1, 3, 0, 2, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1, 3, 1, 1, 1, 1, 1, 3, 3, 2, 3, 2, 3, 2, 3, 2, 1, 3, 2, 3, 2, 1, 3, 1, 1, 3, 3, 3, 2, 3, 2, 3, 2, 1, 3, 1, 3, 1, 3, 3, 2, 3, 3, 2, 1, 3, 1, 1, }, yyDefRed = { //yyDefRed 127 0, 0, 29, 0, 0, 0, 30, 31, 33, 0, 19, 0, 0, 0, 1, 4, 5, 6, 0, 34, 35, 36, 37, 28, 9, 25, 7, 26, 8, 0, 0, 0, 27, 0, 0, 0, 0, 0, 11, 2, 0, 12, 51, 0, 0, 52, 55, 74, 0, 78, 0, 75, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 47, 0, 0, 0, 68, 0, 18, 16, 17, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 50, 0, 73, 0, 22, 0, 46, 63, 0, 42, 59, 0, 44, 61, 40, 0, 23, 32, 0, 10, 21, 38, 39, 0, 56, 57, 0, 0, 13, 72, 53, 76, 64, 0, 0, 0, 0, 0, 0, 65, 24, 48, 69, 70, 66, 67, }, yyDgoto = { //yyDgoto 28 13, 38, 39, 15, 16, 17, 18, 98, 41, 102, 99, 19, 20, 21, 22, 60, 61, 62, 44, 45, 46, 63, 64, 65, 126, 66, 50, 51, }, yySindex = { //yySindex 127 -65, -1, 0, -1, -1, 170, 0, 0, 0, 13, 0, -55, -12, 0, 0, 0, 0, 0, -45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 170, 170, 170, 0, -128, 13, 13, 13, 180, 0, 0, -34, 0, 0, -48, -38, 0, 0, 0, -48, 0, -40, 0, -89, -89, -89, 0, 13, -1, -226, -226, -249, -224, 0, -249, -224, -35, 0, -226, 0, 0, 0, 180, 180, 180, 159, 0, -76, -76, -76, -249, 13, 0, -1, 0, -1, 0, -23, 0, 0, -23, 0, 0, -23, 0, 0, 0, -234, 0, 0, -226, 0, 0, 0, 0, -10, 0, 0, -23, 13, 0, 0, 0, 0, 0, -234, -234, -234, -234, -234, -234, 0, 0, 0, 0, 0, 0, 0, }, yyRindex = { //yyRindex 127 37, 0, 0, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, -220, 0, 0, -32, 0, 0, 0, 0, -39, 0, 0, 0, 0, 0, 0, 0, -205, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, -220, 0, -220, -220, -220, 0, -41, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -196, 0, 0, -185, -205, 0, 0, 0, 0, 0, -214, -208, -203, -199, -192, -181, 0, 0, 0, 0, 0, 0, 0, }, yyGindex = { //yyGindex 28 0, 9, -49, 277, 284, 0, 72, -46, 337, -47, 280, 0, 0, 0, 0, -3, -62, -79, 0, 6, -4, 43, -22, 0, 0, -15, 0, 14, }, yyTable = { //yyTable 447 56, 14, 11, 14, 84, 77, 82, 95, 49, 14, 80, 56, 54, 100, 103, 11, 105, 106, 57, 101, 43, 48, 56, 108, 114, 122, 11, 116, 123, 57, 118, 110, 109, 85, 12, 56, 11, 3, 42, 14, 57, 85, 97, 85, 101, 14, 11, 12, 14, 87, 90, 93, 14, 121, 45, 81, 64, 11, 12, 125, 62, 54, 14, 14, 115, 41, 96, 117, 12, 58, 119, 49, 49, 87, 90, 93, 43, 33, 12, 11, 49, 40, 71, 71, 14, 83, 77, 60, 111, 12, 11, 43, 124, 48, 14, 88, 91, 94, 112, 0, 0, 33, 33, 33, 11, 33, 40, 40, 40, 74, 0, 12, 40, 47, 0, 0, 0, 0, 0, 88, 91, 94, 12, 0, 0, 0, 14, 0, 40, 29, 2, 30, 31, 5, 6, 7, 12, 0, 10, 55, 0, 0, 0, 74, 74, 74, 74, 0, 40, 40, 40, 0, 40, 0, 0, 0, 0, 0, 33, 0, 0, 33, 0, 0, 33, 0, 0, 0, 52, 2, 53, 54, 5, 6, 7, 8, 0, 10, 85, 33, 40, 76, 2, 77, 78, 37, 6, 7, 8, 0, 10, 85, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 0, 10, 52, 2, 53, 54, 5, 6, 7, 8, 0, 10, 55, 76, 2, 77, 78, 37, 6, 7, 8, 0, 10, 55, 29, 2, 30, 31, 5, 6, 7, 0, 0, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 10, 0, 0, 14, 14, 34, 2, 35, 36, 37, 6, 7, 8, 23, 10, 25, 27, 32, 0, 0, 24, 0, 26, 28, 0, 0, 0, 0, 0, 0, 58, 0, 0, 0, 0, 0, 0, 59, 0, 0, 0, 23, 25, 27, 0, 67, 23, 25, 27, 32, 0, 0, 58, 24, 26, 28, 0, 0, 0, 59, 0, 0, 0, 0, 23, 25, 27, 86, 89, 92, 0, 24, 26, 28, 0, 0, 104, 0, 0, 107, 0, 0, 0, 23, 25, 27, 67, 0, 23, 25, 27, 86, 89, 92, 0, 24, 26, 28, 113, 0, 0, 113, 0, 0, 113, 0, 68, 69, 70, 75, 0, 120, 79, 0, 0, 0, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 104, 107, 104, 107, 104, 107, 0, 0, 0, 0, 0, 0, 0, 0, 68, 69, 70, 79, 0, 68, 69, 70, 71, 2, 72, 73, 37, 6, 7, 0, 0, 10, 55, 29, 2, 30, 31, 5, 6, 7, 0, 0, 10, 71, 2, 72, 73, 37, 6, 7, 0, 0, 10, }, yyCheck = { //yyCheck 447 45, 0, 91, 44, 44, 44, 44, 56, 12, 0, 58, 45, 44, 59, 61, 91, 63, 64, 63, 268, 11, 12, 45, 58, 86, 104, 91, 89, 107, 63, 92, 80, 79, 267, 123, 45, 91, 0, 93, 0, 63, 267, 268, 267, 268, 44, 91, 123, 268, 52, 53, 54, 93, 99, 268, 93, 58, 91, 123, 108, 268, 93, 267, 268, 86, 268, 57, 89, 123, 268, 92, 267, 268, 76, 77, 78, 268, 5, 123, 91, 84, 9, 267, 268, 125, 125, 125, 268, 82, 123, 91, 82, 107, 84, 93, 52, 53, 54, 84, -1, -1, 29, 30, 31, 91, 33, 34, 35, 36, 37, -1, 123, 40, 125, -1, -1, -1, -1, -1, 76, 77, 78, 123, -1, -1, -1, 125, -1, 56, 257, 258, 259, 260, 261, 262, 263, 123, -1, 266, 267, -1, -1, -1, 71, 72, 73, 74, -1, 76, 77, 78, -1, 80, -1, -1, -1, -1, -1, 86, -1, -1, 89, -1, -1, 92, -1, -1, -1, 257, 258, 259, 260, 261, 262, 263, 264, -1, 266, 267, 107, 108, 257, 258, 259, 260, 261, 262, 263, 264, -1, 266, 267, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 257, 258, 259, 260, 261, 262, 263, 264, -1, 266, 257, 258, 259, 260, 261, 262, 263, 264, -1, 266, 267, 257, 258, 259, 260, 261, 262, 263, 264, -1, 266, 267, 257, 258, 259, 260, 261, 262, 263, -1, -1, 266, -1, 257, 258, 259, 260, 261, 262, 263, 264, -1, 266, -1, 257, 258, 259, 260, 261, 262, 263, 264, -1, 266, -1, -1, 267, 268, 257, 258, 259, 260, 261, 262, 263, 264, 1, 266, 3, 4, 5, -1, -1, 1, -1, 3, 4, -1, -1, -1, -1, -1, -1, 18, -1, -1, -1, -1, -1, -1, 18, -1, -1, -1, 29, 30, 31, -1, 33, 34, 35, 36, 37, -1, -1, 40, 34, 35, 36, -1, -1, -1, 40, -1, -1, -1, -1, 52, 53, 54, 52, 53, 54, -1, 52, 53, 54, -1, -1, 61, -1, -1, 64, -1, -1, -1, 71, 72, 73, 74, -1, 76, 77, 78, 76, 77, 78, -1, 76, 77, 78, 86, -1, -1, 89, -1, -1, 92, -1, 34, 35, 36, 37, -1, 96, 40, -1, -1, -1, -1, -1, -1, 107, -1, -1, -1, -1, -1, -1, -1, -1, -1, 114, 115, 116, 117, 118, 119, -1, -1, -1, -1, -1, -1, -1, -1, 71, 72, 73, 74, -1, 76, 77, 78, 257, 258, 259, 260, 261, 262, 263, -1, -1, 266, 267, 257, 258, 259, 260, 261, 262, 263, -1, -1, 266, 257, 258, 259, 260, 261, 262, 263, -1, -1, 266, }; /** maps symbol value to printable name. @see #yyExpecting */ protected static final String[] yyNames = { "end-of-file",null,null,null,null,null,null,null,null,null,null,null, null,null,null,null,null,null,null,null,null,null,null,null,null,null, null,null,null,null,null,null,null,null,null,null,null,null,null,null, null,null,null,null,"','","'-'",null,null,null,null,null,null,null, null,null,null,null,null,"':'",null,null,null,null,"'?'",null,null, null,null,null,null,null,null,null,null,null,null,null,null,null,null, null,null,null,null,null,null,null,null,null,null,null,"'['",null, "']'",null,null,null,null,null,null,null,null,null,null,null,null, null,null,null,null,null,null,null,null,null,null,null,null,null,null, null,null,null,"'{'",null,"'}'",null,null,null,null,null,null,null, null,null,null,null,null,null,null,null,null,null,null,null,null,null, null,null,null,null,null,null,null,null,null,null,null,null,null,null, null,null,null,null,null,null,null,null,null,null,null,null,null,null, null,null,null,null,null,null,null,null,null,null,null,null,null,null, null,null,null,null,null,null,null,null,null,null,null,null,null,null, null,null,null,null,null,null,null,null,null,null,null,null,null,null, null,null,null,null,null,null,null,null,null,null,null,null,null,null, null,null,null,null,null,null,null,null,null,null,null,null,null,null, null,null,null,null,null,null,null,null,null,null,null,null, "YAML_ANCHOR","YAML_ALIAS","YAML_TRANSFER","YAML_TAGURI", "YAML_ITRANSFER","YAML_WORD","YAML_PLAIN","YAML_BLOCK","YAML_DOCSEP", "YAML_IOPEN","YAML_INDENT","YAML_IEND", }; /** must be implemented by a scanner object to supply input to the parser. Nested for convenience, does not depend on parser class. */ public interface yyInput { /** move on to next token. @return false if positioned beyond tokens. @throws IOException on input error. */ boolean advance () throws java.io.IOException; /** classifies current token. Should not be called if {@link #advance()} returned false. @return current %token or single character. */ int token (); /** associated with current token. Should not be called if {@link #advance()} returned false. @return value for {@link #token()}. */ Object value (); } /** the generated parser, with debugging messages. Maintains a dynamic state and value stack. @param yyLex scanner. @param yydebug debug message writer implementing yyDebug, or null. @return result of the last reduction, if any. */ public Object yyparse (yyInput yyLex, Object yydebug) throws java.io.IOException { //t this.yydebug = (jay.yydebug.yyDebug)yydebug; return yyparse(yyLex); } /** initial size and increment of the state/value stack [default 256]. This is not final so that it can be overwritten outside of invocations of {@link #yyparse}. */ protected int yyMax; /** executed at the beginning of a reduce action. Used as $$ = yyDefault($1), prior to the user-specified action, if any. Can be overwritten to provide deep copy, etc. @param first value for $1, or null. @return first. */ protected Object yyDefault (Object first) { return first; } /** the generated parser. Maintains a dynamic state and value stack. @param yyLex scanner. @return result of the last reduction, if any. */ public Object yyparse (yyInput yyLex) throws java.io.IOException { if (yyMax <= 0) yyMax = 256; // initial size int yyState = 0, yyStates[] = new int[yyMax]; // state stack Object yyVal = null, yyVals[] = new Object[yyMax]; // value stack int yyToken = -1; // current input int yyErrorFlag = 0; // #tokens to shift yyLoop: for (int yyTop = 0;; ++ yyTop) { if (yyTop >= yyStates.length) { // dynamically increase int[] i = new int[yyStates.length+yyMax]; System.arraycopy(yyStates, 0, i, 0, yyStates.length); yyStates = i; Object[] o = new Object[yyVals.length+yyMax]; System.arraycopy(yyVals, 0, o, 0, yyVals.length); yyVals = o; } yyStates[yyTop] = yyState; yyVals[yyTop] = yyVal; yyDiscarded: for (;;) { // discarding a token does not change stack int yyN; if ((yyN = yyDefRed[yyState]) == 0) { // else [default] reduce (yyN) if (yyToken < 0) { yyToken = yyLex.advance() ? yyLex.token() : 0; } if ((yyN = yySindex[yyState]) != 0 && (yyN += yyToken) >= 0 && yyN < yyTable.length && yyCheck[yyN] == yyToken) { yyState = yyTable[yyN]; // shift to yyN yyVal = yyLex.value(); yyToken = -1; if (yyErrorFlag > 0) -- yyErrorFlag; continue yyLoop; } if ((yyN = yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0 && yyN < yyTable.length && yyCheck[yyN] == yyToken) yyN = yyTable[yyN]; // reduce (yyN) else switch (yyErrorFlag) { case 0: yyerror("syntax error"); case 1: case 2: yyErrorFlag = 3; do { if ((yyN = yySindex[yyStates[yyTop]]) != 0 && (yyN += yyErrorCode) >= 0 && yyN < yyTable.length && yyCheck[yyN] == yyErrorCode) { yyState = yyTable[yyN]; yyVal = yyLex.value(); continue yyLoop; } } while (-- yyTop >= 0); yyerror("irrecoverable syntax error"); case 3: if (yyToken == 0) { yyerror("irrecoverable syntax error at end-of-file"); } yyToken = -1; continue yyDiscarded; // leave stack alone } } int yyV = yyTop + 1-yyLen[yyN]; yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]); switch (yyN) { // ACTIONS_BEGIN case 1: // line 18 "src/main/org/yecht/DefaultYAMLParser.y" { parser.root = parser.addNode((Node)yyVals[0+yyTop]); } break; case 2: // line 21 "src/main/org/yecht/DefaultYAMLParser.y" { parser.root = parser.addNode((Node)yyVals[0+yyTop]); } break; case 3: // line 24 "src/main/org/yecht/DefaultYAMLParser.y" { parser.eof = true; } break; case 7: // line 34 "src/main/org/yecht/DefaultYAMLParser.y" { Parser.addTransfer((String)yyVals[-1+yyTop], (Node)yyVals[0+yyTop], parser.taguri_expansion); yyVal = yyVals[0+yyTop]; } break; case 8: // line 38 "src/main/org/yecht/DefaultYAMLParser.y" { Parser.addTransfer((String)yyVals[-1+yyTop], (Node)yyVals[0+yyTop], false); yyVal = yyVals[0+yyTop]; } break; case 9: // line 42 "src/main/org/yecht/DefaultYAMLParser.y" { /* * _Anchors_: The language binding must keep a separate symbol table * for anchors. The actual ID in the symbol table is returned to the * higher nodes, though. */ yyVal = parser.addAnchor((String)yyVals[-1+yyTop], (Node)yyVals[0+yyTop] ); } break; case 10: // line 50 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = yyVals[-1+yyTop]; } break; case 13: // line 59 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = yyVals[-1+yyTop]; } break; case 14: // line 62 "src/main/org/yecht/DefaultYAMLParser.y" { Node n = NULL_NODE( parser ); yyVal = n; } break; case 15: // line 67 "src/main/org/yecht/DefaultYAMLParser.y" { if(parser.implicit_typing) { ImplicitScanner2.tryTagImplicit((Node)yyVals[0+yyTop], parser.taguri_expansion); } yyVal = yyVals[0+yyTop]; } break; case 16: // line 75 "src/main/org/yecht/DefaultYAMLParser.y" { Parser.addTransfer((String)yyVals[-1+yyTop], (Node)yyVals[0+yyTop], parser.taguri_expansion); yyVal = yyVals[0+yyTop]; } break; case 17: // line 80 "src/main/org/yecht/DefaultYAMLParser.y" { Parser.addTransfer((String)yyVals[-1+yyTop], (Node)yyVals[0+yyTop], false); yyVal = yyVals[0+yyTop]; } break; case 18: // line 85 "src/main/org/yecht/DefaultYAMLParser.y" { /* * _Anchors_: The language binding must keep a separate symbol table * for anchors. The actual ID in the symbol table is returned to the * higher nodes, though. */ yyVal = parser.addAnchor((String)yyVals[-1+yyTop], (Node)yyVals[0+yyTop] ); } break; case 25: // line 118 "src/main/org/yecht/DefaultYAMLParser.y" { Parser.addTransfer((String)yyVals[-1+yyTop], (Node)yyVals[0+yyTop], parser.taguri_expansion); yyVal = yyVals[0+yyTop]; } break; case 26: // line 123 "src/main/org/yecht/DefaultYAMLParser.y" { Parser.addTransfer((String)yyVals[-1+yyTop], (Node)yyVals[0+yyTop], false); yyVal = yyVals[0+yyTop]; } break; case 27: // line 128 "src/main/org/yecht/DefaultYAMLParser.y" { if(parser.implicit_typing) { ImplicitScanner2.tryTagImplicit((Node)yyVals[0+yyTop], parser.taguri_expansion); } yyVal = yyVals[0+yyTop]; } break; case 28: // line 136 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = parser.addAnchor((String)yyVals[-1+yyTop], (Node)yyVals[0+yyTop] ); } break; case 29: // line 140 "src/main/org/yecht/DefaultYAMLParser.y" { /* * _Aliases_: The anchor symbol table is scanned for the anchor name. * The anchor's ID in the language's symbol table is returned. */ yyVal = parser.getAnchor((String)yyVals[0+yyTop]); } break; case 30: // line 148 "src/main/org/yecht/DefaultYAMLParser.y" { Node n = (Node)yyVals[0+yyTop]; if(parser.taguri_expansion) { n.type_id = Parser.taguri(YAML.DOMAIN, "str"); } else { n.type_id = "str"; } yyVal = n; } break; case 32: // line 159 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = yyVals[-1+yyTop]; } break; case 38: // line 179 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = yyVals[-1+yyTop]; } break; case 39: // line 183 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = yyVals[-1+yyTop]; } break; case 40: // line 189 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = parser.addNode((Node) yyVals[0+yyTop]); } break; case 41: // line 195 "src/main/org/yecht/DefaultYAMLParser.y" { Parser.addTransfer((String)yyVals[-2+yyTop], (Node)yyVals[0+yyTop], parser.taguri_expansion); yyVal = yyVals[0+yyTop]; } break; case 42: // line 200 "src/main/org/yecht/DefaultYAMLParser.y" { Parser.addTransfer((String)yyVals[-1+yyTop], (Node)yyVals[0+yyTop], parser.taguri_expansion); yyVal = yyVals[0+yyTop]; } break; case 43: // line 205 "src/main/org/yecht/DefaultYAMLParser.y" { Parser.addTransfer((String)yyVals[-2+yyTop], (Node)yyVals[0+yyTop], false); yyVal = yyVals[0+yyTop]; } break; case 44: // line 210 "src/main/org/yecht/DefaultYAMLParser.y" { Parser.addTransfer((String)yyVals[-1+yyTop], (Node)yyVals[0+yyTop], false); yyVal = yyVals[0+yyTop]; } break; case 45: // line 215 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = parser.addAnchor((String)yyVals[-2+yyTop], (Node)yyVals[0+yyTop] ); } break; case 46: // line 219 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = parser.addAnchor((String)yyVals[-1+yyTop], (Node)yyVals[0+yyTop] ); } break; case 47: // line 225 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = Node.newSeq(yyVals[0+yyTop]); } break; case 48: // line 229 "src/main/org/yecht/DefaultYAMLParser.y" { ((Node)yyVals[-2+yyTop]).seqAdd(yyVals[0+yyTop]); yyVal = yyVals[-2+yyTop]; } break; case 49: // line 234 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = yyVals[-1+yyTop]; } break; case 50: // line 243 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = yyVals[-1+yyTop]; } break; case 51: // line 247 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = Node.allocSeq(); } break; case 52: // line 253 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = Node.newSeq(parser.addNode((Node)yyVals[0+yyTop])); } break; case 53: // line 257 "src/main/org/yecht/DefaultYAMLParser.y" { ((Node)yyVals[-2+yyTop]).seqAdd(parser.addNode((Node)yyVals[0+yyTop])); yyVal = yyVals[-2+yyTop]; } break; case 56: // line 271 "src/main/org/yecht/DefaultYAMLParser.y" { applySeqInMap(parser, (Node)yyVals[-1+yyTop]); yyVal = yyVals[-1+yyTop]; } break; case 57: // line 276 "src/main/org/yecht/DefaultYAMLParser.y" { applySeqInMap(parser, (Node)yyVals[-1+yyTop]); yyVal = yyVals[-1+yyTop]; } break; case 58: // line 283 "src/main/org/yecht/DefaultYAMLParser.y" { Parser.addTransfer((String)yyVals[-2+yyTop], (Node)yyVals[0+yyTop], parser.taguri_expansion); yyVal = yyVals[0+yyTop]; } break; case 59: // line 288 "src/main/org/yecht/DefaultYAMLParser.y" { Parser.addTransfer((String)yyVals[-1+yyTop], (Node)yyVals[0+yyTop], parser.taguri_expansion); yyVal = yyVals[0+yyTop]; } break; case 60: // line 293 "src/main/org/yecht/DefaultYAMLParser.y" { Parser.addTransfer((String)yyVals[-2+yyTop], (Node)yyVals[0+yyTop], false); yyVal = yyVals[0+yyTop]; } break; case 61: // line 298 "src/main/org/yecht/DefaultYAMLParser.y" { Parser.addTransfer((String)yyVals[-1+yyTop], (Node)yyVals[0+yyTop], false); yyVal = yyVals[0+yyTop]; } break; case 62: // line 303 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = parser.addAnchor((String)yyVals[-2+yyTop], (Node)yyVals[0+yyTop]); } break; case 63: // line 307 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = parser.addAnchor((String)yyVals[-1+yyTop], (Node)yyVals[0+yyTop]); } break; case 65: // line 314 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = yyVals[-1+yyTop]; } break; case 67: // line 323 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = Node.newMap( parser.addNode( (Node)yyVals[-2+yyTop] ), parser.addNode( (Node)yyVals[0+yyTop] ) ); } break; case 69: // line 332 "src/main/org/yecht/DefaultYAMLParser.y" { if ( ((Node)yyVals[-2+yyTop]).shortcut == null ) { ((Node)yyVals[-2+yyTop]).shortcut = Node.newSeq(yyVals[0+yyTop]); } else { ((Node)((Node)yyVals[-2+yyTop]).shortcut).seqAdd(yyVals[0+yyTop]); } yyVal = yyVals[-2+yyTop]; } break; case 70: // line 344 "src/main/org/yecht/DefaultYAMLParser.y" { applySeqInMap( parser, (Node)yyVals[-2+yyTop] ); ((Node)yyVals[-2+yyTop]).mapUpdate((Node)yyVals[0+yyTop]); yyVals[0+yyTop] = null; yyVal = yyVals[-2+yyTop]; } break; case 71: // line 351 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = yyVals[-1+yyTop]; } break; case 72: // line 360 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = Node.newMap( parser.addNode( (Node)yyVals[-2+yyTop] ), parser.addNode( (Node)yyVals[0+yyTop] ) ); } break; case 73: // line 368 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = yyVals[-1+yyTop]; } break; case 74: // line 372 "src/main/org/yecht/DefaultYAMLParser.y" { yyVal = Node.allocMap(); } break; case 76: // line 379 "src/main/org/yecht/DefaultYAMLParser.y" { ((Node)yyVals[-2+yyTop]).mapUpdate((Node)yyVals[0+yyTop]); yyVals[0+yyTop] = null; yyVal = yyVals[-2+yyTop]; } break; case 77: // line 387 "src/main/org/yecht/DefaultYAMLParser.y" { Node n = NULL_NODE( parser ); yyVal = Node.newMap( parser.addNode( (Node)yyVals[0+yyTop] ), parser.addNode( n )); } break; // line 749 "-" // ACTIONS_END } yyTop -= yyLen[yyN]; yyState = yyStates[yyTop]; int yyM = yyLhs[yyN]; if (yyState == 0 && yyM == 0) { yyState = yyFinal; if (yyToken < 0) { yyToken = yyLex.advance() ? yyLex.token() : 0; } if (yyToken == 0) { return yyVal; } continue yyLoop; } if ((yyN = yyGindex[yyM]) != 0 && (yyN += yyState) >= 0 && yyN < yyTable.length && yyCheck[yyN] == yyState) yyState = yyTable[yyN]; else yyState = yyDgoto[yyM]; continue yyLoop; } } } // ACTION_BODIES // line 396 "src/main/org/yecht/DefaultYAMLParser.y" private Parser parser; public DefaultYAMLParser(Parser parser) { this.parser = parser; } public static Node NULL_NODE(Parser parser) { Node n = Node.newStr(Pointer.create(new byte[0], 0), 0, ScalarStyle.Plain); if(parser.taguri_expansion) { n.type_id = Parser.taguri(YAML.DOMAIN, "null"); } else { n.type_id = "null"; } return n; } public static void applySeqInMap(Parser parser, Node n) { if(n.shortcut == null) { return; } int map_len = (int)n.mapCount(); n.mapAssign(MapPart.Value, map_len - 1, parser.addNode((Node)n.shortcut)); n.shortcut = null; } public void yyerror(String msg) { TokenScanner.error(msg, parser); } } // line 808 "-" yecht-yecht-1.1/src/main/org/yecht/DefaultYAMLParser.y000066400000000000000000000270341262256356000226520ustar00rootroot00000000000000%{ package org.yecht; public class DefaultYAMLParser { %} %start doc %token YAML_ANCHOR YAML_ALIAS YAML_TRANSFER YAML_TAGURI YAML_ITRANSFER %token YAML_WORD YAML_PLAIN YAML_BLOCK %token YAML_DOCSEP YAML_IOPEN YAML_INDENT YAML_IEND %left '-' ':' %left '[' ']' '{' '}' ',' '?' %% doc : atom { parser.root = parser.addNode((Node)$1); } | YAML_DOCSEP atom_or_empty { parser.root = parser.addNode((Node)$2); } | { parser.eof = true; } ; atom : word_rep | ind_rep ; ind_rep : struct_rep | YAML_TRANSFER ind_rep { Parser.addTransfer((String)$1, (Node)$2, parser.taguri_expansion); $$ = $2; } | YAML_TAGURI ind_rep { Parser.addTransfer((String)$1, (Node)$2, false); $$ = $2; } | YAML_ANCHOR ind_rep { /* * _Anchors_: The language binding must keep a separate symbol table * for anchors. The actual ID in the symbol table is returned to the * higher nodes, though. */ $$ = parser.addAnchor((String)$1, (Node)$2 ); } | indent_open ind_rep indent_flex_end { $$ = $2; } ; atom_or_empty : atom | empty ; empty : indent_open empty indent_end { $$ = $2; } | { Node n = NULL_NODE( parser ); $$ = n; } | YAML_ITRANSFER empty { if(parser.implicit_typing) { ImplicitScanner2.tryTagImplicit((Node)$2, parser.taguri_expansion); } $$ = $2; } | YAML_TRANSFER empty { Parser.addTransfer((String)$1, (Node)$2, parser.taguri_expansion); $$ = $2; } | YAML_TAGURI empty { Parser.addTransfer((String)$1, (Node)$2, false); $$ = $2; } | YAML_ANCHOR empty { /* * _Anchors_: The language binding must keep a separate symbol table * for anchors. The actual ID in the symbol table is returned to the * higher nodes, though. */ $$ = parser.addAnchor((String)$1, (Node)$2 ); } ; /* * Indentation abstractions */ indent_open : YAML_IOPEN | indent_open YAML_INDENT ; indent_end : YAML_IEND ; indent_sep : YAML_INDENT ; indent_flex_end : YAML_IEND | indent_sep indent_flex_end ; /* * Words are broken out to distinguish them * as keys in implicit maps and valid elements * for the inline structures */ word_rep : YAML_TRANSFER word_rep { Parser.addTransfer((String)$1, (Node)$2, parser.taguri_expansion); $$ = $2; } | YAML_TAGURI word_rep { Parser.addTransfer((String)$1, (Node)$2, false); $$ = $2; } | YAML_ITRANSFER word_rep { if(parser.implicit_typing) { ImplicitScanner2.tryTagImplicit((Node)$2, parser.taguri_expansion); } $$ = $2; } | YAML_ANCHOR word_rep { $$ = parser.addAnchor((String)$1, (Node)$2 ); } | YAML_ALIAS { /* * _Aliases_: The anchor symbol table is scanned for the anchor name. * The anchor's ID in the language's symbol table is returned. */ $$ = parser.getAnchor((String)$1); } | YAML_WORD { Node n = (Node)$1; if(parser.taguri_expansion) { n.type_id = Parser.taguri(YAML.DOMAIN, "str"); } else { n.type_id = "str"; } $$ = n; } | YAML_PLAIN | indent_open word_rep indent_flex_end { $$ = $2; } ; /* * Any of these structures can be used as * complex keys */ struct_rep : YAML_BLOCK | implicit_seq | inline_seq | implicit_map | inline_map ; /* * Implicit sequence */ implicit_seq : indent_open top_imp_seq indent_end { $$ = $2; } | indent_open in_implicit_seq indent_end { $$ = $2; } ; basic_seq : '-' atom_or_empty { $$ = parser.addNode((Node) $2); } ; top_imp_seq : YAML_TRANSFER indent_sep in_implicit_seq { Parser.addTransfer((String)$1, (Node)$3, parser.taguri_expansion); $$ = $3; } | YAML_TRANSFER top_imp_seq { Parser.addTransfer((String)$1, (Node)$2, parser.taguri_expansion); $$ = $2; } | YAML_TAGURI indent_sep in_implicit_seq { Parser.addTransfer((String)$1, (Node)$3, false); $$ = $3; } | YAML_TAGURI top_imp_seq { Parser.addTransfer((String)$1, (Node)$2, false); $$ = $2; } | YAML_ANCHOR indent_sep in_implicit_seq { $$ = parser.addAnchor((String)$1, (Node)$3 ); } | YAML_ANCHOR top_imp_seq { $$ = parser.addAnchor((String)$1, (Node)$2 ); } ; in_implicit_seq : basic_seq { $$ = Node.newSeq($1); } | in_implicit_seq indent_sep basic_seq { ((Node)$1).seqAdd($3); $$ = $1; } | in_implicit_seq indent_sep { $$ = $1; } ; /* * Inline sequences */ inline_seq : '[' in_inline_seq ']' { $$ = $2; } | '[' ']' { $$ = Node.allocSeq(); } ; in_inline_seq : inline_seq_atom { $$ = Node.newSeq(parser.addNode((Node)$1)); } | in_inline_seq ',' inline_seq_atom { ((Node)$1).seqAdd(parser.addNode((Node)$3)); $$ = $1; } ; inline_seq_atom : atom | basic_mapping ; /* * Implicit maps */ implicit_map : indent_open top_imp_map indent_end { applySeqInMap(parser, (Node)$2); $$ = $2; } | indent_open in_implicit_map indent_end { applySeqInMap(parser, (Node)$2); $$ = $2; } ; top_imp_map : YAML_TRANSFER indent_sep in_implicit_map { Parser.addTransfer((String)$1, (Node)$3, parser.taguri_expansion); $$ = $3; } | YAML_TRANSFER top_imp_map { Parser.addTransfer((String)$1, (Node)$2, parser.taguri_expansion); $$ = $2; } | YAML_TAGURI indent_sep in_implicit_map { Parser.addTransfer((String)$1, (Node)$3, false); $$ = $3; } | YAML_TAGURI top_imp_map { Parser.addTransfer((String)$1, (Node)$2, false); $$ = $2; } | YAML_ANCHOR indent_sep in_implicit_map { $$ = parser.addAnchor((String)$1, (Node)$3); } | YAML_ANCHOR top_imp_map { $$ = parser.addAnchor((String)$1, (Node)$2); } ; complex_key : word_rep | '?' atom indent_sep { $$ = $2; } ; complex_value : atom_or_empty ; complex_mapping : complex_key ':' complex_value { $$ = Node.newMap( parser.addNode( (Node)$1 ), parser.addNode( (Node)$3 ) ); } ; in_implicit_map : complex_mapping | in_implicit_map indent_sep basic_seq { if ( ((Node)$1).shortcut == null ) { ((Node)$1).shortcut = Node.newSeq($3); } else { ((Node)((Node)$1).shortcut).seqAdd($3); } $$ = $1; } | in_implicit_map indent_sep complex_mapping { applySeqInMap( parser, (Node)$1 ); ((Node)$1).mapUpdate((Node)$3); $3 = null; $$ = $1; } | in_implicit_map indent_sep { $$ = $1; } ; /* * Inline maps */ basic_mapping : atom ':' atom_or_empty { $$ = Node.newMap( parser.addNode( (Node)$1 ), parser.addNode( (Node)$3 ) ); } ; inline_map : '{' in_inline_map '}' { $$ = $2; } | '{' '}' { $$ = Node.allocMap(); } ; in_inline_map : inline_map_atom | in_inline_map ',' inline_map_atom { ((Node)$1).mapUpdate((Node)$3); $3 = null; $$ = $1; } ; inline_map_atom : atom { Node n = NULL_NODE( parser ); $$ = Node.newMap( parser.addNode( (Node)$1 ), parser.addNode( n )); } | basic_mapping ; %% private Parser parser; public DefaultYAMLParser(Parser parser) { this.parser = parser; } public static Node NULL_NODE(Parser parser) { Node n = Node.newStr(Pointer.create(new byte[0], 0), 0, ScalarStyle.Plain); if(parser.taguri_expansion) { n.type_id = Parser.taguri(YAML.DOMAIN, "null"); } else { n.type_id = "null"; } return n; } public static void applySeqInMap(Parser parser, Node n) { if(n.shortcut == null) { return; } int map_len = (int)n.mapCount(); n.mapAssign(MapPart.Value, map_len - 1, parser.addNode((Node)n.shortcut)); n.shortcut = null; } public void yyerror(String msg) { TokenScanner.error(msg, parser); } } yecht-yecht-1.1/src/main/org/yecht/DocStage.java000066400000000000000000000004101262256356000215550ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public enum DocStage { // doc_open, doc_processing open, processing }// DocStage yecht-yecht-1.1/src/main/org/yecht/Emitter.java000066400000000000000000001013221262256356000215010ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; import java.util.IdentityHashMap; import java.util.Map; import java.util.HashMap; /** * * @author Ola Bini */ public class Emitter { public static class Node { public int pos; public int indent; public boolean is_shortcut; } public boolean headless; public boolean use_header; public boolean use_version; public boolean sort_keys; public String anchor_format; public boolean explicit_typing; public int best_width; public ScalarStyle style; public DocStage stage; public int level; public int indent; Map markers; Map anchors; Map anchored; int bufsize; byte[] buffer; int marker; int bufpos; EmitterHandler emitter_handler; OutputHandler output_handler; Level[] levels; int lvl_idx; int lvl_capa; public Object bonus; // syck_new_emitter public Emitter() { this.headless = false; this.use_header = false; this.use_version = false; this.sort_keys = false; this.anchor_format = null; this.explicit_typing = false; this.best_width = 80; this.style = ScalarStyle.None; this.stage = DocStage.open; this.indent = 2; this.level = -1; this.anchors = null; this.markers = null; this.anchored = null; this.bufsize = YAML.BUFFERSIZE; this.buffer = null; this.marker = -1; this.bufpos = 0; this.emitter_handler = null; this.output_handler = null; this.lvl_idx = 0; this.lvl_capa = YAML.ALLOC_CT; this.levels = new Level[this.lvl_capa]; resetLevels(); this.bonus = null; } // syck_emitter_current_level public Level currentLevel() { return levels[lvl_idx-1]; } // syck_emitter_parent_level public Level parentLevel() { return levels[lvl_idx-2]; } // syck_emitter_pop_level public void popLevel() { if(lvl_idx <= 1) { return; } lvl_idx--; } // syck_emitter_add_level public void addLevel(int len, LevelStatus status) { if(lvl_idx + 1 > lvl_capa) { lvl_capa += YAML.ALLOC_CT; levels = YAML.realloc(levels, lvl_capa); } levels[lvl_idx] = new Level(); levels[lvl_idx].spaces = len; levels[lvl_idx].ncount = 0; levels[lvl_idx].domain = levels[lvl_idx-1].domain; levels[lvl_idx].status = status; levels[lvl_idx].anctag = 0; lvl_idx++; } // syck_emitter_reset_levels public void resetLevels() { while(lvl_idx > 1) { popLevel(); } if(lvl_idx < 1) { lvl_idx = 1; levels[0] = new Level(); levels[0].spaces = -1; levels[0].ncount = 0; levels[0].domain = ""; levels[0].anctag = 0; } levels[0].status = LevelStatus.header; } // syck_emitter_handler public void handler(EmitterHandler hdlr) { this.emitter_handler = hdlr; } // syck_output_handler public void outputHandler(OutputHandler hdlr) { this.output_handler = hdlr; } // syck_emitter_clear public void clear() { if(this.buffer == null) { this.buffer = new byte[this.bufsize]; } this.buffer[0] = 0; this.marker = 0; this.bufpos = 0; } // syck_emitter_write public void write(Pointer _str, final int _len) { int len = _len; byte[] bstr = _str.buffer; int str = _str.start; if(this.buffer == null) { clear(); } int at = this.marker; if(len + at >= this.bufsize - 1) { flush(0); for(;;) { int rest = (this.bufsize - 1) - this.marker; if(len <= rest) break; System.arraycopy(bstr, str, this.buffer, this.marker, rest); this.marker += rest; str += rest; len -= rest; flush(0); } } System.arraycopy(bstr, str, this.buffer, this.marker, len); this.marker += len; this.buffer[this.marker] = 0; } // syck_emitter_flush public void flush(int check_room ){ if(check_room > 0) { if((this.bufsize - 1) > (this.marker + check_room)) { return; } } else { check_room = this.bufsize - 1; } if(check_room > this.marker ) { check_room = this.marker; } this.output_handler.handle(this, this.buffer, check_room); this.bufpos += check_room; this.marker -= check_room; } private final static Pointer NEWLINE = Pointer.create("\n"); private final static Pointer TWO_NEWLINES = Pointer.create("\n\n"); private final static Pointer SPACE = Pointer.create(" "); private final static Pointer SLASH = Pointer.create("/"); private final static Pointer THREE_DASHES = Pointer.create("--- "); private final static Pointer QUESTION_MARK_SPACE = Pointer.create("? "); private final static Pointer BANG = Pointer.create("!"); private final static Pointer BANG_SPACE = Pointer.create("! "); private final static Pointer TWO_BANGS = Pointer.create("!!"); private final static Pointer BACKSLASH = Pointer.create("\\"); private final static Pointer ZERO = Pointer.create("0"); private final static Pointer X = Pointer.create("x"); private final static Pointer SINGLE_QUOTE = Pointer.create("'"); private final static Pointer DOUBLE_QUOTE = Pointer.create("\""); private final static Pointer PIPE = Pointer.create("|"); private final static Pointer PLUS = Pointer.create("+"); private final static Pointer MINUS = Pointer.create("-"); private final static Pointer GT = Pointer.create(">"); private final static Pointer SQUARE_OPEN = Pointer.create("["); private final static Pointer SQUARE_CLOSE = Pointer.create("]"); private final static Pointer CURLY_OPEN = Pointer.create("{"); private final static Pointer CURLY_CLOSE = Pointer.create("}"); private final static Pointer DASH_SPACE = Pointer.create("- "); private final static Pointer COMMA_SPACE = Pointer.create(", "); private final static Pointer COLON_SPACE = Pointer.create(": "); private final static Pointer EMPTY_ARRAY = Pointer.create("[]\n"); private final static Pointer EMPTY_HASH = Pointer.create("{}\n"); private final static Pointer COLON = Pointer.create(":"); /* * Start emitting from the given node, check for anchoring and then * issue the callback to the emitter handler. */ // syck_emit public void emit(Object n) { int indent = 0; int x = 0; Level lvl = currentLevel(); if(stage == DocStage.open && (!headless || use_header)) { if(use_version) { String header = "--- %YAML:" + YAML.YAML_MAJOR + "." + YAML.YAML_MINOR + " "; write(Pointer.create(header), header.length()); } else { write(THREE_DASHES, 4); } stage = DocStage.processing; } if(lvl.spaces >= 0) { indent = lvl.spaces + this.indent; } addLevel(indent, LevelStatus.open); Level parent = lvl; lvl = currentLevel(); boolean handle = true; if(this.anchors != null && this.markers.containsKey(n)) { long oid = this.markers.get(n); if(this.anchors.containsKey(oid)) { String anchor_name = this.anchors.get(oid); if(this.anchored == null) { anchored = new HashMap(); } if(!anchored.containsKey(anchor_name)) { String an = "&" + anchor_name + " "; if(parent.status == LevelStatus.map && parent.ncount % 2 == 1) { write(QUESTION_MARK_SPACE, 2); parent.status = LevelStatus.mapx; } write(Pointer.create(an), an.length()); this.anchored.put(anchor_name, null); lvl.anctag = 1; } else { String an = "*" + anchor_name; write(Pointer.create(an), an.length()); handle = false; } } } if(handle) { this.emitter_handler.handle(this, n); } popLevel(); if(lvl_idx == 1) { write(NEWLINE, 1); this.headless = false; this.stage = DocStage.open; } } // syck_emit_tag public void emitTag(String tag, String ignore) { if(tag == null) { return; } if(ignore != null && ImplicitScanner2.tagcmp(tag, ignore) && !this.explicit_typing) { return; } Level lvl = currentLevel(); if(tag.length() == 0) { write(BANG_SPACE, 2); } else if(tag.startsWith("tag:")) { int taglen = tag.length(); Pointer ptag = Pointer.create(tag); write(BANG, 1); if(tag.substring(4).startsWith(YAML.DOMAIN)) { int skip = 4 + YAML.DOMAIN.length() + 1; write(ptag.withStart(skip), taglen - skip); } else { int subd = 4; while(subd < taglen && tag.charAt(subd) != ':') { subd++; } if(subd < taglen && tag.charAt(subd) == ':') { if(subd > (YAML.DOMAIN.length() + 5) && tag.substring(subd - YAML.DOMAIN.length()).startsWith(YAML.DOMAIN)) { write(ptag.withStart(4), (subd - YAML.DOMAIN.length()) - 5); write(SLASH, 1); write(ptag.withStart(subd+1), taglen - (subd + 1)); } else { write(ptag.withStart(4), subd - 4); write(SLASH, 1); write(ptag.withStart(subd + 1), taglen - (subd + 1)); } } else { /* TODO: Invalid tag (no colon after domain) */ return; } } write(SPACE, 1); } else if(tag.startsWith("x-private:")) { write(TWO_BANGS, 2); write(Pointer.create(tag.substring(10)), tag.length()-10); write(SPACE, 1); } lvl.anctag = 1; } // syck_emit_indent public void emitIndent() { Level lvl = currentLevel(); if(bufpos == 0 && marker == 0) { return; } if(lvl.spaces >= 0) { byte[] spcs = new byte[lvl.spaces + 2]; spcs[0] = '\n'; spcs[lvl.spaces + 1] = 0; for(int i=0; i': case '\'': case '"': case '#': case '%': case '@': case '`': flags |= SCAN_INDIC_S; break; case '-': case ':': case '?': case ',': if(len == 1 || cursorb[cursor+1] == ' ' || cursorb[cursor+1] == '\n') { flags |= SCAN_INDIC_S; } break; } if(cursorb[cursor + len - 1] != '\n') { flags |= SCAN_NONL_E; } else if(len > 1 && cursorb[cursor + len - 2] == '\n') { flags |= SCAN_MANYNL_E; } if( (len>0 && (cursorb[cursor] == ' ' || cursorb[cursor] == '\t')) || (len>1 && (cursorb[cursor + len - 1] == ' ' || cursorb[cursor + len - 1] == '\t')) ) { flags |= SCAN_WHITEEDGE; } if(len >= 3 && cursorb[cursor] == '-' && cursorb[cursor+1] == '-' && cursorb[cursor+2] == '-') { flags |= SCAN_DOCSEP; } for(int i=0; i= 0x20 && ci <= 0x7E))) { flags |= SCAN_NONPRINT; } else if(ci == '\n') { flags |= SCAN_NEWLINE; if(len - i >= 3 && cursorb[cursor+i+1] == '-' && cursorb[cursor+i+2] == '-' && cursorb[cursor+i+3] == '-' ) { flags |= SCAN_DOCSEP; } if(i+1 < len && (cursorb[cursor+i+1] == ' ' || cursorb[cursor+i+1] == '\t')) { flags |= SCAN_INDENTED; } if(req_width > 0 && (i - start) > req_width) { flags |= SCAN_WIDE; } start = i; } else if(ci == '\'') { flags |= SCAN_SINGLEQ; } else if(ci == '"') { flags |= SCAN_DOUBLEQ; } else if(ci == ']') { flags |= SCAN_FLOWSEQ; } else if(ci == '}') { flags |= SCAN_FLOWMAP; } else if(((ci == ' ' && (i+1 0) { lvl.spaces = parent.spaces + force_indent; } else if((scan & SCAN_DOCSEP) != 0) { lvl.spaces = parent.spaces + this.indent; } if((parent.status == LevelStatus.map || parent.status == LevelStatus.mapx) && parent.ncount % 2 == 1) { if(force_style != ScalarStyle.Plain) { force_style = ScalarStyle.TwoQuote; } } if(parent.status == LevelStatus.imap || parent.status == LevelStatus.iseq) { if(force_style != ScalarStyle.Plain && force_style != ScalarStyle.OneQuote) { force_style = ScalarStyle.TwoQuote; } } if((scan & SCAN_NONL_E) != 0) { keep_nl = YAML.NL_CHOMP; } else if((scan & SCAN_MANYNL_E) != 0) { keep_nl = YAML.NL_KEEP; } switch(force_style) { case OneQuote: emit1Quoted(force_width, _str, len); break; case None: case TwoQuote: emit2Quoted(force_width, _str, len); break; case Fold: emitFolded(force_width, keep_nl, _str, len); break; case Literal: emitLiteral(keep_nl, _str, len); break; case Plain: write(_str, len); break; } if(parent.status == LevelStatus.mapx) { write(NEWLINE, 1); } } private final static Pointer hex_table = Pointer.create("0123456789ABCDEF"); // syck_emitter_escape public void escape(Pointer _src, int len) { byte[] bsrc = _src.buffer; int src = _src.start; for(int i=0; i> 4), 1); write(hex_table.withStart(curr & 0x0F), 1); } } else { write(_src.withStart(src+i), 1); if(curr == '\\') { write(BACKSLASH, 1); } } } } // syck_emit_1quoted public void emit1Quoted(int width, Pointer _str, final int len) { byte[] bstr = _str.buffer; int str = _str.start; boolean do_indent = false; int mark = str; int start = str; int end = str; write(SINGLE_QUOTE, 1); while(mark < str + len) { if(do_indent) { emitIndent(); do_indent = false; } switch(bstr[mark]) { case '\'': write(SINGLE_QUOTE, 1); break; case '\n': end = mark + 1; if(bstr[start] != ' ' && bstr[start] != '\n' && bstr[end] != '\n' && bstr[end] != ' ' ) { write(TWO_NEWLINES, 2); } else { write(NEWLINE, 1); } do_indent = true; start = mark + 1; break; case ' ': if(width > 0 && bstr[start] != ' ' && mark - end > width ) { do_indent = true; end = mark + 1; } else { write(SPACE, 1); } break; default: write(_str.withStart(mark), 1); break; } } write(SINGLE_QUOTE, 1); } private final static Pointer SLASH_QUOTE = Pointer.create("\\\""); private final static Pointer SLASH_SLASH = Pointer.create("\\\\"); private final static Pointer SLASH_ZERO = Pointer.create("\\0"); private final static Pointer SLASH_A = Pointer.create("\\a"); private final static Pointer SLASH_B = Pointer.create("\\b"); private final static Pointer SLASH_F = Pointer.create("\\f"); private final static Pointer SLASH_R = Pointer.create("\\r"); private final static Pointer SLASH_T = Pointer.create("\\t"); private final static Pointer SLASH_V = Pointer.create("\\v"); private final static Pointer SLASH_E = Pointer.create("\\e"); private final static Pointer SLASH_N = Pointer.create("\\n"); // syck_emit_2quoted public void emit2Quoted(int width, Pointer _str, final int len) { byte[] bstr = _str.buffer; int str = _str.start; int do_indent = 0; int mark = str; int start = str; int end = str; write(DOUBLE_QUOTE, 1); while( mark < str + len ) { if(do_indent > 0 ) { if(do_indent == 2) { write(BACKSLASH, 1); } emitIndent(); do_indent = 0; } switch(bstr[mark]) { /* Escape sequences allowed within double quotes. */ case '"': write( SLASH_QUOTE, 2 ); break; case '\\': write( SLASH_SLASH, 2 ); break; case '\0': write( SLASH_ZERO, 2 ); break; case 0x07: write( SLASH_A, 2 ); break; case '\b': write( SLASH_B, 2 ); break; case '\f': write( SLASH_F, 2 ); break; case '\r': write( SLASH_R, 2 ); break; case '\t': write( SLASH_T, 2 ); break; case 0x0B: write( SLASH_V, 2 ); break; case 0x1B: write( SLASH_E, 2 ); break; case '\n': end = mark + 1; write( SLASH_N, 2 ); do_indent = 2; start = mark + 1; if( start < str + len && ( bstr[start] == ' ' || bstr[start] == '\n' ) ) { do_indent = 0; } break; case ' ': if( width > 0 && bstr[start] != ' ' && mark - end > width ) { do_indent = 1; end = mark + 1; } else { write(SPACE, 1 ); } break; default: escape(_str.withStart(mark), 1 ); break; } mark++; } write(DOUBLE_QUOTE, 1 ); } // syck_emit_literal public void emitLiteral(int keep_nl, Pointer _str, int len) { byte[] bstr = _str.buffer; int str = _str.start; int mark = str; int start = str; int end = str; write(PIPE, 1); if(keep_nl == YAML.NL_CHOMP) { write(MINUS, 1); } else if(keep_nl == YAML.NL_KEEP) { write(PLUS, 1); } emitIndent(); while(mark < str + len) { if(bstr[mark] == '\n') { end = mark; if( bstr[start] != ' ' && bstr[start] != '\n' && bstr[end] != '\n' && bstr[end] != ' ' ) end += 1; write(_str.withStart(start), end - start); if(mark + 1 == str + len) { if(keep_nl != YAML.NL_KEEP) write(NEWLINE, 1); } else { emitIndent(); } start = mark + 1; } mark++; } end = str + len; if( start < end ) { write(_str.withStart(start), end - start); } } // syck_emit_folded public void emitFolded(int width, int keep_nl, Pointer _str, int len) { byte[] bstr = _str.buffer; int str = _str.start; int mark = str; int start = str; int end = str; write(GT, 1); if(keep_nl == YAML.NL_CHOMP) { write(MINUS, 1); } else if(keep_nl == YAML.NL_KEEP) { write(PLUS, 1); } emitIndent(); if(width <= 0) width = this.best_width; while(mark < str + len) { switch(bstr[mark]) { case '\n': write(_str.withStart(end), mark - end ); end = mark + 1; if(bstr[start] != ' ' && bstr[start] != '\n' && bstr[end] != '\n' && bstr[end] != ' ' ) { write(NEWLINE, 1); } if(mark + 1 == str + len) { if(keep_nl != YAML.NL_KEEP) write(NEWLINE, 1); } else { emitIndent(); } start = mark + 1; break; case ' ': if(bstr[start] != ' ') { if(mark - end > width) { write(_str.withStart(end), mark - end ); emitIndent(); end = mark + 1; } } break; } mark++; } if(end < mark) { write(_str.withStart(end), mark - end); } } // syck_emit_seq public void emitSeq(String tag, SeqStyle style) { Level parent = parentLevel(); Level lvl = currentLevel(); if(parent.status == LevelStatus.map && parent.ncount % 2 == 1) { write(QUESTION_MARK_SPACE, 2); parent.status = LevelStatus.mapx; } emitTag(tag, "tag:yaml.org,2002:seq"); if(style == SeqStyle.Inline || (parent.status == LevelStatus.imap || parent.status == LevelStatus.iseq)) { write(SQUARE_OPEN, 1); lvl.status = LevelStatus.iseq; } else { lvl.status = LevelStatus.seq; } } // syck_emit_map public void emitMap(String tag, MapStyle style) { Level parent = parentLevel(); Level lvl = currentLevel(); if(parent.status == LevelStatus.map && parent.ncount % 2 == 1) { write(QUESTION_MARK_SPACE, 2); parent.status = LevelStatus.mapx; } emitTag(tag, "tag:yaml.org,2002:map"); if(style == MapStyle.Inline || (parent.status == LevelStatus.imap || parent.status == LevelStatus.iseq)) { write(CURLY_OPEN, 1); lvl.status = LevelStatus.imap; } else { lvl.status = LevelStatus.map; } } // syck_emit_item public void emitItem(Object n) { Level lvl = currentLevel(); switch(lvl.status) { case seq: { Level parent = parentLevel(); if(parent.status == LevelStatus.mapx && lvl.ncount == 0) { if(parent.ncount % 2 == 0 && lvl.anctag == 0) { lvl.spaces = parent.spaces; } } else if(lvl.anctag == 0 && parent.status == LevelStatus.seq && lvl.ncount == 0) { int spcs = (lvl.spaces - parent.spaces ) - 2; if(spcs >= 0) { for(int i = 0; i < spcs; i++) { write(SPACE, 1); } write(DASH_SPACE, 2); break; } } emitIndent(); write(DASH_SPACE, 2); break; } case iseq: if(lvl.ncount > 0) { write(COMMA_SPACE, 2); } break; case map: { Level parent = parentLevel(); if(lvl.anctag == 0 && parent.status == LevelStatus.seq && lvl.ncount == 0) { int spcs = (lvl.spaces - parent.spaces) - 2; if(spcs >= 0) { for(int i = 0; i < spcs; i++) { write(SPACE, 1); } break; } } if(lvl.ncount % 2 == 0) { emitIndent(); } else { write(COLON_SPACE, 2); } break; } case mapx: { if(lvl.ncount % 2 == 0) { emitIndent(); lvl.status = LevelStatus.map; } else { if(lvl.spaces > 0) { byte[] spcs = new byte[lvl.spaces]; java.util.Arrays.fill(spcs, (byte)' '); write(Pointer.create(spcs, 0), lvl.spaces); } write(COLON_SPACE, 2); } break; } case imap: { if(lvl.ncount > 0) { if(lvl.ncount % 2 == 0) { write(COMMA_SPACE, 2); } else { write(COLON_SPACE, 2); } } break; } default: break; } lvl.ncount++; emit(n); } // syck_emit_end public void emitEnd() { Level lvl = currentLevel(); Level parent = parentLevel(); switch(lvl.status) { case seq: if(lvl.ncount == 0) { write(EMPTY_ARRAY, 3); } else if(parent.status == LevelStatus.mapx) { write(NEWLINE, 1); } break; case iseq: write(SQUARE_CLOSE, 1); if(parent.status == LevelStatus.mapx) { write(NEWLINE, 1); } break; case map: if(lvl.ncount == 0) { write(EMPTY_HASH, 3); } else if(lvl.ncount % 2 == 1) { write(COLON, 1); } else if(parent.status == LevelStatus.mapx) { write(NEWLINE, 1); } break; case imap: write(CURLY_CLOSE, 1); if(parent.status == LevelStatus.mapx) { write(NEWLINE, 1); } break; default: break; } } // syck_emitter_mark_node public long markNode(Object n) { long oid = 0; if(this.markers == null) { this.markers = new IdentityHashMap(); } if(!this.markers.containsKey(n)) { oid = this.markers.size() + 1; markers.put(n, oid); } else { oid = this.markers.get(n); if(this.anchors == null) { this.anchors = new HashMap(); } if(!anchors.containsKey(oid)) { int idx = 0; String anc = this.anchor_format == null ? YAML.DEFAULT_ANCHOR_FORMAT : this.anchor_format; idx = anchors.size() + 1; String anchor_name = String.format(anc, idx); anchors.put(oid, anchor_name); } } return oid; } }// Emitter yecht-yecht-1.1/src/main/org/yecht/EmitterHandler.java000066400000000000000000000004151262256356000230000ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public interface EmitterHandler { void handle(Emitter e, Object data); }// EmitterHandler yecht-yecht-1.1/src/main/org/yecht/ErrorHandler.java000066400000000000000000000010331262256356000224550ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public interface ErrorHandler { void handle(Parser p, String msg); public static class Default implements ErrorHandler { // syck_default_error_handler public void handle(Parser p, String msg) { System.err.println("Error at [Line " + p.linect + ", Col " + (p.cursor - p.lineptr) + "]: " + msg); } } }// ErrorHandler yecht-yecht-1.1/src/main/org/yecht/IOType.java000066400000000000000000000003351262256356000212430ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public enum IOType { Str, File }// IOType yecht-yecht-1.1/src/main/org/yecht/ImplicitScanner.java000066400000000000000000001260031262256356000231570ustar00rootroot00000000000000/* Generated by re2j 0.13.6.dev on Mon Jul 27 17:41:42 2009 */ package org.yecht; // Equivalent to implicit.re public class ImplicitScanner { // syck_type_id_to_uri public static String typeIdToUri(String type_id) { // System.err.println("typeIdToUri(" + type_id + ")"); byte[] data = null; try { data = type_id.getBytes("ISO8859-1"); } catch(Exception e) {} byte[] dx = new byte[data.length+1]; System.arraycopy(data, 0, dx, 0, data.length); dx[data.length] = 0; data = dx; int cursor = 0; int limit = data.length; int marker = -1; int gotoPoint = -1; byte yych = (byte) 0; gotoNext: while(gotoPoint != -2) { int currentGoto = gotoPoint; gotoPoint = -2; switch(currentGoto) { case -1: yych = data[cursor]; switch (yych) { case 0x00: {gotoPoint = 2; continue gotoNext;} case '!': {gotoPoint = 6; continue gotoNext;} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 'u': case 'v': case 'w': case 'y': case 'z': {gotoPoint = 8; continue gotoNext;} case 't': {gotoPoint = 3; continue gotoNext;} case 'x': {gotoPoint = 5; continue gotoNext;} default: {gotoPoint = 9; continue gotoNext;} } case 2: cursor = marker; {gotoPoint = 4; continue gotoNext;} case 3: yych = data[(marker = ++cursor)]; switch (yych) { case ',': {gotoPoint = 14; continue gotoNext;} case '-': {gotoPoint = 10; continue gotoNext;} case '.': {gotoPoint = 15; continue gotoNext;} case '/': {gotoPoint = 16; continue gotoNext;} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 12; continue gotoNext;} case 'a': {gotoPoint = 44; continue gotoNext;} default: {gotoPoint = 4; continue gotoNext;} } case 4: { return Parser.taguri(YAML.DOMAIN, type_id); } case 5: yych = data[(marker = ++cursor)]; switch (yych) { case ',': case '.': case '/': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 13; continue gotoNext;} case '-': {gotoPoint = 34; continue gotoNext;} default: {gotoPoint = 4; continue gotoNext;} } case 6: ++cursor; { return Parser.xprivate(type_id.substring(1)); } case 8: yych = data[(marker = ++cursor)]; switch (yych) { case ',': {gotoPoint = 14; continue gotoNext;} case '-': {gotoPoint = 10; continue gotoNext;} case '.': {gotoPoint = 15; continue gotoNext;} case '/': {gotoPoint = 16; continue gotoNext;} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 12; continue gotoNext;} default: {gotoPoint = 4; continue gotoNext;} } case 9: yych = data[++cursor]; {gotoPoint = 4; continue gotoNext;} case 10: ++cursor; yych = data[cursor]; case 11: switch (yych) { case '-': {gotoPoint = 10; continue gotoNext;} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 12; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 12: ++cursor; yych = data[cursor]; case 13: switch (yych) { case ',': {gotoPoint = 14; continue gotoNext;} case '-': {gotoPoint = 10; continue gotoNext;} case '.': {gotoPoint = 15; continue gotoNext;} case '/': {gotoPoint = 16; continue gotoNext;} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 12; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 14: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 22; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 15: ++cursor; yych = data[cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 18; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 16: ++cursor; { return Parser.taguri(type_id.substring(0, cursor -1) + "." + YAML.DOMAIN, type_id.substring(cursor)); } case 18: ++cursor; yych = data[cursor]; switch (yych) { case ',': {gotoPoint = 14; continue gotoNext;} case '-': {gotoPoint = 20; continue gotoNext;} case '.': {gotoPoint = 15; continue gotoNext;} case '/': {gotoPoint = 16; continue gotoNext;} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 18; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 20: ++cursor; yych = data[cursor]; switch (yych) { case '-': {gotoPoint = 20; continue gotoNext;} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 18; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 22: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 23; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 23: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 24; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 24: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 25; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 25: yych = data[++cursor]; switch (yych) { case '-': {gotoPoint = 26; continue gotoNext;} case '/': {gotoPoint = 27; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 26: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 29; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 27: ++cursor; { return Parser.taguri(type_id.substring(0, cursor-1), type_id.substring(cursor)); } case 29: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 30; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 30: yych = data[++cursor]; switch (yych) { case '-': {gotoPoint = 31; continue gotoNext;} case '/': {gotoPoint = 27; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 31: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 32; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 32: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 33; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 33: yych = data[++cursor]; switch (yych) { case '/': {gotoPoint = 27; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 34: yych = data[++cursor]; switch (yych) { case 'p': {gotoPoint = 35; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 35: yych = data[++cursor]; switch (yych) { case ',': {gotoPoint = 14; continue gotoNext;} case '.': {gotoPoint = 15; continue gotoNext;} case '/': {gotoPoint = 16; continue gotoNext;} case 'r': {gotoPoint = 36; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 36: yych = data[++cursor]; switch (yych) { case ',': {gotoPoint = 14; continue gotoNext;} case '.': {gotoPoint = 15; continue gotoNext;} case '/': {gotoPoint = 16; continue gotoNext;} case 'i': {gotoPoint = 37; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 37: yych = data[++cursor]; switch (yych) { case ',': {gotoPoint = 14; continue gotoNext;} case '.': {gotoPoint = 15; continue gotoNext;} case '/': {gotoPoint = 16; continue gotoNext;} case 'v': {gotoPoint = 38; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 38: yych = data[++cursor]; switch (yych) { case ',': {gotoPoint = 14; continue gotoNext;} case '.': {gotoPoint = 15; continue gotoNext;} case '/': {gotoPoint = 16; continue gotoNext;} case 'a': {gotoPoint = 39; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 39: yych = data[++cursor]; switch (yych) { case ',': {gotoPoint = 14; continue gotoNext;} case '.': {gotoPoint = 15; continue gotoNext;} case '/': {gotoPoint = 16; continue gotoNext;} case 't': {gotoPoint = 40; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 40: yych = data[++cursor]; switch (yych) { case ',': {gotoPoint = 14; continue gotoNext;} case '.': {gotoPoint = 15; continue gotoNext;} case '/': {gotoPoint = 16; continue gotoNext;} case 'e': {gotoPoint = 41; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 41: yych = data[++cursor]; switch (yych) { case ',': {gotoPoint = 14; continue gotoNext;} case '.': {gotoPoint = 15; continue gotoNext;} case '/': {gotoPoint = 16; continue gotoNext;} case ':': {gotoPoint = 42; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 42: ++cursor; { return type_id; } case 44: yych = data[++cursor]; switch (yych) { case ',': {gotoPoint = 14; continue gotoNext;} case '.': {gotoPoint = 15; continue gotoNext;} case '/': {gotoPoint = 16; continue gotoNext;} case 'g': {gotoPoint = 45; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 45: yych = data[++cursor]; switch (yych) { case ',': {gotoPoint = 14; continue gotoNext;} case '.': {gotoPoint = 15; continue gotoNext;} case '/': {gotoPoint = 16; continue gotoNext;} case ':': {gotoPoint = 46; continue gotoNext;} default: {gotoPoint = 11; continue gotoNext;} } case 46: yych = data[++cursor]; switch (yych) { case ',': case '-': case '.': {gotoPoint = 2; continue gotoNext;} default: {gotoPoint = 48; continue gotoNext;} } case 47: ++cursor; yych = data[cursor]; case 48: switch (yych) { case ',': {gotoPoint = 51; continue gotoNext;} case '-': {gotoPoint = 49; continue gotoNext;} case '.': {gotoPoint = 52; continue gotoNext;} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 47; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 49: ++cursor; yych = data[cursor]; switch (yych) { case '-': {gotoPoint = 49; continue gotoNext;} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 47; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 51: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 57; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 52: ++cursor; yych = data[cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 53; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 53: ++cursor; yych = data[cursor]; switch (yych) { case ',': {gotoPoint = 51; continue gotoNext;} case '-': {gotoPoint = 55; continue gotoNext;} case '.': {gotoPoint = 52; continue gotoNext;} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 53; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 55: ++cursor; yych = data[cursor]; switch (yych) { case '-': {gotoPoint = 55; continue gotoNext;} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 53; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 57: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 58; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 58: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 59; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 59: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 60; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 60: yych = data[++cursor]; switch (yych) { case '-': {gotoPoint = 61; continue gotoNext;} case ':': {gotoPoint = 62; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 61: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 64; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 62: ++cursor; { return type_id; } case 64: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 65; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 65: yych = data[++cursor]; switch (yych) { case '-': {gotoPoint = 66; continue gotoNext;} case ':': {gotoPoint = 62; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 66: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 67; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 67: yych = data[++cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {gotoPoint = 68; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } case 68: ++cursor; switch ((yych = data[cursor])) { case ':': {gotoPoint = 62; continue gotoNext;} default: {gotoPoint = 2; continue gotoNext;} } } } return null; } } yecht-yecht-1.1/src/main/org/yecht/ImplicitScanner.re000066400000000000000000000032761262256356000226520ustar00rootroot00000000000000package org.yecht; // Equivalent to implicit.re public class ImplicitScanner { // syck_type_id_to_uri public static String typeIdToUri(String type_id) { // System.err.println("typeIdToUri(" + type_id + ")"); byte[] data = null; try { data = type_id.getBytes("ISO8859-1"); } catch(Exception e) {} byte[] dx = new byte[data.length+1]; System.arraycopy(data, 0, dx, 0, data.length); dx[data.length] = 0; data = dx; int cursor = 0; int limit = data.length; int marker = -1; /*!re2j re2j:define:YYCTYPE = "byte"; re2j:define:YYCURSOR = "cursor"; re2j:define:YYMARKER = "marker"; re2j:define:YYLIMIT = "limit"; re2j:define:YYDATA = "data"; re2j:yyfill:enable = 0; DIGIT = [0-9] ; ANY = [\001-\377] ; YEAR = DIGIT DIGIT DIGIT DIGIT ; MON = DIGIT DIGIT ; TAG = "tag" ; XPRIVATE = "x-private" ; WD = [A-Za-z0-9_] ; WDD = [A-Za-z0-9_-] ; DNSCOMPRE = WD ( WDD* WD )? ; DNSNAMERE = ( ( DNSCOMPRE "." )+ DNSCOMPRE | DNSCOMPRE ) ; TAGDATE = YEAR ( "-" MON )? ( "-" MON )? ; TAG ":" DNSNAMERE "," TAGDATE ":" { return type_id; } XPRIVATE ":" { return type_id; } "!" { return Parser.xprivate(type_id.substring(1)); } DNSNAMERE "/" { return Parser.taguri(type_id.substring(0, cursor -1) + "." + YAML.DOMAIN, type_id.substring(cursor)); } DNSNAMERE "," TAGDATE "/" { return Parser.taguri(type_id.substring(0, cursor-1), type_id.substring(cursor)); } ANY { return Parser.taguri(YAML.DOMAIN, type_id); } */ return null; } } yecht-yecht-1.1/src/main/org/yecht/ImplicitScanner2.java000066400000000000000000000436661262256356000232560ustar00rootroot00000000000000// line 1 "src/main/org/yecht/ImplicitScanner2.rl" package org.yecht; // Equivalent to implicit.re public class ImplicitScanner2 { // try_tag_implicit public static void tryTagImplicit(Node n, boolean taguri) { String tid = ""; switch(n.kind) { case Str: Data.Str s = (Data.Str)n.data; tid = matchImplicit(s.ptr, s.len); break; case Seq: tid = "seq"; break; case Map: tid = "map"; break; default: break; } if(taguri) { n.type_id = Parser.taguri(YAML.DOMAIN, tid); } else { n.type_id = tid; } } // syck_tagcmp public static boolean tagcmp(String tag1, String tag2) { if(tag1 == tag2) return true; if(tag1 == null || tag2 == null) return false; if(tag1.equals(tag2)) return true; int slen1 = tag1.indexOf('#'); if(slen1 == -1) slen1 = tag1.length(); int slen2 = tag2.indexOf('#'); if(slen2 == -1) slen2 = tag2.length(); return tag1.substring(0, slen1).equals(tag2.substring(0,slen2)); } // line 78 "src/main/org/yecht/ImplicitScanner2.rl" // line 48 "src/main/org/yecht/ImplicitScanner2.java" private static byte[] init__ImplicitScanner_actions_0() { return new byte [] { 0, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 17, 1, 18, 2, 14, 16 }; } private static final byte _ImplicitScanner_actions[] = init__ImplicitScanner_actions_0(); private static short[] init__ImplicitScanner_key_offsets_0() { return new short [] { 0, 0, 19, 23, 25, 27, 28, 29, 30, 35, 37, 39, 44, 48, 55, 59, 61, 63, 64, 65, 66, 70, 72, 73, 74, 75, 77, 79, 80, 82, 84, 88, 90, 91, 93, 95, 96, 98, 100, 103, 108, 110, 112, 114, 116, 120, 122, 124, 125, 127, 129, 130, 132, 134, 138, 140, 142, 144, 146, 152, 158, 160, 162, 163, 165, 167, 168, 170, 172, 176, 181, 187, 192, 197, 198, 200, 201, 202, 203, 204, 205, 206, 210, 211, 212, 213, 214, 218, 219, 220, 222, 223, 224, 225, 226, 228, 229, 230, 231, 233, 235, 236, 237, 237, 245, 252, 258, 261, 263, 267, 270, 272, 279, 284, 284, 284, 292, 299, 306, 314, 318, 319, 319, 320, 320, 320, 325, 330, 335, 341, 341, 341, 341, 341 }; } private static final short _ImplicitScanner_key_offsets[] = init__ImplicitScanner_key_offsets_0(); private static char[] init__ImplicitScanner_trans_keys_0() { return new char [] { 43, 45, 46, 48, 60, 61, 70, 78, 79, 84, 89, 102, 110, 111, 116, 121, 126, 49, 57, 46, 48, 49, 57, 73, 105, 78, 110, 70, 102, 110, 46, 69, 101, 48, 57, 43, 45, 48, 57, 44, 46, 58, 48, 57, 48, 53, 54, 57, 44, 48, 57, 65, 70, 97, 102, 46, 48, 49, 57, 73, 105, 78, 110, 70, 102, 110, 73, 78, 105, 110, 65, 97, 78, 97, 110, 48, 57, 48, 57, 45, 48, 57, 48, 57, 9, 32, 48, 57, 48, 57, 58, 48, 57, 48, 57, 58, 48, 57, 48, 57, 9, 32, 46, 9, 32, 43, 45, 90, 48, 57, 48, 57, 48, 57, 48, 57, 9, 32, 48, 57, 48, 57, 48, 57, 58, 48, 57, 48, 57, 58, 48, 57, 48, 57, 43, 45, 46, 90, 48, 57, 48, 57, 48, 57, 48, 57, 43, 45, 48, 90, 49, 57, 43, 45, 48, 90, 49, 57, 48, 57, 48, 57, 58, 48, 57, 48, 57, 58, 48, 57, 48, 57, 43, 45, 46, 90, 43, 45, 90, 48, 57, 44, 45, 46, 58, 48, 57, 44, 46, 58, 48, 57, 44, 46, 58, 48, 57, 60, 65, 97, 76, 83, 69, 108, 115, 101, 79, 85, 111, 117, 76, 76, 108, 108, 70, 78, 102, 110, 70, 102, 82, 114, 85, 69, 117, 101, 69, 101, 83, 115, 97, 111, 117, 102, 110, 114, 101, 44, 46, 58, 120, 48, 55, 56, 57, 44, 46, 58, 48, 55, 56, 57, 44, 46, 69, 101, 48, 57, 44, 48, 57, 48, 57, 46, 58, 48, 57, 44, 48, 57, 46, 58, 44, 48, 57, 65, 70, 97, 102, 44, 46, 58, 48, 57, 44, 46, 58, 120, 48, 55, 56, 57, 44, 46, 58, 48, 55, 56, 57, 44, 46, 58, 48, 55, 56, 57, 44, 45, 46, 58, 48, 55, 56, 57, 9, 32, 84, 116, 58, 58, 44, 46, 58, 48, 57, 44, 46, 58, 48, 57, 44, 46, 58, 48, 57, 44, 45, 46, 58, 48, 57, 0 }; } private static final char _ImplicitScanner_trans_keys[] = init__ImplicitScanner_trans_keys_0(); private static byte[] init__ImplicitScanner_single_lengths_0() { return new byte [] { 0, 17, 2, 2, 2, 1, 1, 1, 3, 2, 0, 3, 0, 1, 2, 2, 2, 1, 1, 1, 4, 2, 1, 1, 1, 0, 0, 1, 0, 0, 2, 0, 1, 0, 0, 1, 0, 0, 3, 5, 0, 0, 0, 0, 2, 0, 0, 1, 0, 0, 1, 0, 0, 4, 0, 0, 0, 0, 4, 4, 0, 0, 1, 0, 0, 1, 0, 0, 4, 3, 4, 3, 3, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 4, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 1, 1, 0, 4, 3, 4, 1, 0, 2, 1, 2, 1, 3, 0, 0, 4, 3, 3, 4, 4, 1, 0, 1, 0, 0, 3, 3, 3, 4, 0, 0, 0, 0, 0 }; } private static final byte _ImplicitScanner_single_lengths[] = init__ImplicitScanner_single_lengths_0(); private static byte[] init__ImplicitScanner_range_lengths_0() { return new byte [] { 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 2, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 1, 1, 1, 1, 1, 0, 3, 1, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; } private static final byte _ImplicitScanner_range_lengths[] = init__ImplicitScanner_range_lengths_0(); private static short[] init__ImplicitScanner_index_offsets_0() { return new short [] { 0, 0, 19, 23, 26, 29, 31, 33, 35, 40, 43, 45, 50, 53, 58, 62, 65, 68, 70, 72, 74, 79, 82, 84, 86, 88, 90, 92, 94, 96, 98, 102, 104, 106, 108, 110, 112, 114, 116, 120, 126, 128, 130, 132, 134, 138, 140, 142, 144, 146, 148, 150, 152, 154, 159, 161, 163, 165, 167, 173, 179, 181, 183, 185, 187, 189, 191, 193, 195, 200, 205, 211, 216, 221, 223, 226, 228, 230, 232, 234, 236, 238, 243, 245, 247, 249, 251, 256, 258, 260, 263, 265, 267, 269, 271, 274, 276, 278, 280, 283, 286, 288, 290, 291, 298, 304, 310, 313, 315, 319, 322, 325, 330, 335, 336, 337, 344, 350, 356, 363, 368, 370, 371, 373, 374, 375, 380, 385, 390, 396, 397, 398, 399, 400 }; } private static final short _ImplicitScanner_index_offsets[] = init__ImplicitScanner_index_offsets_0(); private static short[] init__ImplicitScanner_indicies_0() { return new short [] { 0, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 5, 1, 19, 20, 21, 1, 22, 23, 1, 24, 25, 1, 26, 1, 26, 1, 25, 1, 27, 28, 28, 27, 1, 29, 29, 1, 30, 1, 31, 32, 33, 31, 1, 34, 35, 1, 36, 36, 36, 36, 1, 37, 20, 21, 1, 38, 39, 1, 40, 41, 1, 42, 1, 42, 1, 41, 1, 22, 43, 23, 44, 1, 45, 45, 1, 46, 1, 47, 1, 46, 1, 48, 1, 49, 1, 50, 1, 51, 1, 52, 1, 53, 53, 54, 1, 55, 1, 56, 1, 57, 1, 58, 1, 59, 1, 60, 1, 61, 1, 62, 62, 63, 1, 62, 62, 64, 64, 65, 1, 66, 1, 67, 1, 68, 1, 65, 1, 62, 62, 63, 1, 69, 1, 70, 1, 71, 1, 72, 1, 73, 1, 74, 1, 75, 1, 76, 1, 77, 77, 78, 79, 1, 80, 1, 81, 1, 82, 1, 83, 1, 77, 77, 78, 83, 84, 1, 77, 77, 78, 79, 84, 1, 85, 1, 86, 1, 87, 1, 88, 1, 89, 1, 90, 1, 91, 1, 92, 1, 77, 77, 93, 83, 1, 77, 77, 83, 93, 1, 31, 94, 32, 33, 31, 1, 31, 32, 33, 95, 1, 31, 32, 33, 96, 1, 97, 1, 98, 99, 1, 100, 1, 101, 1, 102, 1, 103, 1, 104, 1, 102, 1, 102, 105, 102, 106, 1, 107, 1, 18, 1, 108, 1, 18, 1, 109, 110, 111, 110, 1, 102, 1, 102, 1, 112, 113, 1, 114, 1, 110, 1, 115, 1, 110, 1, 116, 117, 1, 110, 1, 110, 1, 99, 1, 102, 106, 1, 111, 110, 1, 113, 1, 117, 1, 1, 118, 32, 33, 119, 118, 31, 1, 118, 32, 33, 118, 31, 1, 120, 27, 28, 28, 32, 1, 120, 120, 1, 30, 1, 121, 33, 35, 1, 121, 121, 1, 121, 33, 1, 36, 36, 36, 36, 1, 21, 32, 33, 21, 1, 1, 1, 118, 32, 33, 119, 122, 123, 1, 118, 32, 33, 124, 96, 1, 118, 32, 33, 125, 95, 1, 118, 94, 32, 33, 118, 31, 1, 53, 53, 126, 127, 1, 128, 1, 1, 129, 1, 1, 1, 21, 32, 33, 130, 1, 21, 32, 33, 131, 1, 21, 32, 33, 132, 1, 21, 94, 32, 33, 21, 1, 1, 1, 1, 1, 1, 0 }; } private static final short _ImplicitScanner_indicies[] = init__ImplicitScanner_indicies_0(); private static short[] init__ImplicitScanner_trans_targs_0() { return new short [] { 2, 0, 14, 20, 115, 125, 73, 130, 74, 81, 86, 89, 94, 97, 98, 99, 100, 101, 132, 3, 103, 112, 4, 7, 5, 6, 102, 8, 9, 10, 107, 11, 105, 12, 108, 110, 111, 15, 16, 19, 17, 18, 113, 21, 23, 22, 114, 24, 26, 27, 28, 29, 119, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 44, 40, 121, 41, 120, 43, 46, 47, 48, 49, 50, 51, 52, 53, 54, 58, 124, 55, 122, 57, 123, 59, 61, 62, 63, 64, 65, 66, 67, 68, 69, 25, 70, 71, 129, 75, 78, 76, 77, 131, 79, 80, 82, 84, 83, 85, 87, 133, 88, 90, 92, 91, 93, 95, 96, 104, 13, 106, 109, 116, 72, 117, 118, 45, 60, 42, 56, 126, 127, 128 }; } private static final short _ImplicitScanner_trans_targs[] = init__ImplicitScanner_trans_targs_0(); private static byte[] init__ImplicitScanner_trans_actions_0() { return new byte [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; } private static final byte _ImplicitScanner_trans_actions[] = init__ImplicitScanner_trans_actions_0(); private static byte[] init__ImplicitScanner_eof_actions_0() { return new byte [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 13, 9, 15, 15, 17, 11, 19, 11, 7, 13, 23, 25, 13, 9, 9, 9, 27, 31, 31, 29, 29, 37, 13, 13, 13, 13, 35, 33, 5, 1, 3 }; } private static final byte _ImplicitScanner_eof_actions[] = init__ImplicitScanner_eof_actions_0(); static final int ImplicitScanner_start = 1; static final int ImplicitScanner_error = 0; static final int ImplicitScanner_en_main = 1; // line 81 "src/main/org/yecht/ImplicitScanner2.rl" // syck_match_implicit public static String matchImplicit(Pointer ptr, int len) { String tag = "str"; int cs; int act; int have = 0; int nread = 0; int p=ptr.start; int pe = p+len; int eof = p+len; int tokstart = -1; int tokend = -1; byte[] data = ptr.buffer; if(len == 0) { data = new byte[]{(byte)'~'}; p = 0; pe = 1; eof = 1; } // line 319 "src/main/org/yecht/ImplicitScanner2.java" { cs = ImplicitScanner_start; } // line 104 "src/main/org/yecht/ImplicitScanner2.rl" // line 326 "src/main/org/yecht/ImplicitScanner2.java" { int _klen; int _trans = 0; int _keys; int _goto_targ = 0; _goto: while (true) { switch ( _goto_targ ) { case 0: if ( p == pe ) { _goto_targ = 4; continue _goto; } if ( cs == 0 ) { _goto_targ = 5; continue _goto; } case 1: _match: do { _keys = _ImplicitScanner_key_offsets[cs]; _trans = _ImplicitScanner_index_offsets[cs]; _klen = _ImplicitScanner_single_lengths[cs]; if ( _klen > 0 ) { int _lower = _keys; int _mid; int _upper = _keys + _klen - 1; while (true) { if ( _upper < _lower ) break; _mid = _lower + ((_upper-_lower) >> 1); if ( data[p] < _ImplicitScanner_trans_keys[_mid] ) _upper = _mid - 1; else if ( data[p] > _ImplicitScanner_trans_keys[_mid] ) _lower = _mid + 1; else { _trans += (_mid - _keys); break _match; } } _keys += _klen; _trans += _klen; } _klen = _ImplicitScanner_range_lengths[cs]; if ( _klen > 0 ) { int _lower = _keys; int _mid; int _upper = _keys + (_klen<<1) - 2; while (true) { if ( _upper < _lower ) break; _mid = _lower + (((_upper-_lower) >> 1) & ~1); if ( data[p] < _ImplicitScanner_trans_keys[_mid] ) _upper = _mid - 2; else if ( data[p] > _ImplicitScanner_trans_keys[_mid+1] ) _lower = _mid + 2; else { _trans += ((_mid - _keys)>>1); break _match; } } _trans += _klen; } } while (false); _trans = _ImplicitScanner_indicies[_trans]; cs = _ImplicitScanner_trans_targs[_trans]; case 2: if ( cs == 0 ) { _goto_targ = 5; continue _goto; } if ( ++p != pe ) { _goto_targ = 1; continue _goto; } case 4: if ( p == eof ) { int __acts = _ImplicitScanner_eof_actions[cs]; int __nacts = (int) _ImplicitScanner_actions[__acts++]; while ( __nacts-- > 0 ) { switch ( _ImplicitScanner_actions[__acts++] ) { case 0: // line 56 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "null";} break; case 1: // line 57 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "bool#yes";} break; case 2: // line 58 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "bool#no";} break; case 3: // line 59 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "int#hex";} break; case 4: // line 60 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "int#oct";} break; case 5: // line 61 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "int#base60";} break; case 6: // line 62 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "int";} break; case 7: // line 63 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "float#fix";} break; case 8: // line 64 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "float#exp";} break; case 9: // line 65 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "float#base60";} break; case 10: // line 66 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "float#inf";} break; case 11: // line 67 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "float#neginf";} break; case 12: // line 68 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "float#nan";} break; case 13: // line 69 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "timestamp#ymd";} break; case 14: // line 70 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "timestamp#iso8601";} break; case 15: // line 71 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "timestamp#spaced";} break; case 16: // line 72 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "timestamp";} break; case 17: // line 73 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "default";} break; case 18: // line 74 "src/main/org/yecht/ImplicitScanner2.rl" {tag = "merge";} break; // line 489 "src/main/org/yecht/ImplicitScanner2.java" } } } case 5: } break; } } // line 106 "src/main/org/yecht/ImplicitScanner2.rl" return tag; } } yecht-yecht-1.1/src/main/org/yecht/ImplicitScanner2.rl000066400000000000000000000074411262256356000227410ustar00rootroot00000000000000package org.yecht; // Equivalent to implicit.re public class ImplicitScanner2 { // try_tag_implicit public static void tryTagImplicit(Node n, boolean taguri) { String tid = ""; switch(n.kind) { case Str: Data.Str s = (Data.Str)n.data; tid = matchImplicit(s.ptr, s.len); break; case Seq: tid = "seq"; break; case Map: tid = "map"; break; default: break; } if(taguri) { n.type_id = Parser.taguri(YAML.DOMAIN, tid); } else { n.type_id = tid; } } // syck_tagcmp public static boolean tagcmp(String tag1, String tag2) { if(tag1 == tag2) return true; if(tag1 == null || tag2 == null) return false; if(tag1.equals(tag2)) return true; int slen1 = tag1.indexOf('#'); if(slen1 == -1) slen1 = tag1.length(); int slen2 = tag2.indexOf('#'); if(slen2 == -1) slen2 = tag2.length(); return tag1.substring(0, slen1).equals(tag2.substring(0,slen2)); } %%{ machine ImplicitScanner; DIGIT = [0-9] ; DIGITSC = [0-9,] ; DIGITSP = [0-9.] ; YEAR = DIGIT DIGIT DIGIT DIGIT ; MON = DIGIT DIGIT ; SIGN = [\-+] ; OCT = [0-7,] ; HEX = [0-9a-fA-F,] ; INF = ( "inf" | "Inf" | "INF" ) ; TIMEZ = ( "Z" | [\-+] DIGIT DIGIT ( ":" DIGIT DIGIT )? ) ; NULLTYPE = ( "~" | "null" | "Null" | "NULL" ) %/{tag = "null";} ; BOOLYES = ( "yes" | "Yes" | "YES" | "true" | "True" | "TRUE" | "on" | "On" | "ON" ) %/{tag = "bool#yes";} ; BOOLNO = ( "no" | "No" | "NO" | "false" | "False" | "FALSE" | "off" | "Off" | "OFF" ) %/{tag = "bool#no";} ; INTHEX = (SIGN? "0x" HEX+) %/{tag = "int#hex";}; INTOCT = (SIGN? "0" OCT+) %/{tag = "int#oct";}; INTSIXTY = (SIGN? DIGIT DIGITSC* ( ":" [0-5]? DIGIT )+ ) %/{tag = "int#base60";}; INTCANON = (SIGN? ( "0" | [1-9] DIGITSC* )) %/{tag = "int";}; FLOATFIX = (SIGN? DIGIT DIGITSC* "." DIGITSC*) %/{tag = "float#fix";}; FLOATEXP = (SIGN? DIGIT DIGITSC* "." DIGITSP* [eE] SIGN DIGIT+) %/{tag = "float#exp";}; FLOATSIXTY = (SIGN? DIGIT DIGITSC* ( ":" [0-5]? DIGIT )+ "." DIGITSC*) %/{tag = "float#base60";}; FLOATINF = ([+]? "." INF) %/{tag = "float#inf";}; FLOATNEGINF = ([\-] "." INF) %/{tag = "float#neginf";} ; FLOATNAN = ("." ( "nan" | "NaN" | "NAN" )) %/{tag = "float#nan";}; TIMEYMD = (YEAR "-" MON "-" MON) %/{tag = "timestamp#ymd";}; TIMEISO = (YEAR "-" MON "-" MON [Tt] MON ":" MON ":" MON ( "." DIGIT* )? TIMEZ) %/{tag = "timestamp#iso8601";}; TIMESPACED = (YEAR "-" MON "-" MON [ \t]+ MON ":" MON ":" MON ( "." DIGIT* )? [ \t]+ TIMEZ) %/{tag = "timestamp#spaced";}; TIMECANON = (YEAR "-" MON "-" MON "T" MON ":" MON ":" MON ( "." DIGIT* [1-9]+ )? "Z") %/{tag = "timestamp";}; DEFAULTKEY = "=" %/{tag = "default";}; MERGE = "<<" %/{tag = "merge";}; Scalar = NULLTYPE | BOOLYES | BOOLNO | INTHEX | INTOCT | INTSIXTY | INTCANON | FLOATFIX | FLOATEXP | FLOATSIXTY | FLOATINF | FLOATNEGINF | FLOATNAN | TIMEYMD | TIMEISO | TIMESPACED | TIMECANON | DEFAULTKEY | MERGE; main := Scalar; }%% %% write data nofinal; // syck_match_implicit public static String matchImplicit(Pointer ptr, int len) { String tag = "str"; int cs; int act; int have = 0; int nread = 0; int p=ptr.start; int pe = p+len; int eof = p+len; int tokstart = -1; int tokend = -1; byte[] data = ptr.buffer; if(len == 0) { data = new byte[]{(byte)'~'}; p = 0; pe = 1; eof = 1; } %% write init; %% write exec; return tag; } } yecht-yecht-1.1/src/main/org/yecht/IoFileRead.java000066400000000000000000000013551262256356000220400ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; import java.io.IOException; /** * * @author Ola Bini */ public interface IoFileRead { public int read(Pointer buf, JechtIO.File file, int max_size, int skip) throws IOException; public static class Default implements IoFileRead { // syck_io_file_read public int read(Pointer buf, JechtIO.File file, int max_size, int skip) throws IOException { max_size -= skip; int len = file.ptr.read(buf.buffer, buf.start + skip, max_size); len += skip; buf.buffer[buf.start + len] = 0; return len; } } }// IoFileRead yecht-yecht-1.1/src/main/org/yecht/IoStrRead.java000066400000000000000000000025511262256356000217300ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public interface IoStrRead { public int read(Pointer buf, JechtIO.Str str, int max_size, int skip); public static class Default implements IoStrRead { // syck_io_str_read public int read(Pointer buf, JechtIO.Str str, int max_size, int skip) { int beg = str.ptr.start; if(max_size >= 0) { max_size -= skip; if(max_size <= 0) { max_size = 0; } else { str.ptr.start += max_size; } if(str.ptr.start > str.end) { str.ptr.start = str.end; } } else { while(str.ptr.start < str.end) { if(str.ptr.buffer[str.ptr.start++] == '\n') { break; } } } int len = 0; if(beg < str.ptr.start) { len = str.ptr.start - beg; System.arraycopy(str.ptr.buffer, beg, buf.buffer, buf.start + skip, len); } len += skip; buf.buffer[buf.start+len] = 0; return len; } } }// IoStrRead yecht-yecht-1.1/src/main/org/yecht/JechtIO.java000066400000000000000000000011721262256356000213570ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public abstract class JechtIO { public static class File extends JechtIO { public java.io.InputStream ptr; public IoFileRead read; public File(java.io.InputStream is, IoFileRead read) { this.ptr = is; this.read = read; } } public static class Str extends JechtIO { public Pointer ptr; public int beg; public int end; public IoStrRead read; } }// JechtIO yecht-yecht-1.1/src/main/org/yecht/KindTag.java000066400000000000000000000005771262256356000214230ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public enum KindTag { Map, Seq, Str; // syck_alloc_node public Node allocNode() { Node s = new Node(); s.kind = this; s.id = null; return s; } }// KindTag yecht-yecht-1.1/src/main/org/yecht/Level.java000066400000000000000000000004511262256356000211400ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public class Level { int spaces; int ncount; int anctag; String domain; LevelStatus status; }// Level yecht-yecht-1.1/src/main/org/yecht/LevelStatus.java000066400000000000000000000004611262256356000223450ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public enum LevelStatus { header, doc, open, seq, map, block, str, iseq, imap, end, pause, anctag, mapx, seqx }// LevelStatus yecht-yecht-1.1/src/main/org/yecht/MapPart.java000066400000000000000000000003401262256356000214320ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public enum MapPart { Key, Value }// MapPart yecht-yecht-1.1/src/main/org/yecht/MapStyle.java000066400000000000000000000003311262256356000216240ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public enum MapStyle { None, Inline } yecht-yecht-1.1/src/main/org/yecht/Node.java000066400000000000000000000135761262256356000207720ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public class Node { public Object id = null; public KindTag kind; public String type_id; public String anchor; public Data data; public Object shortcut; Node() { } public String toString() { if(kind != null) { switch(kind) { case Str: return "Str[id=" + id +", type=" + type_id +", val="+data+"]"; case Seq: return "Seq[id=" + id +", type=" + type_id +", val="+data+"]"; case Map: return "Map[id=" + id +", type=" + type_id +", val="+data+"]"; } } return "other[id=" + id +", type=" + type_id +", val="+data+"]"; } // syck_replace_str // syck_replace_str2 public void replaceStr(Pointer str, int len, ScalarStyle style) { Data.Str s = (Data.Str)data; s.ptr = Pointer.create(new byte[len], 0); s.len = len; s.style = style; str.memcpy(s.ptr, len); } // syck_str_blow_away_commas public void strBlowAwayCommas() { Data.Str d = ((Data.Str)data); byte[] buf = d.ptr.buffer; int go = d.ptr.start; int end = go + d.len; for(;go < end;go++) { if(buf[go] == ',') { d.len--; end--; System.arraycopy(buf, go+1, buf, go, end-go); } } } // syck_str_read public Pointer strRead() { return ((Data.Str)data).ptr; } // syck_map_empty public void mapEmpty() { Data.Map m = (Data.Map)data; m.idx = 0; m.capa = YAML.ALLOC_CT; m.keys = new Object[m.capa]; m.values = new Object[m.capa]; } // syck_map_add public void mapAdd(Object key, Object value) { Data.Map m = (Data.Map)data; int idx = m.idx; m.idx++; if(m.idx > m.capa) { m.capa += YAML.ALLOC_CT; m.keys = YAML.realloc(m.keys, m.capa); m.values = YAML.realloc(m.values, m.capa); } m.keys[idx] = key; m.values[idx] = value; } // syck_map_update public void mapUpdate(Node map2) { Data.Map m1 = (Data.Map)data; Data.Map m2 = (Data.Map)map2.data; if(m2.idx < 1) { return; } int new_idx = m1.idx; new_idx += m2.idx; int new_capa = m1.capa; while(new_idx > new_capa) { new_capa += YAML.ALLOC_CT; } if(new_capa > m1.capa) { m1.capa = new_capa; m1.keys = YAML.realloc(m1.keys, m1.capa); m1.values = YAML.realloc(m1.values, m1.capa); } for(new_idx = 0; new_idx < m2.idx; m1.idx++, new_idx++) { m1.keys[m1.idx] = m2.keys[new_idx]; m1.values[m1.idx] = m2.values[new_idx]; } } // syck_map_count public long mapCount() { return ((Data.Map)data).idx; } // syck_map_assign public void mapAssign(MapPart p, int idx, Object id) { Data.Map m = (Data.Map)data; if(p == MapPart.Key) { m.keys[idx] = id; } else { m.values[idx] = id; } } // syck_map_read public Object mapRead(MapPart p, int idx) { Data.Map m = (Data.Map)data; if(p == MapPart.Key) { return m.keys[idx]; } else { return m.values[idx]; } } // syck_seq_empty public void seqEmpty() { Data.Seq s = (Data.Seq)data; s.idx = 0; s.capa = YAML.ALLOC_CT; s.items = new Object[s.capa]; } // syck_seq_add public void seqAdd(Object value) { Data.Seq s = (Data.Seq)data; int idx = s.idx; s.idx++; if(s.idx > s.capa) { s.capa += YAML.ALLOC_CT; s.items = YAML.realloc(s.items, s.capa); } s.items[idx] = value; } // syck_seq_count public int seqCount() { return ((Data.Seq)data).idx; } // syck_seq_assign public void seqAssign(int idx, Object id) { ((Data.Seq)data).items[idx] = id; } // syck_seq_read public Object seqRead(int idx) { return ((Data.Seq)data).items[idx]; } // syck_alloc_map public static Node allocMap() { Data.Map m = new Data.Map(); m.style = MapStyle.None; m.idx = 0; m.capa = YAML.ALLOC_CT; m.keys = new Object[m.capa]; m.values = new Object[m.capa]; Node n = KindTag.Map.allocNode(); n.data = m; return n; } // syck_alloc_seq public static Node allocSeq() { Data.Seq s = new Data.Seq(); s.style = SeqStyle.None; s.idx = 0; s.capa = YAML.ALLOC_CT; s.items = new Object[s.capa]; Node n = KindTag.Seq.allocNode(); n.data = s; return n; } // syck_alloc_str public static Node allocStr() { Data.Str s = new Data.Str(); s.style = ScalarStyle.None; s.ptr = Pointer.nullPointer(); s.len = 0; Node n = KindTag.Str.allocNode(); n.data = s; return n; } // syck_new_str // syck_new_str2 public static Node newStr(Pointer str, int len, ScalarStyle style) { Node n = allocStr(); Data.Str s = (Data.Str)n.data; s.ptr = Pointer.create(new byte[len], 0); s.len = len; s.style = style; str.memcpy(s.ptr, len); return n; } // syck_new_map public static Node newMap(Object key, Object value) { Node n = allocMap(); n.mapAdd(key, value); return n; } // syck_new_seq public static Node newSeq(Object value) { Node n = allocSeq(); n.seqAdd(value); return n; } }// Node yecht-yecht-1.1/src/main/org/yecht/NodeHandler.java000066400000000000000000000004031262256356000222510ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public interface NodeHandler { Object handle(Parser p, Node n); }// NodeHandler yecht-yecht-1.1/src/main/org/yecht/NullNodeHandler.java000066400000000000000000000005631262256356000231130ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public class NullNodeHandler implements NodeHandler { private long current = 0; public Object handle(Parser p, Node n) { return Long.valueOf(current++); } }// NullNodeHandler yecht-yecht-1.1/src/main/org/yecht/OutputHandler.java000066400000000000000000000004231262256356000226660ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public interface OutputHandler { void handle(Emitter e, byte[] str, int len); }// OutputHandler yecht-yecht-1.1/src/main/org/yecht/Parser.java000066400000000000000000000263451262256356000213370ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; import java.util.Map; import java.util.HashMap; /** * * @author Ola Bini */ public class Parser { private Parser() {} public Object root, root_on_error; boolean implicit_typing, taguri_expansion; NodeHandler handler; ErrorHandler error_handler; BadAnchorHandler bad_anchor_handler = new BadAnchorHandler.Default(); ParserInput input_type; IOType io_type; public int bufsize; public Pointer buffer; public int linectptr, lineptr, token, toktmp, cursor = -1, marker, limit; public int linect; int last_token; int force_token; public boolean eof; JechtIO io; Map anchors, bad_anchors, prepared_anchors; // Map syms; Level[] levels; int lvl_idx; int lvl_capa; public Object bonus; // syck_parser_reset_levels public void resetLevels() { while(lvl_idx > 1) { popLevel(); } if(lvl_idx < 1) { lvl_idx = 1; levels[0] = new Level(); levels[0].spaces = -1; levels[0].ncount = 0; levels[0].domain = ""; } levels[0].status = LevelStatus.header; } // syck_parser_pop_level public void popLevel() { if(lvl_idx <= 1) { return; } lvl_idx--; } // syck_parser_reset_cursor public void resetCursor() { if(buffer == null) { buffer = Pointer.create(new byte[bufsize], 0); } buffer.buffer[buffer.start] = 0; cursor = -1; lineptr = -1; linectptr = -1; token = -1; toktmp = -1; marker = -1; limit = -1; root = null; root_on_error = null; linect = 0; eof = false; last_token = 0; force_token = 0; } // syck_parser_set_root_on_error public void setRootOnError(Object roer) { this.root_on_error = roer; } // syck_new_parser public static Parser newParser() { Parser p = new Parser(); p.lvl_capa = YAML.ALLOC_CT; p.levels = new Level[p.lvl_capa]; p.input_type = ParserInput.YAML_UTF8; p.io_type = IOType.Str; p.io = null; // p.syms = new HashMap(); p.anchors = null; p.bad_anchors = null; p.prepared_anchors = null; p.implicit_typing = true; p.taguri_expansion = false; p.bufsize = YAML.BUFFERSIZE; p.buffer = null; p.lvl_idx = 0; p.resetLevels(); return p; } // // syck_add_sym // public int addSym(Object data) { // int id = syms.size() + 1; // syms.put(Integer.valueOf(id), data); // return id; // } // // syck_lookup_sym // public Object lookupSym(long id) { // return syms.get(Integer.valueOf((int)id)); // } // syck_parser_handler public void handler(NodeHandler hdlr) { handler = hdlr; } // syck_parser_implicit_typing public void implicitTyping(boolean flag) { implicit_typing = flag; } // syck_parser_taguri_expansion public void taguriExpansion(boolean flag) { taguri_expansion = flag; } // syck_parser_error_handler public void errorHandler(ErrorHandler hdlr) { error_handler = hdlr; } // syck_parser_bad_anchor_handler public void badAnchorHandler(BadAnchorHandler hdlr) { bad_anchor_handler = hdlr; } // syck_parser_set_input_type public void setInputType(ParserInput input_type) { this.input_type = input_type; } // syck_parser_file public void file(java.io.InputStream fp, IoFileRead read) { resetCursor(); io_type = IOType.File; if(read == null) { read = new IoFileRead.Default(); } io = new JechtIO.File(fp, read); } // syck_parser_str public void str(Pointer ptr, int len, IoStrRead read) { resetCursor(); io_type = IOType.Str; JechtIO.Str ss = new JechtIO.Str(); io = ss; ss.beg = ptr.start; ss.ptr = ptr; ss.end = ptr.start + len; if(read == null) { ss.read = new IoStrRead.Default(); } else { ss.read = read; } } // syck_parser_str_auto public void str(Pointer ptr, IoStrRead read) { str(ptr, ptr.buffer.length - ptr.start, read); } // syck_parser_current_level public Level currentLevel() { return levels[lvl_idx-1]; } // syck_parser_add_level public void addLevel(int len, LevelStatus status) { if(lvl_idx + 1 > lvl_capa) { lvl_capa += YAML.ALLOC_CT; levels = YAML.realloc(levels, lvl_capa); } levels[lvl_idx] = new Level(); levels[lvl_idx].spaces = len; levels[lvl_idx].ncount = 0; levels[lvl_idx].domain = levels[lvl_idx-1].domain; levels[lvl_idx].status = status; lvl_idx++; } // syck_move_tokens public int moveTokens() { int count; if(token == -1) { return 0; } int skip = limit - token; if(skip < 0) { return 0; } if((count = token - buffer.start) != 0) { System.arraycopy(buffer.buffer, token, buffer.buffer, buffer.start, skip); token = buffer.start; marker -= count; cursor -= count; toktmp -= count; limit -= count; lineptr -= count; linectptr -= count; } return skip; } // syck_check_limit public void checkLimit(int len) { if(cursor == -1) { cursor = buffer.start; lineptr = buffer.start; linectptr = buffer.start; marker = buffer.start; } limit = buffer.start + len; } // syck_parser_read public int read() throws java.io.IOException { int len = 0; int skip = 0; switch(io_type) { case Str: skip = moveTokens(); len = ((JechtIO.Str)io).read.read(buffer, ((JechtIO.Str)io), YAML.BUFFERSIZE-1, skip); break; case File: skip = moveTokens(); len = ((JechtIO.File)io).read.read(buffer, ((JechtIO.File)io), YAML.BUFFERSIZE-1, skip); break; default: break; } checkLimit(len); return len; } // syck_parser_readlen public int read(int max_size) throws java.io.IOException { int len = 0; int skip = 0; switch(io_type) { case Str: skip = moveTokens(); len = ((JechtIO.Str)io).read.read(buffer, ((JechtIO.Str)io), max_size, skip); break; case File: skip = moveTokens(); len = ((JechtIO.File)io).read.read(buffer, ((JechtIO.File)io), max_size, skip); break; default: break; } checkLimit(len); return len; } // syck_parse public Object parse() { resetLevels(); yechtparse(); return root; } private void yechtparse() { try { new DefaultYAMLParser(this).yyparse(TokenScanner.createScanner(this)); } catch(java.io.IOException e) { root = root_on_error; } } // syck_hdlr_add_node public Object addNode(Node n) { // System.err.println("addNode(" + n + ")"); if(n.id == null) { n.id = handler.handle(this, n); } return n.id; } // public void prepareAnchor(String a, Node n) { // System.err.println("prepareAnchor(" + a + ", " + n + ")"); // if(prepared_anchors == null) { // prepared_anchors = new HashMap(); // } // prepared_anchors.put(a, n); // } // syck_hdlr_add_anchor public Node addAnchor(String a, Node n) { // System.err.println("addAnchor(" + a + ", " + n + ")"); n.anchor = a; if(bad_anchors != null) { // System.err.print(" -- bad_anchors != null\n"); if(bad_anchors.containsKey(a)) { // System.err.print(" -- st_lookup(p->bad_anchors) succeeded\n"); if(n.kind != KindTag.Str) { Node bad = bad_anchors.get(a); // System.err.print(" -- this is not a str\n"); // System.err.print(" -- id: " + n.id + ", bad.id: " + bad.id +"\n"); n.id = bad.id; handler.handle(this, n); } } } if(anchors == null) { // System.err.print(" -- anchors == null\n"); anchors = new HashMap(); } // System.err.print(" -- inserting into the anchor again\n"); anchors.put(a, n); return n; } // syck_hdlr_remove_anchor public void removeAnchor(String a) { if(anchors == null) { anchors = new HashMap(); } anchors.put(a, null); } // syck_hdlr_get_anchor public Node getAnchor(String a) { // System.err.println("getAnchor(" + a + ")"); Node n = null; if(anchors != null) { // System.err.print(" -- anchors != null\n"); if(anchors.containsKey(a)) { // System.err.print(" -- st_lookup succeeded\n"); n = anchors.get(a); if(n != null) { // System.err.print(" -- n != 1\n"); return n; } else { // System.err.print(" -- n === 1\n"); if(bad_anchors == null) { // System.err.print(" -- creating new list of bad anchors\n"); bad_anchors = new HashMap(); } // System.err.print(" -- checking if n exists in bad anchors\n"); if(!bad_anchors.containsKey(a)) { // System.err.print(" -- no, it doesnt\n"); n = bad_anchor_handler.handle(this, a); bad_anchors.put(a, n); } else { n = bad_anchors.get(a); } } } } // System.err.print(" -- n == null?\n"); if(n == null) { // System.err.print(" --- yep ?\n"); n = bad_anchor_handler.handle(this, a); } if(n.anchor == null) { n.anchor = a; } return n; } // syck_add_transfer public static void addTransfer(String uri, Node n, boolean taguri) { if(!taguri) { n.type_id = uri; return; } n.type_id = ImplicitScanner.typeIdToUri(uri); } // syck_xprivate public static String xprivate(String type_id) { return "x-private:" + type_id; } // syck_taguri public static String taguri(String domain, String type_id) { return "tag:" + domain + ":" + type_id; } // syck_try_implicit public static boolean tryImplicit(Node n) { return true; } }// Parser yecht-yecht-1.1/src/main/org/yecht/ParserInput.java000066400000000000000000000004161262256356000223460ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public enum ParserInput { YAML_UTF8, YAML_UTF16, YAML_UTF32, Bytecode_UTF8 }// ParserInput yecht-yecht-1.1/src/main/org/yecht/Pointer.java000066400000000000000000000023561262256356000215170ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public class Pointer { public byte[] buffer; public int start = -1; private Pointer() { } private final static byte[] emptyBuffer = new byte[0]; public static Pointer empty() { return create(emptyBuffer, 0); } public static Pointer nullPointer() { return new Pointer(); } public static Pointer create(byte[] buf, int start) { Pointer p = new Pointer(); p.buffer = buf; p.start = start; return p; } public static Pointer create(String buf) { Pointer p = new Pointer(); try { p.buffer = buf.getBytes("ISO-8859-1"); } catch(Exception e) {} p.start = 0; return p; } public void memcpy(byte[] toBuffer, int toIndex, int len) { System.arraycopy(buffer, start, toBuffer, toIndex, len); } public void memcpy(Pointer to, int len) { System.arraycopy(buffer, start, to.buffer, to.start, len); } public Pointer withStart(int start) { return Pointer.create(this.buffer, start); } }// Pointer yecht-yecht-1.1/src/main/org/yecht/ScalarStyle.java000066400000000000000000000004141262256356000223160ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public enum ScalarStyle { None, OneQuote, TwoQuote, Fold, Literal, Plain }// ScalarStyle yecht-yecht-1.1/src/main/org/yecht/SeqStyle.java000066400000000000000000000003441262256356000216430ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public enum SeqStyle { None, Inline }// SeqStyle yecht-yecht-1.1/src/main/org/yecht/TokenScanner.java000066400000000000000000002443041262256356000224720ustar00rootroot00000000000000/* Generated by re2j 0.13.6.dev on Mon Jul 27 17:41:42 2009 */ package org.yecht; import java.io.IOException; // Equivalent to token.re public class TokenScanner implements DefaultYAMLParser.yyInput { public final static int QUOTELEN = 1024; private Parser parser; private Object lval; private int currentToken = -1; public static void error(String msg, Parser parser) { if(parser.error_handler == null) { parser.error_handler = new ErrorHandler.Default(); } parser.root = parser.root_on_error; parser.error_handler.handle(parser, msg); } public static DefaultYAMLParser.yyInput createScanner(Parser parser) { switch(parser.input_type) { case YAML_UTF8: return new TokenScanner(parser); case Bytecode_UTF8: return new BytecodeScanner(parser); case YAML_UTF16: error("UTF-16 is not currently supported in Yecht.\nPlease contribute code to help this happen!", parser); return null; case YAML_UTF32: error("UTF-32 is not currently supported in Yecht.\nPlease contribute code to help this happen!", parser); return null; } return null; } public TokenScanner(Parser parser) { this.parser = parser; } public Object value() { return lval; } public int token() { return currentToken; } public boolean advance() throws java.io.IOException { currentToken = real_yylex(); return currentToken == 0 ? false : true; } private int isNewline(int ptr) { return newlineLen(ptr); } private int newlineLen(int ptr) { if(parser.buffer.buffer[ptr] == '\n') return 1; if(parser.buffer.buffer[ptr] == '\r' && parser.buffer.buffer[ptr+1] == '\n') return 2; return 0; } private int isNewline(byte[] buff, int ptr) { return newlineLen(buff, ptr); } private int newlineLen(byte[] buff, int ptr) { if(buff[ptr] == '\n') return 1; if(buff[ptr] == '\r' && buff[ptr+1] == '\n') return 2; return 0; } private void NEWLINE(int ptr) { parser.lineptr = ptr + newlineLen(ptr); if(parser.lineptr > parser.linectptr) { parser.linect++; parser.linectptr = parser.lineptr; } } private void RETURN_YAML_BLOCK(QuotedString q, int blockType, int nlDoWhat) { Node n = Node.allocStr(); if(parser.taguri_expansion) { n.type_id = Parser.taguri(YAML.DOMAIN, "str"); } else { n.type_id = "str"; } Data.Str dd = (Data.Str)n.data; dd.ptr = Pointer.create(q.str, 0); dd.len = q.idx; if(blockType == YAML.BLOCK_LIT) { dd.style = ScalarStyle.Literal; } else { dd.style = ScalarStyle.Fold; } if(q.idx > 0) { if(nlDoWhat != YAML.NL_KEEP) { int fc = dd.len - 1; while(isNewline(dd.ptr.buffer, fc) > 0) { fc--; } if(nlDoWhat != YAML.NL_CHOMP && fc < (dd.len-1)) { fc += 1; } dd.len = fc + 1; } } lval = n; } private int GET_TRUE_YAML_INDENT() { Level lvl_deep = parser.currentLevel(); int indt_len = lvl_deep.spaces; if(lvl_deep.status == LevelStatus.seq || (indt_len == parser.cursor - parser.lineptr && lvl_deep.status != LevelStatus.map)) { parser.lvl_idx--; Level lvl_over = parser.currentLevel(); indt_len = lvl_over.spaces; parser.lvl_idx++; } return indt_len; } public final static String[] tnames = new String[269]; static { tnames[0] = "ENDINPUT"; tnames[256] = "error"; tnames[44] = "COMMA"; tnames[45] = "DASH"; tnames[58] = "COLON"; tnames[63] = "QUESTION"; tnames[91] = "SQUAREO"; tnames[93] = "SQUAREC"; tnames[123] = "CURLYO"; tnames[125] = "CURLYC"; tnames[257] = "ANCHOR"; tnames[258] = "ALIAS"; tnames[264] = "BLOCK"; tnames[265] = "DOCSEP"; tnames[268] = "IEND"; tnames[267] = "INDENT"; tnames[266] = "IOPEN"; tnames[261] = "ITRANSFER"; tnames[263] = "PLAIN"; tnames[260] = "TAGURI"; tnames[259] = "TRANSFER"; tnames[262] = "WORD"; } private void YYPOS(int n) { parser.cursor = parser.token + n; } private static class QuotedString { public int idx = 0; public int capa = 100; public byte[] str; public QuotedString() { str = new byte[100]; } public void cat(char l) { cat((byte)l); } public void cat(byte l) { if(idx + 1 >= capa) { capa += QUOTELEN; str = YAML.realloc(str, capa); } str[idx++] = l; str[idx] = 0; } public void cat(byte[] l, int cs, int cl) { while(idx + cl >= capa) { capa += QUOTELEN; str = YAML.realloc(str, capa); } System.arraycopy(l, cs, str, idx, cl); idx += cl; str[idx] = 0; } public void plain_is_inl() { int walker = idx - 1; while(walker > 0 && (str[walker] == '\n' || str[walker] == ' ' || str[walker] == '\t')) { idx--; str[walker] = 0; walker--; } } } public void RETURN_IMPLICIT(QuotedString q) { Node n = Node.allocStr(); parser.cursor = parser.token; Data.Str dd = (Data.Str)n.data; dd.ptr = Pointer.create(q.str, 0); dd.len = q.idx; dd.style = ScalarStyle.Plain; lval = n; if(parser.implicit_typing) { ImplicitScanner2.tryTagImplicit(n, parser.taguri_expansion); } } private int real_yylex() throws IOException { if(parser.cursor == -1) { parser.read(); } // System.err.println("real_yylex(" + new String(parser.buffer.buffer, parser.buffer.start, parser.bufsize) + ")"); // System.out.println("real_yylex()"); if(parser.force_token != 0) { int t = parser.force_token; parser.force_token = 0; return t; } if(parser.lineptr != parser.cursor) { return document(0); } else { return header(); } } private int header() throws java.io.IOException { // System.out.println("header()"); Level lvl; int doc_level = 0; while(true) { parser.token = parser.cursor; int gotoPoint = -1; byte yych = (byte) 0; int yyaccept = 0; gotoNext: while(gotoPoint != -2) { int currentGoto = gotoPoint; gotoPoint = -2; switch(currentGoto) { case -1: if ((parser.limit - parser.cursor) < 5) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case 0x00: {gotoPoint = 7; continue gotoNext;} case '\t': case ' ': {gotoPoint = 12; continue gotoNext;} case '\n': {gotoPoint = 9; continue gotoNext;} case '\r': {gotoPoint = 11; continue gotoNext;} case '#': {gotoPoint = 5; continue gotoNext;} case '-': {gotoPoint = 2; continue gotoNext;} case '.': {gotoPoint = 4; continue gotoNext;} default: {gotoPoint = 14; continue gotoNext;} } case 2: yyaccept = 0; yych = parser.buffer.buffer[(parser.marker = ++parser.cursor)]; switch (yych) { case '-': {gotoPoint = 28; continue gotoNext;} default: {gotoPoint = 3; continue gotoNext;} } case 3: { YYPOS(0); return document(doc_level); } case 4: yyaccept = 0; yych = parser.buffer.buffer[(parser.marker = ++parser.cursor)]; switch (yych) { case '.': {gotoPoint = 21; continue gotoNext;} default: {gotoPoint = 3; continue gotoNext;} } case 5: ++parser.cursor; { eatComments(); break; } case 7: ++parser.cursor; { lvl = parser.currentLevel(); if(lvl.spaces > -1) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } YYPOS(0); return 0; } case 9: yyaccept = 1; yych = parser.buffer.buffer[(parser.marker = ++parser.cursor)]; {gotoPoint = 18; continue gotoNext;} case 10: { int indent = parser.token; NEWLINE(indent); while(indent < parser.cursor) { // these pieces commented out to be compatible with Syck 0.60. // if(parser.buffer.buffer[indent] == '\t') { // error("TAB found in your indentation, please remove",parser); // } else if(isNewline(++indent) != 0) { // NEWLINE(indent); // } if(isNewline(++indent) != 0) { NEWLINE(indent); } } doc_level = 0; if(parser.buffer.buffer[parser.cursor] == 0) { doc_level = -1; parser.token = parser.cursor-1; } else if(parser.buffer.buffer[parser.lineptr] == ' ') { doc_level = parser.cursor - parser.lineptr; } break; } case 11: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 17; continue gotoNext;} default: {gotoPoint = 3; continue gotoNext;} } case 12: ++parser.cursor; yych = parser.buffer.buffer[parser.cursor]; {gotoPoint = 16; continue gotoNext;} case 13: { doc_level = parser.cursor - parser.lineptr; break; } case 14: yych = parser.buffer.buffer[++parser.cursor]; {gotoPoint = 3; continue gotoNext;} case 15: ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; case 16: switch (yych) { case '\t': case ' ': {gotoPoint = 15; continue gotoNext;} default: {gotoPoint = 13; continue gotoNext;} } case 17: yyaccept = 1; parser.marker = ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; case 18: switch (yych) { case '\n': case ' ': {gotoPoint = 17; continue gotoNext;} case '\r': {gotoPoint = 19; continue gotoNext;} default: {gotoPoint = 10; continue gotoNext;} } case 19: ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case '\n': {gotoPoint = 17; continue gotoNext;} default: {gotoPoint = 20; continue gotoNext;} } case 20: parser.cursor = parser.marker; if (yyaccept == 0) { {gotoPoint = 3; continue gotoNext;} } else { {gotoPoint = 10; continue gotoNext;} } case 21: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '.': {gotoPoint = 22; continue gotoNext;} default: {gotoPoint = 20; continue gotoNext;} } case 22: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 23; continue gotoNext;} case '\r': {gotoPoint = 27; continue gotoNext;} case ' ': {gotoPoint = 25; continue gotoNext;} default: {gotoPoint = 20; continue gotoNext;} } case 23: ++parser.cursor; case 24: { lvl = parser.currentLevel(); if(lvl.status != LevelStatus.header) { if(lvl.spaces > -1) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } YYPOS(0); return 0; } break; } case 25: ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case ' ': {gotoPoint = 25; continue gotoNext;} default: {gotoPoint = 24; continue gotoNext;} } case 27: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 23; continue gotoNext;} default: {gotoPoint = 20; continue gotoNext;} } case 28: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '-': {gotoPoint = 29; continue gotoNext;} default: {gotoPoint = 20; continue gotoNext;} } case 29: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 30; continue gotoNext;} case '\r': {gotoPoint = 34; continue gotoNext;} case ' ': {gotoPoint = 32; continue gotoNext;} default: {gotoPoint = 20; continue gotoNext;} } case 30: ++parser.cursor; case 31: { lvl = parser.currentLevel(); if(lvl.status == LevelStatus.header) { YYPOS(3); return directive(); } else { if(lvl.spaces > -1) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } YYPOS(0); return 0; } } case 32: ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case ' ': {gotoPoint = 32; continue gotoNext;} default: {gotoPoint = 31; continue gotoNext;} } case 34: ++parser.cursor; switch ((yych = parser.buffer.buffer[parser.cursor])) { case '\n': {gotoPoint = 30; continue gotoNext;} default: {gotoPoint = 20; continue gotoNext;} } } } } } private final static boolean[] YWORDC = new boolean[256]; private final static boolean[] DIGIT_OR_SIGN = new boolean[256]; static { for(char c = 'a'; c<='z'; c++) { YWORDC[c] = true; } for(char c = 'A'; c<='Z'; c++) { YWORDC[c] = true; } for(char c = '0'; c<='9'; c++) { YWORDC[c] = true; DIGIT_OR_SIGN[c] = true; } YWORDC['_'] = true; YWORDC['-'] = true; DIGIT_OR_SIGN['-'] = true; DIGIT_OR_SIGN['+'] = true; } // (SPC | LF)* private void spcOrLfStar() throws IOException { byte ych; while(true) { if(parser.cursor+3 >= parser.limit) parser.read(); ych = parser.buffer.buffer[parser.cursor]; switch(ych) { case ' ': case '\n': parser.cursor++; break; case '\r': if(parser.buffer.buffer[parser.cursor+1] == '\n') { parser.cursor+=2; break; } else { return; } default: return; } } } // YWORDC+ private boolean ywordc() throws IOException { if(!YWORDC[parser.buffer.buffer[parser.cursor] & 0xFF]) return false; parser.cursor++; while(true) { if(parser.cursor == parser.limit) parser.read(); if(!YWORDC[parser.buffer.buffer[parser.cursor] & 0xFF]) return true; parser.cursor++; } } // ( SPC+ | LF ) private boolean endspc() throws IOException { byte ych = parser.buffer.buffer[parser.cursor]; switch(ych) { case ' ': parser.cursor++; while(true) { if(parser.cursor == parser.limit) parser.read(); if(parser.buffer.buffer[parser.cursor] != ' ') return true; parser.cursor++; } case '\r': if(parser.buffer.buffer[parser.cursor+1] != '\n') { return false; } parser.cursor++; case '\n': parser.cursor++; return true; default: return false; } } // [-+0-9]* ENDSPC private boolean yblock() throws IOException { int plus = 0; int ych = parser.buffer.buffer[parser.cursor + plus] & 0xFF; while(DIGIT_OR_SIGN[ych]) { plus++; if((parser.limit - parser.cursor) < plus) parser.read(); ych = parser.buffer.buffer[parser.cursor + plus] & 0xFF; } switch(ych) { case ' ': plus++; while(true) { if((parser.limit - parser.cursor) < plus) parser.read(); if(parser.buffer.buffer[parser.cursor + plus] != ' ') { parser.cursor += plus; return true; } plus++; } case '\r': if(parser.buffer.buffer[parser.cursor+plus+1] != '\n') { return false; } plus++; case '\n': plus++; parser.cursor += plus; return true; default: return false; } } private int document(int doc_level) throws java.io.IOException { // System.out.println("document()"); boolean do_any = false; while(true) { Level lvl = parser.currentLevel(); if(lvl.status == LevelStatus.header) { lvl.status = LevelStatus.doc; } parser.token = parser.cursor; if ((parser.limit - parser.cursor) < 3) parser.read(); byte yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case 0x00: parser.cursor++; if(lvl.spaces > -1) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } YYPOS(0); return 0; case '\t': case ' ': parser.cursor++; while((yych = parser.buffer.buffer[parser.cursor]) == '\t' || yych == ' ') { parser.cursor++; if(parser.cursor == parser.limit) parser.read(); } break; case '\r': if(parser.buffer.buffer[parser.cursor+1] != '\n') { do_any = true; break; } else { parser.cursor++; } case '\n': parser.cursor++; spcOrLfStar(); /* Isolate spaces */ int indt_len; int indent = parser.token; NEWLINE(indent); while(indent < parser.cursor) { // these pieces commented out to be compatible with Syck 0.60. // if(parser.buffer.buffer[indent] == '\t') { // error("TAB found in your indentation, please remove",parser); // } else if(isNewline(++indent) != 0) { // NEWLINE(indent); // } if(isNewline(++indent) != 0) { NEWLINE(indent); } } indt_len = 0; if(parser.buffer.buffer[parser.cursor] == 0) { indt_len = -1; parser.token = parser.cursor-1; } else if(parser.buffer.buffer[parser.lineptr] == ' ') { indt_len = parser.cursor - parser.lineptr; } lvl = parser.currentLevel(); doc_level = 0; /* XXX: Comment lookahead */ /* Ignore indentation inside inlines */ if(parser.buffer.buffer[parser.cursor] != '#' && lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { /* Check for open indent */ if(lvl.spaces > indt_len) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } if(lvl.spaces < indt_len) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel(indt_len, LevelStatus.doc); return DefaultYAMLParser.YAML_IOPEN; } } else { if(indt_len == -1) { return 0; } return DefaultYAMLParser.YAML_INDENT; } } break; case '!': parser.cursor++; return transferMethod(); case '"': parser.cursor++; if(lvl.spaces < doc_level) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel(doc_level, LevelStatus.doc); YYPOS(0); return DefaultYAMLParser.YAML_IOPEN; } } else { return doubleQuote(); } break; case '#': parser.cursor++; eatComments(); break; case '&': parser.cursor++; if(ywordc()) { lval = new String(parser.buffer.buffer, parser.token + 1, parser.cursor - (parser.token + 1), "ISO-8859-1"); /* * Remove previous anchors of the same name. Since the parser will likely * construct deeper nodes first, we want those nodes to be placed in the * queue for matching at a higher level of indentation. */ parser.removeAnchor((String)lval); return DefaultYAMLParser.YAML_ANCHOR; } else { parser.cursor--; do_any = true; break; } case '\'': parser.cursor++; if(lvl.spaces < doc_level) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel(doc_level, LevelStatus.doc); YYPOS(0); return DefaultYAMLParser.YAML_IOPEN; } } else { return singleQuote(); } break; case '*': parser.cursor++; if(ywordc()) { if(lvl.spaces < doc_level) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel(doc_level, LevelStatus.doc); YYPOS(0); return DefaultYAMLParser.YAML_IOPEN; } } else { lval = new String(parser.buffer.buffer, parser.token + 1, parser.cursor - (parser.token + 1), "ISO-8859-1"); return DefaultYAMLParser.YAML_ALIAS; } } else { parser.cursor--; do_any = true; } break; case ',': case ':': parser.cursor++; if(endspc()) { if( parser.buffer.buffer[parser.token] == ':' && lvl.status != LevelStatus.imap && lvl.status != LevelStatus.iseq ) { lvl.status = LevelStatus.map; } YYPOS(1); return parser.buffer.buffer[parser.token]; } else { parser.cursor--; do_any = true; break; } case '-': case '?': parser.cursor++; if(endspc()) { if(lvl.spaces < (parser.token - parser.lineptr)) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel((parser.token - parser.lineptr), LevelStatus.doc); YYPOS(0); return DefaultYAMLParser.YAML_IOPEN; } } else { parser.force_token = DefaultYAMLParser.YAML_IOPEN; if( parser.buffer.buffer[parser.cursor] == '#' || isNewline(parser.cursor) != 0 || isNewline(parser.cursor-1) != 0) { parser.cursor--; parser.addLevel(parser.token + 1 - parser.lineptr, LevelStatus.seq); } else /* spaces followed by content uses the space as indentation */ { parser.addLevel(parser.cursor - parser.lineptr, LevelStatus.seq); } return parser.buffer.buffer[parser.token]; } } else { parser.cursor--; do_any = true; } break; case '>': case '|': parser.cursor++; if(yblock()) { if(isNewline(parser.cursor - 1) != 0) { parser.cursor--; } return scalarBlock(); } else { parser.cursor--; do_any = true; } break; case '[': parser.cursor++; if(lvl.spaces < doc_level) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel(doc_level, LevelStatus.doc); YYPOS(0); return DefaultYAMLParser.YAML_IOPEN; } } else { lvl = parser.currentLevel(); parser.addLevel(lvl.spaces + 1, LevelStatus.iseq); return parser.buffer.buffer[parser.token]; } break; case ']': case '}': parser.cursor++; parser.popLevel(); return parser.buffer.buffer[parser.token]; case '{': parser.cursor++; if(lvl.spaces < doc_level) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel(doc_level, LevelStatus.doc); YYPOS(0); return DefaultYAMLParser.YAML_IOPEN; } } else { lvl = parser.currentLevel(); parser.addLevel(lvl.spaces + 1, LevelStatus.imap); return parser.buffer.buffer[parser.token]; } break; default: do_any = true; break; } if(do_any) { if(lvl.spaces < doc_level) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel(doc_level, LevelStatus.doc); YYPOS(0); return DefaultYAMLParser.YAML_IOPEN; } } else { return plain(); } do_any = false; } } } private int directive() throws java.io.IOException { // System.out.println("directive()"); while(true) { parser.toktmp = parser.cursor; int gotoPoint = -1; byte yych = (byte) 0; gotoNext: while(gotoPoint != -2) { int currentGoto = gotoPoint; gotoPoint = -2; switch(currentGoto) { case -1: if ((parser.limit - parser.cursor) < 2) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case 0x00: {gotoPoint = 37; continue gotoNext;} case '\t': case ' ': {gotoPoint = 40; continue gotoNext;} case '%': {gotoPoint = 38; continue gotoNext;} default: {gotoPoint = 42; continue gotoNext;} } case 37: parser.cursor = parser.marker; {gotoPoint = 39; continue gotoNext;} case 38: yych = parser.buffer.buffer[(parser.marker = ++parser.cursor)]; switch (yych) { case '.': case '/': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case ':': case ';': case '<': case '=': case '>': case '?': case '@': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '[': case '\\': case ']': case '^': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 45; continue gotoNext;} default: {gotoPoint = 39; continue gotoNext;} } case 39: { parser.cursor = parser.toktmp; return DefaultYAMLParser.YAML_DOCSEP; } case 40: ++parser.cursor; yych = parser.buffer.buffer[parser.cursor]; {gotoPoint = 44; continue gotoNext;} case 41: { break; } case 42: yych = parser.buffer.buffer[++parser.cursor]; {gotoPoint = 39; continue gotoNext;} case 43: ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; case 44: switch (yych) { case '\t': case ' ': {gotoPoint = 43; continue gotoNext;} default: {gotoPoint = 41; continue gotoNext;} } case 45: ++parser.cursor; if ((parser.limit - parser.cursor) < 2) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case '.': case '/': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case ';': case '<': case '=': case '>': case '?': case '@': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '[': case '\\': case ']': case '^': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 45; continue gotoNext;} case ':': {gotoPoint = 47; continue gotoNext;} default: {gotoPoint = 37; continue gotoNext;} } case 47: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '.': case '/': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case ':': case ';': case '<': case '=': case '>': case '?': case '@': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '[': case '\\': case ']': case '^': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 48; continue gotoNext;} default: {gotoPoint = 37; continue gotoNext;} } case 48: ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case '.': case '/': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case ':': case ';': case '<': case '=': case '>': case '?': case '@': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '[': case '\\': case ']': case '^': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': {gotoPoint = 48; continue gotoNext;} default: {gotoPoint = 50; continue gotoNext;} } case 50: { break; } } } } } private int getAndCheckIndentLength() { int indt_len; int indent = parser.token; NEWLINE(indent); while(indent < parser.cursor) { // these pieces commented out to be compatible with Syck 0.60. // if(parser.buffer.buffer[indent] == '\t') { // error("TAB found in your indentation, please remove",parser); // } else if(isNewline(++indent) != 0) { // NEWLINE(indent); // } if(isNewline(++indent) != 0) { NEWLINE(indent); } } indt_len = 0; if(parser.buffer.buffer[parser.cursor] == 0) { indt_len = -1; } else if(parser.buffer.buffer[parser.lineptr] == ' ') { indt_len = parser.cursor - parser.lineptr; } return indt_len; } private void countAndAddNewlines(QuotedString q) { int nl_count = 0; while(parser.token < parser.cursor) { int nl_len = newlineLen(parser.token++); if(nl_len > 0) { nl_count++; parser.token += (nl_len - 1); } } if(nl_count <= 1) { q.cat(' '); } else { for(int i = 0; i < nl_count - 1; i++) { q.cat('\n'); } } } private int plain() throws java.io.IOException { // System.out.println("plain()"); QuotedString q = new QuotedString(); parser.cursor = parser.token; Level plvl = parser.currentLevel(); Level lvl_deep = parser.currentLevel(); int parentIndent = lvl_deep.spaces; if(lvl_deep.status == LevelStatus.seq || ((parentIndent == parser.cursor - parser.lineptr) && lvl_deep.status != LevelStatus.map)) { parser.lvl_idx--; Level lvl_over = parser.currentLevel(); parentIndent = lvl_over.spaces; parser.lvl_idx++; } boolean plain3 = false; boolean do_any = false; while(true) { parser.token = parser.cursor; do { plain3 = false; if ((parser.limit - parser.cursor) < 3) parser.read(); byte yych = parser.buffer.buffer[parser.cursor]; switch(yych) { // YINDENT case '\r': if(parser.buffer.buffer[parser.cursor+1] != '\n') { do_any = true; break; } else { parser.cursor++; } case '\n': parser.cursor++; spcOrLfStar(); int indt_len = getAndCheckIndentLength(); if(indt_len <= parentIndent) { RETURN_IMPLICIT(q); return DefaultYAMLParser.YAML_PLAIN; } countAndAddNewlines(q); break; case 0x00: parser.cursor++; RETURN_IMPLICIT(q); return DefaultYAMLParser.YAML_PLAIN; case ' ': if(parser.buffer.buffer[parser.cursor+1] == '#') { parser.cursor+=2; eatComments(); RETURN_IMPLICIT(q); return DefaultYAMLParser.YAML_PLAIN; } case '\t': parser.cursor++; if(q.idx != 0) { plain3 = true; } break; case '}': parser.cursor++; if(plvl.status != LevelStatus.imap) { // PLAIN_NOT_INL if(parser.buffer.buffer[parser.cursor-1] == ' ' || isNewline(parser.cursor-1) > 0) { parser.cursor--; } q.cat(parser.buffer.buffer, parser.token, parser.cursor - parser.token); } else { q.plain_is_inl(); RETURN_IMPLICIT(q); return DefaultYAMLParser.YAML_PLAIN; } break; case ']': parser.cursor++; if(plvl.status != LevelStatus.iseq) { // PLAIN_NOT_INL if(parser.buffer.buffer[parser.cursor-1] == ' ' || isNewline(parser.cursor-1) > 0) { parser.cursor--; } q.cat(parser.buffer.buffer, parser.token, parser.cursor - parser.token); } else { q.plain_is_inl(); RETURN_IMPLICIT(q); return DefaultYAMLParser.YAML_PLAIN; } break; // ALLX case ':': parser.cursor++; if(endspc()) { RETURN_IMPLICIT(q); return DefaultYAMLParser.YAML_PLAIN; } else { parser.cursor--; do_any = true; break; } // ICOMMA case ',': parser.cursor++; if(endspc()) { if(plvl.status != LevelStatus.iseq && plvl.status != LevelStatus.imap) { // PLAIN_NOT_INL if(parser.buffer.buffer[parser.cursor-1] == ' ' || isNewline(parser.cursor-1) > 0) { parser.cursor--; } q.cat(parser.buffer.buffer, parser.token, parser.cursor - parser.token); } else { q.plain_is_inl(); RETURN_IMPLICIT(q); return DefaultYAMLParser.YAML_PLAIN; } break; } else { parser.cursor--; do_any = true; break; } default: do_any = true; break; } if(do_any) { parser.cursor++; q.cat(parser.buffer.buffer, parser.token, parser.cursor - parser.token); do_any = false; } } while(plain3); } } private int doubleQuote() throws java.io.IOException { // System.out.println("doubleQuote()"); int keep_nl = 1; QuotedString q = new QuotedString(); while(true) { parser.token = parser.cursor; int gotoPoint = -1; byte yych = (byte) 0; int yyaccept = 0; gotoNext: while(gotoPoint != -2) { int currentGoto = gotoPoint; gotoPoint = -2; switch(currentGoto) { case -1: if ((parser.limit - parser.cursor) < 4) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case 0x00: {gotoPoint = 58; continue gotoNext;} case '\n': {gotoPoint = 53; continue gotoNext;} case '\r': {gotoPoint = 55; continue gotoNext;} case '"': {gotoPoint = 60; continue gotoNext;} case '\\': {gotoPoint = 57; continue gotoNext;} default: {gotoPoint = 61; continue gotoNext;} } case 53: yyaccept = 0; yych = parser.buffer.buffer[(parser.marker = ++parser.cursor)]; {gotoPoint = 75; continue gotoNext;} case 54: { // GOBBLE_UP_YAML_INDENT( indt_len, YYTOKEN ) int indent = parser.token; NEWLINE(indent); while(indent < parser.cursor) { // these pieces commented out to be compatible with Syck 0.60. // if(parser.buffer.buffer[indent] == '\t') { // error("TAB found in your indentation, please remove",parser); // } else if(isNewline(++indent) != 0) { // NEWLINE(indent); // } if(isNewline(++indent) != 0) { NEWLINE(indent); } } int indt_len = 0; if(parser.buffer.buffer[parser.cursor] == 0) { indt_len = -1; parser.token = parser.cursor-1; } else if(parser.buffer.buffer[parser.lineptr] == ' ') { indt_len = parser.cursor - parser.lineptr; } int nl_count = 0; Level lvl = parser.currentLevel(); if(lvl.status != LevelStatus.str) { parser.addLevel(indt_len, LevelStatus.str); } else if(indt_len < lvl.spaces) { // Error! } if(keep_nl == 1) { countAndAddNewlines(q); } keep_nl = 1; break; } case 55: ++parser.cursor; switch ((yych = parser.buffer.buffer[parser.cursor])) { case '\n': {gotoPoint = 74; continue gotoNext;} default: {gotoPoint = 56; continue gotoNext;} } case 56: { q.cat(parser.buffer.buffer[parser.cursor-1]); break; } case 57: yyaccept = 1; yych = parser.buffer.buffer[(parser.marker = ++parser.cursor)]; switch (yych) { case '\n': {gotoPoint = 65; continue gotoNext;} case '\r': {gotoPoint = 67; continue gotoNext;} case ' ': {gotoPoint = 62; continue gotoNext;} case '"': case '0': case '\\': case 'a': case 'b': case 'e': case 'f': case 'n': case 'r': case 't': case 'v': {gotoPoint = 69; continue gotoNext;} case 'x': {gotoPoint = 68; continue gotoNext;} default: {gotoPoint = 56; continue gotoNext;} } case 58: ++parser.cursor; case 59: { Node n = Node.allocStr(); Level lvl = parser.currentLevel(); if(lvl.status == LevelStatus.str) { parser.popLevel(); } if(parser.taguri_expansion) { n.type_id = Parser.taguri(YAML.DOMAIN, "str"); } else { n.type_id = "str"; } Data.Str dd = (Data.Str)n.data; dd.ptr = Pointer.create(q.str, 0); dd.len = q.idx; dd.style = ScalarStyle.TwoQuote; lval = n; return DefaultYAMLParser.YAML_PLAIN; } case 60: yych = parser.buffer.buffer[++parser.cursor]; {gotoPoint = 59; continue gotoNext;} case 61: yych = parser.buffer.buffer[++parser.cursor]; {gotoPoint = 56; continue gotoNext;} case 62: ++parser.cursor; if ((parser.limit - parser.cursor) < 2) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case '\n': {gotoPoint = 65; continue gotoNext;} case '\r': {gotoPoint = 67; continue gotoNext;} case ' ': {gotoPoint = 62; continue gotoNext;} default: {gotoPoint = 64; continue gotoNext;} } case 64: parser.cursor = parser.marker; if (yyaccept == 0) { {gotoPoint = 54; continue gotoNext;} } else { {gotoPoint = 56; continue gotoNext;} } case 65: ++parser.cursor; { keep_nl = 0; parser.cursor--; break; } case 67: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 65; continue gotoNext;} default: {gotoPoint = 64; continue gotoNext;} } case 68: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': {gotoPoint = 71; continue gotoNext;} default: {gotoPoint = 64; continue gotoNext;} } case 69: ++parser.cursor; { byte ch = parser.buffer.buffer[parser.cursor-1]; q.cat(escapeSeq(ch)); break; } case 71: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': {gotoPoint = 72; continue gotoNext;} default: {gotoPoint = 64; continue gotoNext;} } case 72: ++parser.cursor; { q.cat((byte)Integer.valueOf(new String(parser.buffer.buffer, parser.token+2, 2, "ISO-8859-1"), 16).intValue()); break; } case 74: yyaccept = 0; parser.marker = ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; case 75: switch (yych) { case '\n': case ' ': {gotoPoint = 74; continue gotoNext;} case '\r': {gotoPoint = 76; continue gotoNext;} default: {gotoPoint = 54; continue gotoNext;} } case 76: ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case '\n': {gotoPoint = 74; continue gotoNext;} default: {gotoPoint = 64; continue gotoNext;} } } } } } private int singleQuote() throws java.io.IOException { // System.out.println("singleQuote()"); QuotedString q = new QuotedString(); while(true) { parser.token = parser.cursor; int gotoPoint = -1; byte yych = (byte) 0; gotoNext: while(gotoPoint != -2) { int currentGoto = gotoPoint; gotoPoint = -2; switch(currentGoto) { case -1: if ((parser.limit - parser.cursor) < 2) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case 0x00: {gotoPoint = 85; continue gotoNext;} case '\n': {gotoPoint = 79; continue gotoNext;} case '\r': {gotoPoint = 81; continue gotoNext;} case '\'': {gotoPoint = 83; continue gotoNext;} default: {gotoPoint = 86; continue gotoNext;} } case 79: yych = parser.buffer.buffer[(parser.marker = ++parser.cursor)]; {gotoPoint = 90; continue gotoNext;} case 80: { // GOBBLE_UP_YAML_INDENT( indt_len, YYTOKEN ) int indent = parser.token; NEWLINE(indent); while(indent < parser.cursor) { // these pieces commented out to be compatible with Syck 0.60. // if(parser.buffer.buffer[indent] == '\t') { // error("TAB found in your indentation, please remove",parser); // } else if(isNewline(++indent) != 0) { // NEWLINE(indent); // } if(isNewline(++indent) != 0) { NEWLINE(indent); } } int indt_len = 0; if(parser.buffer.buffer[parser.cursor] == 0) { indt_len = -1; parser.token = parser.cursor-1; } else if(parser.buffer.buffer[parser.lineptr] == ' ') { indt_len = parser.cursor - parser.lineptr; } int nl_count = 0; Level lvl = parser.currentLevel(); if(lvl.status != LevelStatus.str) { parser.addLevel(indt_len, LevelStatus.str); } else if(indt_len < lvl.spaces) { // Error! } while(parser.token < parser.cursor) { int nl_len = newlineLen(parser.token++); if(nl_len > 0) { nl_count++; parser.token += (nl_len - 1); } } if(nl_count <= 1) { q.cat(' '); } else { for(int i = 0; i < nl_count - 1; i++) { q.cat('\n'); } } break; } case 81: ++parser.cursor; switch ((yych = parser.buffer.buffer[parser.cursor])) { case '\n': {gotoPoint = 89; continue gotoNext;} default: {gotoPoint = 82; continue gotoNext;} } case 82: { q.cat(parser.buffer.buffer[parser.cursor-1]); break; } case 83: ++parser.cursor; switch ((yych = parser.buffer.buffer[parser.cursor])) { case '\'': {gotoPoint = 87; continue gotoNext;} default: {gotoPoint = 84; continue gotoNext;} } case 84: { Node n = Node.allocStr(); Level lvl = parser.currentLevel(); if(lvl.status == LevelStatus.str) { parser.popLevel(); } if(parser.taguri_expansion) { n.type_id = Parser.taguri(YAML.DOMAIN, "str"); } else { n.type_id = "str"; } Data.Str dd = (Data.Str)n.data; dd.ptr = Pointer.create(q.str, 0); dd.len = q.idx; dd.style = ScalarStyle.OneQuote; lval = n; return DefaultYAMLParser.YAML_PLAIN; } case 85: yych = parser.buffer.buffer[++parser.cursor]; {gotoPoint = 84; continue gotoNext;} case 86: yych = parser.buffer.buffer[++parser.cursor]; {gotoPoint = 82; continue gotoNext;} case 87: ++parser.cursor; { q.cat('\''); break; } case 89: parser.marker = ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; case 90: switch (yych) { case '\n': case ' ': {gotoPoint = 89; continue gotoNext;} case '\r': {gotoPoint = 91; continue gotoNext;} default: {gotoPoint = 80; continue gotoNext;} } case 91: ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case '\n': {gotoPoint = 89; continue gotoNext;} default: {gotoPoint = 92; continue gotoNext;} } case 92: parser.cursor = parser.marker; {gotoPoint = 80; continue gotoNext;} } } } } private int transferMethod() throws java.io.IOException { // System.out.println("transferMethod()"); QuotedString q = new QuotedString(); while(true) { parser.toktmp = parser.cursor; int gotoPoint = -1; byte yych = (byte) 0; gotoNext: while(gotoPoint != -2) { int currentGoto = gotoPoint; gotoPoint = -2; switch(currentGoto) { case -1: if ((parser.limit - parser.cursor) < 4) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case 0x00: {gotoPoint = 95; continue gotoNext;} case '\n': {gotoPoint = 97; continue gotoNext;} case '\r': {gotoPoint = 99; continue gotoNext;} case ' ': {gotoPoint = 98; continue gotoNext;} case '\\': {gotoPoint = 101; continue gotoNext;} default: {gotoPoint = 102; continue gotoNext;} } case 95: ++parser.cursor; case 96: { parser.cursor = parser.toktmp; if(parser.cursor == parser.token + 1) { return DefaultYAMLParser.YAML_ITRANSFER; } Level lvl = parser.currentLevel(); /* * URL Prefixing */ if(q.str[0] == '^') { lval = lvl.domain + new String(q.str, 1, q.idx - 1, "ISO-8859-1"); } else { int carat = 0; int qend = q.idx; while((++carat) < qend) { if(q.str[carat] == '^') { break; } } if(carat < qend) { lvl.domain = new String(q.str, 0, carat, "ISO-8859-1"); lval = lvl.domain + new String(q.str, carat + 1, (qend - carat) - 1, "ISO-8859-1"); } else { lval = new String(q.str, 0, qend, "ISO-8859-1"); } } return DefaultYAMLParser.YAML_TRANSFER; } case 97: yych = parser.buffer.buffer[++parser.cursor]; {gotoPoint = 96; continue gotoNext;} case 98: yych = parser.buffer.buffer[++parser.cursor]; {gotoPoint = 111; continue gotoNext;} case 99: ++parser.cursor; switch ((yych = parser.buffer.buffer[parser.cursor])) { case '\n': {gotoPoint = 95; continue gotoNext;} default: {gotoPoint = 100; continue gotoNext;} } case 100: { q.cat(parser.buffer.buffer[parser.cursor-1]); break; } case 101: yych = parser.buffer.buffer[(parser.marker = ++parser.cursor)]; switch (yych) { case '"': case '0': case '\\': case 'a': case 'b': case 'e': case 'f': case 'n': case 'r': case 't': case 'v': {gotoPoint = 105; continue gotoNext;} case 'x': {gotoPoint = 103; continue gotoNext;} default: {gotoPoint = 100; continue gotoNext;} } case 102: yych = parser.buffer.buffer[++parser.cursor]; {gotoPoint = 100; continue gotoNext;} case 103: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': {gotoPoint = 107; continue gotoNext;} default: {gotoPoint = 104; continue gotoNext;} } case 104: parser.cursor = parser.marker; {gotoPoint = 100; continue gotoNext;} case 105: ++parser.cursor; { byte ch = parser.buffer.buffer[parser.cursor-1]; q.cat(escapeSeq(ch)); break; } case 107: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': {gotoPoint = 108; continue gotoNext;} default: {gotoPoint = 104; continue gotoNext;} } case 108: ++parser.cursor; { q.cat((byte)Integer.valueOf(new String(parser.buffer.buffer, parser.toktmp+2, 2, "ISO-8859-1"), 16).intValue()); break; } case 110: ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; case 111: switch (yych) { case ' ': {gotoPoint = 110; continue gotoNext;} default: {gotoPoint = 96; continue gotoNext;} } } } } } private int scalarBlock() throws java.io.IOException { // System.out.println("scalarBlock()"); QuotedString q = new QuotedString(); q.str[0] = 0; int lastIndent = 0; int parentIndent = -1; int blockType = 0; int nlDoWhat = 0; int forceIndent = -1; int yyt = parser.token; Level lvl = parser.currentLevel(); switch(parser.buffer.buffer[yyt]) { case '|': blockType = YAML.BLOCK_LIT; break; case '>': blockType = YAML.BLOCK_FOLD; break; } while( ++yyt <= parser.cursor ) { if(parser.buffer.buffer[yyt] == '-') { nlDoWhat = YAML.NL_CHOMP; } else if(parser.buffer.buffer[yyt] == '+' ) { nlDoWhat = YAML.NL_KEEP; } else if(Character.isDigit((char)parser.buffer.buffer[yyt])) { forceIndent = (char)parser.buffer.buffer[yyt] - '0'; } } while(true) { parser.token = parser.cursor; int gotoPoint = -1; byte yych = (byte) 0; int yyaccept = 0; gotoNext: while(gotoPoint != -2) { int currentGoto = gotoPoint; gotoPoint = -2; switch(currentGoto) { case -1: if ((parser.limit - parser.cursor) < 5) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case 0x00: {gotoPoint = 120; continue gotoNext;} case '\n': {gotoPoint = 114; continue gotoNext;} case '\r': {gotoPoint = 116; continue gotoNext;} case '#': {gotoPoint = 118; continue gotoNext;} case '-': {gotoPoint = 122; continue gotoNext;} default: {gotoPoint = 123; continue gotoNext;} } case 114: yyaccept = 0; yych = parser.buffer.buffer[(parser.marker = ++parser.cursor)]; {gotoPoint = 133; continue gotoNext;} case 115: { int tok = parser.token; int nl_count = 0, fold_nl = 0, nl_begin = 0; int indt_len = getAndCheckIndentLength(); lvl = parser.currentLevel(); if(lvl.status != LevelStatus.block) { parentIndent = GET_TRUE_YAML_INDENT(); if(forceIndent > 0) forceIndent += parentIndent; if(indt_len > parentIndent) { int new_spaces = forceIndent > 0 ? forceIndent : indt_len; parser.addLevel(new_spaces, LevelStatus.block); lastIndent = indt_len - new_spaces; nl_begin = 1; lvl = parser.currentLevel(); } else { parser.cursor = parser.token; RETURN_YAML_BLOCK(q, blockType, nlDoWhat); return DefaultYAMLParser.YAML_BLOCK; } } /* * Fold only in the event of two lines being on the leftmost * indentation. */ if(blockType == YAML.BLOCK_FOLD && lastIndent == 0 && (indt_len - lvl.spaces) == 0) { fold_nl = 1; } int pacer = parser.token; while(pacer < parser.cursor) { int nl_len = newlineLen(pacer++); if(nl_len>0) { nl_count++; pacer += (nl_len - 1); } } if(fold_nl == 1 || nl_begin == 1) { nl_count--; } if(nl_count < 1 && nl_begin == 0) { q.cat(' '); } else { for(int i = 0; i < nl_count; i++) { q.cat('\n'); } } lastIndent = indt_len - lvl.spaces; parser.cursor -= lastIndent; if(indt_len < lvl.spaces) { parser.popLevel(); parser.cursor = parser.token; RETURN_YAML_BLOCK(q, blockType, nlDoWhat); return DefaultYAMLParser.YAML_BLOCK; } break; } case 116: ++parser.cursor; switch ((yych = parser.buffer.buffer[parser.cursor])) { case '\n': {gotoPoint = 132; continue gotoNext;} default: {gotoPoint = 117; continue gotoNext;} } case 117: { q.cat(parser.buffer.buffer[parser.token]); break; } case 118: ++parser.cursor; { lvl = parser.currentLevel(); if(lvl.status != LevelStatus.block) { eatComments(); parser.token = parser.cursor; } else { q.cat(parser.buffer.buffer[parser.token]); } break; } case 120: ++parser.cursor; { parser.cursor--; parser.popLevel(); RETURN_YAML_BLOCK(q, blockType, nlDoWhat); return DefaultYAMLParser.YAML_BLOCK; } case 122: yyaccept = 1; yych = parser.buffer.buffer[(parser.marker = ++parser.cursor)]; switch (yych) { case '-': {gotoPoint = 124; continue gotoNext;} default: {gotoPoint = 117; continue gotoNext;} } case 123: yych = parser.buffer.buffer[++parser.cursor]; {gotoPoint = 117; continue gotoNext;} case 124: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '-': {gotoPoint = 126; continue gotoNext;} default: {gotoPoint = 125; continue gotoNext;} } case 125: parser.cursor = parser.marker; if (yyaccept == 0) { {gotoPoint = 115; continue gotoNext;} } else { {gotoPoint = 117; continue gotoNext;} } case 126: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 127; continue gotoNext;} case '\r': {gotoPoint = 131; continue gotoNext;} case ' ': {gotoPoint = 129; continue gotoNext;} default: {gotoPoint = 125; continue gotoNext;} } case 127: ++parser.cursor; case 128: { if(parser.token == parser.lineptr) { if(blockType == YAML.BLOCK_FOLD && q.idx > 0) { q.idx--; } q.cat('\n'); parser.popLevel(); parser.cursor = parser.token; RETURN_YAML_BLOCK(q, blockType, nlDoWhat); return DefaultYAMLParser.YAML_BLOCK; } else { q.cat(parser.buffer.buffer[parser.token]); parser.cursor = parser.token + 1; } break; } case 129: ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case ' ': {gotoPoint = 129; continue gotoNext;} default: {gotoPoint = 128; continue gotoNext;} } case 131: yych = parser.buffer.buffer[++parser.cursor]; switch (yych) { case '\n': {gotoPoint = 127; continue gotoNext;} default: {gotoPoint = 125; continue gotoNext;} } case 132: yyaccept = 0; parser.marker = ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; case 133: switch (yych) { case '\n': case ' ': {gotoPoint = 132; continue gotoNext;} case '\r': {gotoPoint = 134; continue gotoNext;} default: {gotoPoint = 115; continue gotoNext;} } case 134: ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case '\n': {gotoPoint = 132; continue gotoNext;} default: {gotoPoint = 125; continue gotoNext;} } } } } } private byte escapeSeq(byte ch) { switch(ch) { case '0': return '\0'; case 'a': return 7; case 'b': return '\010'; case 'e': return '\033'; case 'f': return '\014'; case 'n': return '\n'; case 'r': return '\015'; case 't': return '\t'; case 'v': return '\013'; default: return ch; } } private void eatComments() throws IOException { while(true) { parser.token = parser.cursor; int gotoPoint = -1; byte yych = (byte) 0; gotoNext: while(gotoPoint != -2) { int currentGoto = gotoPoint; gotoPoint = -2; switch(currentGoto) { case -1: if ((parser.limit - parser.cursor) < 2) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case 0x00: {gotoPoint = 137; continue gotoNext;} case '\n': {gotoPoint = 139; continue gotoNext;} case '\r': {gotoPoint = 140; continue gotoNext;} default: {gotoPoint = 142; continue gotoNext;} } case 137: ++parser.cursor; case 138: { parser.cursor = parser.token; return; } case 139: yych = parser.buffer.buffer[(parser.marker = ++parser.cursor)]; {gotoPoint = 144; continue gotoNext;} case 140: ++parser.cursor; switch ((yych = parser.buffer.buffer[parser.cursor])) { case '\n': {gotoPoint = 143; continue gotoNext;} default: {gotoPoint = 141; continue gotoNext;} } case 141: { break; } case 142: yych = parser.buffer.buffer[++parser.cursor]; {gotoPoint = 141; continue gotoNext;} case 143: parser.marker = ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; case 144: switch (yych) { case '\n': {gotoPoint = 143; continue gotoNext;} case '\r': {gotoPoint = 145; continue gotoNext;} default: {gotoPoint = 138; continue gotoNext;} } case 145: ++parser.cursor; if (parser.limit <= parser.cursor) parser.read(); yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case '\n': {gotoPoint = 143; continue gotoNext;} default: {gotoPoint = 146; continue gotoNext;} } case 146: parser.cursor = parser.marker; {gotoPoint = 138; continue gotoNext;} } } } } } yecht-yecht-1.1/src/main/org/yecht/TokenScanner.re000066400000000000000000001343341262256356000221600ustar00rootroot00000000000000package org.yecht; import java.io.IOException; // Equivalent to token.re public class TokenScanner implements DefaultYAMLParser.yyInput { public final static int QUOTELEN = 1024; private Parser parser; private Object lval; private int currentToken = -1; public static void error(String msg, Parser parser) { if(parser.error_handler == null) { parser.error_handler = new ErrorHandler.Default(); } parser.root = parser.root_on_error; parser.error_handler.handle(parser, msg); } public static DefaultYAMLParser.yyInput createScanner(Parser parser) { switch(parser.input_type) { case YAML_UTF8: return new TokenScanner(parser); case Bytecode_UTF8: return new BytecodeScanner(parser); case YAML_UTF16: error("UTF-16 is not currently supported in Yecht.\nPlease contribute code to help this happen!", parser); return null; case YAML_UTF32: error("UTF-32 is not currently supported in Yecht.\nPlease contribute code to help this happen!", parser); return null; } return null; } public TokenScanner(Parser parser) { this.parser = parser; } public Object value() { return lval; } public int token() { return currentToken; } public boolean advance() throws java.io.IOException { currentToken = real_yylex(); return currentToken == 0 ? false : true; } private int isNewline(int ptr) { return newlineLen(ptr); } private int newlineLen(int ptr) { if(parser.buffer.buffer[ptr] == '\n') return 1; if(parser.buffer.buffer[ptr] == '\r' && parser.buffer.buffer[ptr+1] == '\n') return 2; return 0; } private int isNewline(byte[] buff, int ptr) { return newlineLen(buff, ptr); } private int newlineLen(byte[] buff, int ptr) { if(buff[ptr] == '\n') return 1; if(buff[ptr] == '\r' && buff[ptr+1] == '\n') return 2; return 0; } private void NEWLINE(int ptr) { parser.lineptr = ptr + newlineLen(ptr); if(parser.lineptr > parser.linectptr) { parser.linect++; parser.linectptr = parser.lineptr; } } private void RETURN_YAML_BLOCK(QuotedString q, int blockType, int nlDoWhat) { Node n = Node.allocStr(); if(parser.taguri_expansion) { n.type_id = Parser.taguri(YAML.DOMAIN, "str"); } else { n.type_id = "str"; } Data.Str dd = (Data.Str)n.data; dd.ptr = Pointer.create(q.str, 0); dd.len = q.idx; if(blockType == YAML.BLOCK_LIT) { dd.style = ScalarStyle.Literal; } else { dd.style = ScalarStyle.Fold; } if(q.idx > 0) { if(nlDoWhat != YAML.NL_KEEP) { int fc = dd.len - 1; while(isNewline(dd.ptr.buffer, fc) > 0) { fc--; } if(nlDoWhat != YAML.NL_CHOMP && fc < (dd.len-1)) { fc += 1; } dd.len = fc + 1; } } lval = n; } private int GET_TRUE_YAML_INDENT() { Level lvl_deep = parser.currentLevel(); int indt_len = lvl_deep.spaces; if(lvl_deep.status == LevelStatus.seq || (indt_len == parser.cursor - parser.lineptr && lvl_deep.status != LevelStatus.map)) { parser.lvl_idx--; Level lvl_over = parser.currentLevel(); indt_len = lvl_over.spaces; parser.lvl_idx++; } return indt_len; } public final static String[] tnames = new String[269]; static { tnames[0] = "ENDINPUT"; tnames[256] = "error"; tnames[44] = "COMMA"; tnames[45] = "DASH"; tnames[58] = "COLON"; tnames[63] = "QUESTION"; tnames[91] = "SQUAREO"; tnames[93] = "SQUAREC"; tnames[123] = "CURLYO"; tnames[125] = "CURLYC"; tnames[257] = "ANCHOR"; tnames[258] = "ALIAS"; tnames[264] = "BLOCK"; tnames[265] = "DOCSEP"; tnames[268] = "IEND"; tnames[267] = "INDENT"; tnames[266] = "IOPEN"; tnames[261] = "ITRANSFER"; tnames[263] = "PLAIN"; tnames[260] = "TAGURI"; tnames[259] = "TRANSFER"; tnames[262] = "WORD"; } private void YYPOS(int n) { parser.cursor = parser.token + n; } private static class QuotedString { public int idx = 0; public int capa = 100; public byte[] str; public QuotedString() { str = new byte[100]; } public void cat(char l) { cat((byte)l); } public void cat(byte l) { if(idx + 1 >= capa) { capa += QUOTELEN; str = YAML.realloc(str, capa); } str[idx++] = l; str[idx] = 0; } public void cat(byte[] l, int cs, int cl) { while(idx + cl >= capa) { capa += QUOTELEN; str = YAML.realloc(str, capa); } System.arraycopy(l, cs, str, idx, cl); idx += cl; str[idx] = 0; } public void plain_is_inl() { int walker = idx - 1; while(walker > 0 && (str[walker] == '\n' || str[walker] == ' ' || str[walker] == '\t')) { idx--; str[walker] = 0; walker--; } } } public void RETURN_IMPLICIT(QuotedString q) { Node n = Node.allocStr(); parser.cursor = parser.token; Data.Str dd = (Data.Str)n.data; dd.ptr = Pointer.create(q.str, 0); dd.len = q.idx; dd.style = ScalarStyle.Plain; lval = n; if(parser.implicit_typing) { ImplicitScanner2.tryTagImplicit(n, parser.taguri_expansion); } } private int real_yylex() throws IOException { if(parser.cursor == -1) { parser.read(); } // System.err.println("real_yylex(" + new String(parser.buffer.buffer, parser.buffer.start, parser.bufsize) + ")"); // System.out.println("real_yylex()"); if(parser.force_token != 0) { int t = parser.force_token; parser.force_token = 0; return t; } /*!re2j re2j:define:YYCTYPE = "byte"; re2j:define:YYCURSOR = "parser.cursor"; re2j:define:YYMARKER = "parser.marker"; re2j:define:YYLIMIT = "parser.limit"; re2j:define:YYDATA = "parser.buffer.buffer"; re2j:yyfill:parameter = 0; re2j:define:YYFILL = "parser.read()"; YWORDC = [A-Za-z0-9_-] ; YWORDP = [A-Za-z0-9_-\.] ; LF = ( "\n" | "\r\n" ) ; SPC = " " ; TAB = "\t" ; SPCTAB = ( SPC | TAB ) ; ENDSPC = ( SPC+ | LF ) ; YINDENT = LF ( SPC | LF )* ; NULL = [\000] ; ANY = [\001-\377] ; ISEQO = "[" ; ISEQC = "]" ; IMAPO = "{" ; IMAPC = "}" ; CDELIMS = ( ISEQC | IMAPC ) ; ICOMMA = ( "," ENDSPC ) ; ALLX = ( ":" ENDSPC ) ; DIR = "%" YWORDP+ ":" YWORDP+ ; YBLOCK = [>|] [-+0-9]* ENDSPC ; HEX = [0-9A-Fa-f] ; ESCSEQ = ["\\abefnrtv0] ; */ if(parser.lineptr != parser.cursor) { return document(0); } else { return header(); } } private int header() throws java.io.IOException { // System.out.println("header()"); Level lvl; int doc_level = 0; while(true) { parser.token = parser.cursor; /*!re2j "---" ENDSPC { lvl = parser.currentLevel(); if(lvl.status == LevelStatus.header) { YYPOS(3); return directive(); } else { if(lvl.spaces > -1) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } YYPOS(0); return 0; } } "..." ENDSPC { lvl = parser.currentLevel(); if(lvl.status != LevelStatus.header) { if(lvl.spaces > -1) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } YYPOS(0); return 0; } break; } "#" { eatComments(); break; } NULL { lvl = parser.currentLevel(); if(lvl.spaces > -1) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } YYPOS(0); return 0; } YINDENT { int indent = parser.token; NEWLINE(indent); while(indent < parser.cursor) { // these pieces commented out to be compatible with Syck 0.60. // if(parser.buffer.buffer[indent] == '\t') { // error("TAB found in your indentation, please remove",parser); // } else if(isNewline(++indent) != 0) { // NEWLINE(indent); // } if(isNewline(++indent) != 0) { NEWLINE(indent); } } doc_level = 0; if(parser.buffer.buffer[parser.cursor] == 0) { doc_level = -1; parser.token = parser.cursor-1; } else if(parser.buffer.buffer[parser.lineptr] == ' ') { doc_level = parser.cursor - parser.lineptr; } break; } SPCTAB+ { doc_level = parser.cursor - parser.lineptr; break; } ANY { YYPOS(0); return document(doc_level); } */ } } private final static boolean[] YWORDC = new boolean[256]; private final static boolean[] DIGIT_OR_SIGN = new boolean[256]; static { for(char c = 'a'; c<='z'; c++) { YWORDC[c] = true; } for(char c = 'A'; c<='Z'; c++) { YWORDC[c] = true; } for(char c = '0'; c<='9'; c++) { YWORDC[c] = true; DIGIT_OR_SIGN[c] = true; } YWORDC['_'] = true; YWORDC['-'] = true; DIGIT_OR_SIGN['-'] = true; DIGIT_OR_SIGN['+'] = true; } // (SPC | LF)* private void spcOrLfStar() throws IOException { byte ych; while(true) { if(parser.cursor+3 >= parser.limit) parser.read(); ych = parser.buffer.buffer[parser.cursor]; switch(ych) { case ' ': case '\n': parser.cursor++; break; case '\r': if(parser.buffer.buffer[parser.cursor+1] == '\n') { parser.cursor+=2; break; } else { return; } default: return; } } } // YWORDC+ private boolean ywordc() throws IOException { if(!YWORDC[parser.buffer.buffer[parser.cursor] & 0xFF]) return false; parser.cursor++; while(true) { if(parser.cursor == parser.limit) parser.read(); if(!YWORDC[parser.buffer.buffer[parser.cursor] & 0xFF]) return true; parser.cursor++; } } // ( SPC+ | LF ) private boolean endspc() throws IOException { byte ych = parser.buffer.buffer[parser.cursor]; switch(ych) { case ' ': parser.cursor++; while(true) { if(parser.cursor == parser.limit) parser.read(); if(parser.buffer.buffer[parser.cursor] != ' ') return true; parser.cursor++; } case '\r': if(parser.buffer.buffer[parser.cursor+1] != '\n') { return false; } parser.cursor++; case '\n': parser.cursor++; return true; default: return false; } } // [-+0-9]* ENDSPC private boolean yblock() throws IOException { int plus = 0; int ych = parser.buffer.buffer[parser.cursor + plus] & 0xFF; while(DIGIT_OR_SIGN[ych]) { plus++; if((parser.limit - parser.cursor) < plus) parser.read(); ych = parser.buffer.buffer[parser.cursor + plus] & 0xFF; } switch(ych) { case ' ': plus++; while(true) { if((parser.limit - parser.cursor) < plus) parser.read(); if(parser.buffer.buffer[parser.cursor + plus] != ' ') { parser.cursor += plus; return true; } plus++; } case '\r': if(parser.buffer.buffer[parser.cursor+plus+1] != '\n') { return false; } plus++; case '\n': plus++; parser.cursor += plus; return true; default: return false; } } private int document(int doc_level) throws java.io.IOException { // System.out.println("document()"); boolean do_any = false; while(true) { Level lvl = parser.currentLevel(); if(lvl.status == LevelStatus.header) { lvl.status = LevelStatus.doc; } parser.token = parser.cursor; if ((parser.limit - parser.cursor) < 3) parser.read(); byte yych = parser.buffer.buffer[parser.cursor]; switch (yych) { case 0x00: parser.cursor++; if(lvl.spaces > -1) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } YYPOS(0); return 0; case '\t': case ' ': parser.cursor++; while((yych = parser.buffer.buffer[parser.cursor]) == '\t' || yych == ' ') { parser.cursor++; if(parser.cursor == parser.limit) parser.read(); } break; case '\r': if(parser.buffer.buffer[parser.cursor+1] != '\n') { do_any = true; break; } else { parser.cursor++; } case '\n': parser.cursor++; spcOrLfStar(); /* Isolate spaces */ int indt_len; int indent = parser.token; NEWLINE(indent); while(indent < parser.cursor) { // these pieces commented out to be compatible with Syck 0.60. // if(parser.buffer.buffer[indent] == '\t') { // error("TAB found in your indentation, please remove",parser); // } else if(isNewline(++indent) != 0) { // NEWLINE(indent); // } if(isNewline(++indent) != 0) { NEWLINE(indent); } } indt_len = 0; if(parser.buffer.buffer[parser.cursor] == 0) { indt_len = -1; parser.token = parser.cursor-1; } else if(parser.buffer.buffer[parser.lineptr] == ' ') { indt_len = parser.cursor - parser.lineptr; } lvl = parser.currentLevel(); doc_level = 0; /* XXX: Comment lookahead */ /* Ignore indentation inside inlines */ if(parser.buffer.buffer[parser.cursor] != '#' && lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { /* Check for open indent */ if(lvl.spaces > indt_len) { parser.popLevel(); YYPOS(0); return DefaultYAMLParser.YAML_IEND; } if(lvl.spaces < indt_len) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel(indt_len, LevelStatus.doc); return DefaultYAMLParser.YAML_IOPEN; } } else { if(indt_len == -1) { return 0; } return DefaultYAMLParser.YAML_INDENT; } } break; case '!': parser.cursor++; return transferMethod(); case '"': parser.cursor++; if(lvl.spaces < doc_level) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel(doc_level, LevelStatus.doc); YYPOS(0); return DefaultYAMLParser.YAML_IOPEN; } } else { return doubleQuote(); } break; case '#': parser.cursor++; eatComments(); break; case '&': parser.cursor++; if(ywordc()) { lval = new String(parser.buffer.buffer, parser.token + 1, parser.cursor - (parser.token + 1), "ISO-8859-1"); /* * Remove previous anchors of the same name. Since the parser will likely * construct deeper nodes first, we want those nodes to be placed in the * queue for matching at a higher level of indentation. */ parser.removeAnchor((String)lval); return DefaultYAMLParser.YAML_ANCHOR; } else { parser.cursor--; do_any = true; break; } case '\'': parser.cursor++; if(lvl.spaces < doc_level) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel(doc_level, LevelStatus.doc); YYPOS(0); return DefaultYAMLParser.YAML_IOPEN; } } else { return singleQuote(); } break; case '*': parser.cursor++; if(ywordc()) { if(lvl.spaces < doc_level) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel(doc_level, LevelStatus.doc); YYPOS(0); return DefaultYAMLParser.YAML_IOPEN; } } else { lval = new String(parser.buffer.buffer, parser.token + 1, parser.cursor - (parser.token + 1), "ISO-8859-1"); return DefaultYAMLParser.YAML_ALIAS; } } else { parser.cursor--; do_any = true; } break; case ',': case ':': parser.cursor++; if(endspc()) { if( parser.buffer.buffer[parser.token] == ':' && lvl.status != LevelStatus.imap && lvl.status != LevelStatus.iseq ) { lvl.status = LevelStatus.map; } YYPOS(1); return parser.buffer.buffer[parser.token]; } else { parser.cursor--; do_any = true; break; } case '-': case '?': parser.cursor++; if(endspc()) { if(lvl.spaces < (parser.token - parser.lineptr)) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel((parser.token - parser.lineptr), LevelStatus.doc); YYPOS(0); return DefaultYAMLParser.YAML_IOPEN; } } else { parser.force_token = DefaultYAMLParser.YAML_IOPEN; if( parser.buffer.buffer[parser.cursor] == '#' || isNewline(parser.cursor) != 0 || isNewline(parser.cursor-1) != 0) { parser.cursor--; parser.addLevel(parser.token + 1 - parser.lineptr, LevelStatus.seq); } else /* spaces followed by content uses the space as indentation */ { parser.addLevel(parser.cursor - parser.lineptr, LevelStatus.seq); } return parser.buffer.buffer[parser.token]; } } else { parser.cursor--; do_any = true; } break; case '>': case '|': parser.cursor++; if(yblock()) { if(isNewline(parser.cursor - 1) != 0) { parser.cursor--; } return scalarBlock(); } else { parser.cursor--; do_any = true; } break; case '[': parser.cursor++; if(lvl.spaces < doc_level) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel(doc_level, LevelStatus.doc); YYPOS(0); return DefaultYAMLParser.YAML_IOPEN; } } else { lvl = parser.currentLevel(); parser.addLevel(lvl.spaces + 1, LevelStatus.iseq); return parser.buffer.buffer[parser.token]; } break; case ']': case '}': parser.cursor++; parser.popLevel(); return parser.buffer.buffer[parser.token]; case '{': parser.cursor++; if(lvl.spaces < doc_level) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel(doc_level, LevelStatus.doc); YYPOS(0); return DefaultYAMLParser.YAML_IOPEN; } } else { lvl = parser.currentLevel(); parser.addLevel(lvl.spaces + 1, LevelStatus.imap); return parser.buffer.buffer[parser.token]; } break; default: do_any = true; break; } if(do_any) { if(lvl.spaces < doc_level) { if(lvl.status != LevelStatus.iseq && lvl.status != LevelStatus.imap) { parser.addLevel(doc_level, LevelStatus.doc); YYPOS(0); return DefaultYAMLParser.YAML_IOPEN; } } else { return plain(); } do_any = false; } } } private int directive() throws java.io.IOException { // System.out.println("directive()"); while(true) { parser.toktmp = parser.cursor; /*!re2j DIR { break; } SPCTAB+ { break; } ANY { parser.cursor = parser.toktmp; return DefaultYAMLParser.YAML_DOCSEP; } */ } } private int getAndCheckIndentLength() { int indt_len; int indent = parser.token; NEWLINE(indent); while(indent < parser.cursor) { // these pieces commented out to be compatible with Syck 0.60. // if(parser.buffer.buffer[indent] == '\t') { // error("TAB found in your indentation, please remove",parser); // } else if(isNewline(++indent) != 0) { // NEWLINE(indent); // } if(isNewline(++indent) != 0) { NEWLINE(indent); } } indt_len = 0; if(parser.buffer.buffer[parser.cursor] == 0) { indt_len = -1; } else if(parser.buffer.buffer[parser.lineptr] == ' ') { indt_len = parser.cursor - parser.lineptr; } return indt_len; } private void countAndAddNewlines(QuotedString q) { int nl_count = 0; while(parser.token < parser.cursor) { int nl_len = newlineLen(parser.token++); if(nl_len > 0) { nl_count++; parser.token += (nl_len - 1); } } if(nl_count <= 1) { q.cat(' '); } else { for(int i = 0; i < nl_count - 1; i++) { q.cat('\n'); } } } private int plain() throws java.io.IOException { // System.out.println("plain()"); QuotedString q = new QuotedString(); parser.cursor = parser.token; Level plvl = parser.currentLevel(); Level lvl_deep = parser.currentLevel(); int parentIndent = lvl_deep.spaces; if(lvl_deep.status == LevelStatus.seq || ((parentIndent == parser.cursor - parser.lineptr) && lvl_deep.status != LevelStatus.map)) { parser.lvl_idx--; Level lvl_over = parser.currentLevel(); parentIndent = lvl_over.spaces; parser.lvl_idx++; } boolean plain3 = false; boolean do_any = false; while(true) { parser.token = parser.cursor; do { plain3 = false; if ((parser.limit - parser.cursor) < 3) parser.read(); byte yych = parser.buffer.buffer[parser.cursor]; switch(yych) { // YINDENT case '\r': if(parser.buffer.buffer[parser.cursor+1] != '\n') { do_any = true; break; } else { parser.cursor++; } case '\n': parser.cursor++; spcOrLfStar(); int indt_len = getAndCheckIndentLength(); if(indt_len <= parentIndent) { RETURN_IMPLICIT(q); return DefaultYAMLParser.YAML_PLAIN; } countAndAddNewlines(q); break; case 0x00: parser.cursor++; RETURN_IMPLICIT(q); return DefaultYAMLParser.YAML_PLAIN; case ' ': if(parser.buffer.buffer[parser.cursor+1] == '#') { parser.cursor+=2; eatComments(); RETURN_IMPLICIT(q); return DefaultYAMLParser.YAML_PLAIN; } case '\t': parser.cursor++; if(q.idx != 0) { plain3 = true; } break; case '}': parser.cursor++; if(plvl.status != LevelStatus.imap) { // PLAIN_NOT_INL if(parser.buffer.buffer[parser.cursor-1] == ' ' || isNewline(parser.cursor-1) > 0) { parser.cursor--; } q.cat(parser.buffer.buffer, parser.token, parser.cursor - parser.token); } else { q.plain_is_inl(); RETURN_IMPLICIT(q); return DefaultYAMLParser.YAML_PLAIN; } break; case ']': parser.cursor++; if(plvl.status != LevelStatus.iseq) { // PLAIN_NOT_INL if(parser.buffer.buffer[parser.cursor-1] == ' ' || isNewline(parser.cursor-1) > 0) { parser.cursor--; } q.cat(parser.buffer.buffer, parser.token, parser.cursor - parser.token); } else { q.plain_is_inl(); RETURN_IMPLICIT(q); return DefaultYAMLParser.YAML_PLAIN; } break; // ALLX case ':': parser.cursor++; if(endspc()) { RETURN_IMPLICIT(q); return DefaultYAMLParser.YAML_PLAIN; } else { parser.cursor--; do_any = true; break; } // ICOMMA case ',': parser.cursor++; if(endspc()) { if(plvl.status != LevelStatus.iseq && plvl.status != LevelStatus.imap) { // PLAIN_NOT_INL if(parser.buffer.buffer[parser.cursor-1] == ' ' || isNewline(parser.cursor-1) > 0) { parser.cursor--; } q.cat(parser.buffer.buffer, parser.token, parser.cursor - parser.token); } else { q.plain_is_inl(); RETURN_IMPLICIT(q); return DefaultYAMLParser.YAML_PLAIN; } break; } else { parser.cursor--; do_any = true; break; } default: do_any = true; break; } if(do_any) { parser.cursor++; q.cat(parser.buffer.buffer, parser.token, parser.cursor - parser.token); do_any = false; } } while(plain3); } } private int doubleQuote() throws java.io.IOException { // System.out.println("doubleQuote()"); int keep_nl = 1; QuotedString q = new QuotedString(); while(true) { parser.token = parser.cursor; /*!re2j YINDENT { // GOBBLE_UP_YAML_INDENT( indt_len, YYTOKEN ) int indent = parser.token; NEWLINE(indent); while(indent < parser.cursor) { // these pieces commented out to be compatible with Syck 0.60. // if(parser.buffer.buffer[indent] == '\t') { // error("TAB found in your indentation, please remove",parser); // } else if(isNewline(++indent) != 0) { // NEWLINE(indent); // } if(isNewline(++indent) != 0) { NEWLINE(indent); } } int indt_len = 0; if(parser.buffer.buffer[parser.cursor] == 0) { indt_len = -1; parser.token = parser.cursor-1; } else if(parser.buffer.buffer[parser.lineptr] == ' ') { indt_len = parser.cursor - parser.lineptr; } int nl_count = 0; Level lvl = parser.currentLevel(); if(lvl.status != LevelStatus.str) { parser.addLevel(indt_len, LevelStatus.str); } else if(indt_len < lvl.spaces) { // Error! } if(keep_nl == 1) { countAndAddNewlines(q); } keep_nl = 1; break; } "\\" ESCSEQ { byte ch = parser.buffer.buffer[parser.cursor-1]; q.cat(escapeSeq(ch)); break; } "\\x" HEX HEX { q.cat((byte)Integer.valueOf(new String(parser.buffer.buffer, parser.token+2, 2, "ISO-8859-1"), 16).intValue()); break; } "\\" SPC* LF { keep_nl = 0; parser.cursor--; break; } ( "\"" | NULL ) { Node n = Node.allocStr(); Level lvl = parser.currentLevel(); if(lvl.status == LevelStatus.str) { parser.popLevel(); } if(parser.taguri_expansion) { n.type_id = Parser.taguri(YAML.DOMAIN, "str"); } else { n.type_id = "str"; } Data.Str dd = (Data.Str)n.data; dd.ptr = Pointer.create(q.str, 0); dd.len = q.idx; dd.style = ScalarStyle.TwoQuote; lval = n; return DefaultYAMLParser.YAML_PLAIN; } ANY { q.cat(parser.buffer.buffer[parser.cursor-1]); break; } */ } } private int singleQuote() throws java.io.IOException { // System.out.println("singleQuote()"); QuotedString q = new QuotedString(); while(true) { parser.token = parser.cursor; /*!re2j YINDENT { // GOBBLE_UP_YAML_INDENT( indt_len, YYTOKEN ) int indent = parser.token; NEWLINE(indent); while(indent < parser.cursor) { // these pieces commented out to be compatible with Syck 0.60. // if(parser.buffer.buffer[indent] == '\t') { // error("TAB found in your indentation, please remove",parser); // } else if(isNewline(++indent) != 0) { // NEWLINE(indent); // } if(isNewline(++indent) != 0) { NEWLINE(indent); } } int indt_len = 0; if(parser.buffer.buffer[parser.cursor] == 0) { indt_len = -1; parser.token = parser.cursor-1; } else if(parser.buffer.buffer[parser.lineptr] == ' ') { indt_len = parser.cursor - parser.lineptr; } int nl_count = 0; Level lvl = parser.currentLevel(); if(lvl.status != LevelStatus.str) { parser.addLevel(indt_len, LevelStatus.str); } else if(indt_len < lvl.spaces) { // Error! } while(parser.token < parser.cursor) { int nl_len = newlineLen(parser.token++); if(nl_len > 0) { nl_count++; parser.token += (nl_len - 1); } } if(nl_count <= 1) { q.cat(' '); } else { for(int i = 0; i < nl_count - 1; i++) { q.cat('\n'); } } break; } "''" { q.cat('\''); break; } ( "'" | NULL ) { Node n = Node.allocStr(); Level lvl = parser.currentLevel(); if(lvl.status == LevelStatus.str) { parser.popLevel(); } if(parser.taguri_expansion) { n.type_id = Parser.taguri(YAML.DOMAIN, "str"); } else { n.type_id = "str"; } Data.Str dd = (Data.Str)n.data; dd.ptr = Pointer.create(q.str, 0); dd.len = q.idx; dd.style = ScalarStyle.OneQuote; lval = n; return DefaultYAMLParser.YAML_PLAIN; } ANY { q.cat(parser.buffer.buffer[parser.cursor-1]); break; } */ } } private int transferMethod() throws java.io.IOException { // System.out.println("transferMethod()"); QuotedString q = new QuotedString(); while(true) { parser.toktmp = parser.cursor; /*!re2j ( ENDSPC | NULL ) { parser.cursor = parser.toktmp; if(parser.cursor == parser.token + 1) { return DefaultYAMLParser.YAML_ITRANSFER; } Level lvl = parser.currentLevel(); /* * URL Prefixing */ if(q.str[0] == '^') { lval = lvl.domain + new String(q.str, 1, q.idx - 1, "ISO-8859-1"); } else { int carat = 0; int qend = q.idx; while((++carat) < qend) { if(q.str[carat] == '^') { break; } } if(carat < qend) { lvl.domain = new String(q.str, 0, carat, "ISO-8859-1"); lval = lvl.domain + new String(q.str, carat + 1, (qend - carat) - 1, "ISO-8859-1"); } else { lval = new String(q.str, 0, qend, "ISO-8859-1"); } } return DefaultYAMLParser.YAML_TRANSFER; } /* * URL Escapes */ "\\" ESCSEQ { byte ch = parser.buffer.buffer[parser.cursor-1]; q.cat(escapeSeq(ch)); break; } "\\x" HEX HEX { q.cat((byte)Integer.valueOf(new String(parser.buffer.buffer, parser.toktmp+2, 2, "ISO-8859-1"), 16).intValue()); break; } ANY { q.cat(parser.buffer.buffer[parser.cursor-1]); break; } */ } } private int scalarBlock() throws java.io.IOException { // System.out.println("scalarBlock()"); QuotedString q = new QuotedString(); q.str[0] = 0; int lastIndent = 0; int parentIndent = -1; int blockType = 0; int nlDoWhat = 0; int forceIndent = -1; int yyt = parser.token; Level lvl = parser.currentLevel(); switch(parser.buffer.buffer[yyt]) { case '|': blockType = YAML.BLOCK_LIT; break; case '>': blockType = YAML.BLOCK_FOLD; break; } while( ++yyt <= parser.cursor ) { if(parser.buffer.buffer[yyt] == '-') { nlDoWhat = YAML.NL_CHOMP; } else if(parser.buffer.buffer[yyt] == '+' ) { nlDoWhat = YAML.NL_KEEP; } else if(Character.isDigit((char)parser.buffer.buffer[yyt])) { forceIndent = (char)parser.buffer.buffer[yyt] - '0'; } } while(true) { parser.token = parser.cursor; /*!re2j YINDENT { int tok = parser.token; int nl_count = 0, fold_nl = 0, nl_begin = 0; int indt_len = getAndCheckIndentLength(); lvl = parser.currentLevel(); if(lvl.status != LevelStatus.block) { parentIndent = GET_TRUE_YAML_INDENT(); if(forceIndent > 0) forceIndent += parentIndent; if(indt_len > parentIndent) { int new_spaces = forceIndent > 0 ? forceIndent : indt_len; parser.addLevel(new_spaces, LevelStatus.block); lastIndent = indt_len - new_spaces; nl_begin = 1; lvl = parser.currentLevel(); } else { parser.cursor = parser.token; RETURN_YAML_BLOCK(q, blockType, nlDoWhat); return DefaultYAMLParser.YAML_BLOCK; } } /* * Fold only in the event of two lines being on the leftmost * indentation. */ if(blockType == YAML.BLOCK_FOLD && lastIndent == 0 && (indt_len - lvl.spaces) == 0) { fold_nl = 1; } int pacer = parser.token; while(pacer < parser.cursor) { int nl_len = newlineLen(pacer++); if(nl_len>0) { nl_count++; pacer += (nl_len - 1); } } if(fold_nl == 1 || nl_begin == 1) { nl_count--; } if(nl_count < 1 && nl_begin == 0) { q.cat(' '); } else { for(int i = 0; i < nl_count; i++) { q.cat('\n'); } } lastIndent = indt_len - lvl.spaces; parser.cursor -= lastIndent; if(indt_len < lvl.spaces) { parser.popLevel(); parser.cursor = parser.token; RETURN_YAML_BLOCK(q, blockType, nlDoWhat); return DefaultYAMLParser.YAML_BLOCK; } break; } "#" { lvl = parser.currentLevel(); if(lvl.status != LevelStatus.block) { eatComments(); parser.token = parser.cursor; } else { q.cat(parser.buffer.buffer[parser.token]); } break; } NULL { parser.cursor--; parser.popLevel(); RETURN_YAML_BLOCK(q, blockType, nlDoWhat); return DefaultYAMLParser.YAML_BLOCK; } "---" ENDSPC { if(parser.token == parser.lineptr) { if(blockType == YAML.BLOCK_FOLD && q.idx > 0) { q.idx--; } q.cat('\n'); parser.popLevel(); parser.cursor = parser.token; RETURN_YAML_BLOCK(q, blockType, nlDoWhat); return DefaultYAMLParser.YAML_BLOCK; } else { q.cat(parser.buffer.buffer[parser.token]); parser.cursor = parser.token + 1; } break; } ANY { q.cat(parser.buffer.buffer[parser.token]); break; } */ } } private byte escapeSeq(byte ch) { switch(ch) { case '0': return '\0'; case 'a': return 7; case 'b': return '\010'; case 'e': return '\033'; case 'f': return '\014'; case 'n': return '\n'; case 'r': return '\015'; case 't': return '\t'; case 'v': return '\013'; default: return ch; } } private void eatComments() throws IOException { while(true) { parser.token = parser.cursor; /*!re2j ( LF+ | NULL ) { parser.cursor = parser.token; return; } ANY { break; } */ } } } yecht-yecht-1.1/src/main/org/yecht/YAML.java000066400000000000000000000111061262256356000206320ustar00rootroot00000000000000/* * See LICENSE file in distribution for copyright and licensing information. */ package org.yecht; /** * * @author Ola Bini */ public class YAML { public final static int BLOCK_FOLD = 10; public final static int BLOCK_LIT = 20; public final static int BLOCK_PLAIN = 30; public final static int NL_CHOMP = 40; public final static int NL_KEEP = 50; public final static int YAML_MAJOR = 1; public final static int YAML_MINOR = 0; public final static String YECHT_VERSION = "0.0.2"; public final static String DOMAIN = "yaml.org,2002"; public final static int ALLOC_CT = 8; public final static int BUFFERSIZE = 4096; public final static String DEFAULT_ANCHOR_FORMAT = "id%03d"; /* specify list of bytecodes */ public final static byte BYTE_FINISH = (byte) 0; public final static byte BYTE_DOCUMENT = (byte)'D'; public final static byte BYTE_DIRECTIVE = (byte)'V'; public final static byte BYTE_PAUSE = (byte)'P'; public final static byte BYTE_MAPPING = (byte)'M'; public final static byte BYTE_SEQUENCE = (byte)'Q'; public final static byte BYTE_END_BRANCH = (byte)'E'; public final static byte BYTE_SCALAR = (byte)'S'; public final static byte BYTE_CONTINUE = (byte)'C'; public final static byte BYTE_NEWLINE = (byte)'N'; public final static byte BYTE_NULLCHAR = (byte)'Z'; public final static byte BYTE_ANCHOR = (byte)'A'; public final static byte BYTE_ALIAS = (byte)'R'; public final static byte BYTE_TRANSFER = (byte)'T'; /* formatting bytecodes */ public final static byte BYTE_COMMENT = (byte)'c'; public final static byte BYTE_INDENT = (byte)'i'; public final static byte BYTE_STYLE = (byte)'s'; /* other bytecodes */ public final static byte BYTE_LINE_NUMBER = (byte)'#'; public final static byte BYTE_WHOLE_SCALAR = (byte)'<'; public final static byte BYTE_NOTICE = (byte)'!'; public final static byte BYTE_SPAN = (byte)')'; public final static byte BYTE_ALLOC = (byte)'@'; /* second level style bytecodes, ie "s>" */ public final static byte BYTE_FLOW = (byte)'>'; public final static byte BYTE_LITERAL = (byte)'|'; public final static byte BYTE_BLOCK = (byte)'b'; public final static byte BYTE_PLAIN = (byte)'p'; public final static byte BYTE_INLINE_MAPPING = (byte)'{'; public final static byte BYTE_INLINE_SEQUENCE = (byte)'['; public final static byte BYTE_SINGLE_QUOTED = (byte)39; public final static byte BYTE_DOUBLE_QUOTED = (byte)'"'; public static byte[] realloc(byte[] input, int size) { byte[] newArray = new byte[size]; System.arraycopy(input, 0, newArray, 0, input.length); return newArray; } public static long[] realloc(long[] input, int size) { long[] newArray = new long[size]; System.arraycopy(input, 0, newArray, 0, input.length); return newArray; } public static Level[] realloc(Level[] input, int size) { Level[] newArray = new Level[size]; System.arraycopy(input, 0, newArray, 0, input.length); return newArray; } public static Object[] realloc(Object[] input, int size) { Object[] newArray = new Object[size]; System.arraycopy(input, 0, newArray, 0, input.length); return newArray; } // syck_yaml2byte public static byte[] yaml2byte(byte[] yamlstr) { Parser parser = Parser.newParser(); parser.str(Pointer.create(yamlstr, 0), null); parser.handler(new BytecodeNodeHandler()); parser.errorHandler(null); parser.implicitTyping(true); parser.taguriExpansion(true); Bytestring sav = (Bytestring)parser.parse(); if(null == sav) { return null; } else { byte[] ret = new byte[Bytestring.strlen(sav.buffer) + 2]; ret[0] = 'D'; ret[1] = '\n'; System.arraycopy(sav.buffer, 0, ret, 2, ret.length-2); return ret; } } public static void main(String[] args) throws Exception { byte[] yaml = "test: 1\nand: \"with new\\nline\\n\"\nalso: &3 three\nmore: *3".getBytes("ISO-8859-1"); System.out.println("--- # YAML "); System.out.print(new String(yaml, "ISO-8859-1")); System.out.print("\n...\n"); System.out.print(new String(yaml2byte(yaml), "ISO-8859-1")); } } yecht-yecht-1.1/src/main/org/yecht/debug/000077500000000000000000000000001262256356000203145ustar00rootroot00000000000000yecht-yecht-1.1/src/main/org/yecht/debug/ScannerOutput.java000066400000000000000000000037661262256356000240050ustar00rootroot00000000000000package org.yecht.debug; import java.io.InputStream; import java.io.FileInputStream; import org.yecht.*; public class ScannerOutput { public static void main(String[] args) throws Exception { String filename = args[0]; int len = 8000; int read = 0; int currRead = 0; byte[] buffer = new byte[1024]; byte[] input = new byte[len]; InputStream is = new FileInputStream(filename); while((currRead = is.read(buffer, 0, 1024)) != -1) { if(read + currRead >= len) { len *= 2; input = YAML.realloc(input, len); } System.arraycopy(buffer, 0, input, read, currRead); read += currRead; } Parser parser = Parser.newParser(); parser.str(Pointer.create(input, 0), read, null); parser.handler(new NullNodeHandler()); parser.errorHandler(null); parser.implicitTyping(true); parser.taguriExpansion(true); DefaultYAMLParser.yyInput s = TokenScanner.createScanner(parser); int tok = -1; Object lval = null; int indent = 0; while(tok != 0) { s.advance(); tok = s.token(); if(tok == DefaultYAMLParser.YAML_IOPEN) { for(int i=0; i < indent; i++) { System.out.print(" "); } indent++; } else if(tok == DefaultYAMLParser.YAML_IEND) { indent--; for(int i=0; i < indent; i++) { System.out.print(" "); } } else { for(int i=0; i < indent; i++) { System.out.print(" "); } } Object lval2 = s.value(); System.out.print("tok: " + TokenScanner.tnames[tok]); if(lval != lval2) { System.out.print(" lval: " + lval2); lval = lval2; } System.out.println(); } } } yecht-yecht-1.1/src/main/org/yecht/debug/TimeImplicit.java000066400000000000000000000013021262256356000235440ustar00rootroot00000000000000package org.yecht.debug; import java.io.InputStream; import java.io.FileInputStream; import org.yecht.*; public class TimeImplicit { public static void main(String[] args) throws Exception { Pointer ptr = Pointer.create("one little thing"); Pointer ptr2 = Pointer.create("13455"); int times = 10000000; long before = System.currentTimeMillis(); for(int i=0; i= len) { len *= 2; input = YAML.realloc(input, len); } System.arraycopy(buffer, 0, input, read, currRead); read += currRead; } int times = 10000; long before = System.currentTimeMillis(); for(int i=0; i= len) { len *= 2; input = YAML.realloc(input, len); } System.arraycopy(buffer, 0, input, read, currRead); read += currRead; } int times = 10000; long before = System.currentTimeMillis(); for(int i=0; i