Guest User

Untitled

a guest
Oct 23rd, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 2.27 KB | None | 0 0
  1. use v6;
  2.  
  3. use NativeCall;
  4.  
  5. module Gumbo {
  6.   class gumbo_node_t is repr('CPointer') {};
  7.   class gumbo_output_t is repr('CPointer') {};
  8.   class gumbo_vector_t is repr('CPointer') {};
  9.  
  10. #    typedef struct {
  11. #      void** data;
  12. #    
  13. #      unsigned int length;
  14. #    
  15. #      unsigned int capacity;
  16. #    } GumboVector;
  17.  
  18.   class gumbo_vector_s is repr('CStruct') {
  19.     has OpaquePointer $.data;
  20.     has uint          $.length;
  21.     has uint          $.capacity;
  22.   }
  23.  
  24. #   typedef struct GumboInternalOutput {
  25. #      GumboNode* document;
  26. #    
  27. #      GumboNode* root;
  28. #    
  29. #      GumboVector /* GumboError */ errors;
  30. #    } GumboOutput;
  31. #  
  32.   class gumbo_output_s is repr('CStruct') {
  33.     has gumbo_node_t $.document;
  34.     has gumbo_node_t $.root;
  35.     has gumbo_vector_s $.errors;
  36.   }
  37.  
  38.   #typedef struct {
  39.   #   GumboVector /* GumboNode* */ children;
  40.   #
  41.   #   // True if there was an explicit doctype token as opposed to it being omitted.
  42. #      bool has_doctype;
  43. #    
  44. #      // Fields from the doctype token, copied verbatim.
  45. #      const char* name;
  46. #      const char* public_identifier;
  47. #      const char* system_identifier;
  48. #    
  49. #      GumboQuirksModeEnum doc_type_quirks_mode;
  50. #    } GumboDocument;
  51. #  
  52.   class gumbo_document_s is repr('CStruct') {
  53.      has gumbo_vector_s $.children;
  54.      has int8       $.has_doctype;
  55.      has str        $.name;
  56.      has str        $.public_identifier;
  57.      has str        $.system_identifier;
  58.      has int        $.doc_type_quirks_mode;
  59.   }
  60.  
  61.   sub gumbo_parse(Str) is native('libgumbo') returns gumbo_output_t { * }
  62.  
  63.  
  64.  
  65.   sub parse-html (Str $html) is export {
  66.     my gumbo_output_t $gumbo_output = gumbo_parse($html);
  67.     say nativesizeof(gumbo_output_s);
  68.     say nativesizeof(gumbo_vector_s);
  69.     say nativesizeof(OpaquePointer);
  70.     my gumbo_output_s $go = nativecast(gumbo_output_s, $gumbo_output);
  71.     say $go.perl;
  72.     #say $go.root.perl;
  73.     #my gumbo_vector_s $vec = $go.errors;
  74.     #say $vec.perl;
  75.   }
  76.  
  77. }
  78.  
  79. (gumbo.pl call parse-html("<html><head><title>piko</title></html>");)
  80. root@testperl6:~/piko# perl6 gumbo.pl
  81. 12
  82. 20
  83. 4
  84. gumbo_output_s.new(document => gumbo_node_t.new, root => gumbo_node_t.new, errors => gumbo_vector_s.new(data => Pointer.new(224520520), length => 692114188733142712, capacity => 103240360544))
Advertisement
Add Comment
Please, Sign In to add comment