github.com/hirochachacha/plua@v0.0.0-20170217012138-c82f520cc725/compiler/ast/printer/example_test.go (about)

     1  package printer_test
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/hirochachacha/plua/compiler/ast/printer"
     7  	"github.com/hirochachacha/plua/compiler/parser"
     8  )
     9  
    10  func ExampleFprint() {
    11  	ast, err := parser.ParseFile("testdata/example.lua", parser.ParseComments)
    12  	if err != nil {
    13  		panic(err)
    14  	}
    15  
    16  	printer.Fprint(os.Stdout, ast)
    17  
    18  	// Output:
    19  	// if true then -- comment1
    20  	//   print("x")    -- comment2
    21  	//   print("yyyy") -- comment3
    22  	// elseif true then -- comment4
    23  	//   print("y")        -- comment5
    24  	//   print("xxxxxxxx") -- comment6
    25  	// else -- comment7
    26  	//   -- comment8
    27  	//   -- comment9
    28  	//   print("xxxx") -- comment 10
    29  	//   print("xx")   -- comment 11
    30  	// end
    31  	//
    32  	// -- fake
    33  	// -- art
    34  	// --[[
    35  	//  fake
    36  	//  man
    37  	//  ]]
    38  	//
    39  	// -- TODO
    40  	// -- x = 1 + -- bar
    41  	// -- 4 + 9 -- foo
    42  	// -- + 10 -- baz
    43  	//
    44  	// x = x + 5*9 - 10/5 - (-5)
    45  	// x = x + (5-1+9)*6
    46  	// x = 1-(-5), 9
    47  	//
    48  	// if (x ~= 10) == true then
    49  	//   print(x)
    50  	// end
    51  	//
    52  	// print("hello" .. "world")
    53  	// print("hello".."world", "hello".."world")
    54  	// print(1 + 7)
    55  	// print(1+7, 1+8)
    56  	//
    57  	// y = foo[x+5] + 8
    58  	//
    59  	// t = {[5+9] = y, 11}
    60  	//
    61  	// local foo
    62  	//
    63  	// x = 10; y = 24
    64  	//
    65  	// t = { --xxx
    66  	//   1,        -- foo
    67  	//   81111111, -- bar
    68  	// } -- aaa
    69  	//
    70  	// t =
    71  	//   {
    72  	//     11111,
    73  	//     [5] = 011,
    74  	//   }
    75  	//
    76  	// t = {
    77  	//   x = {
    78  	//     y =
    79  	//       {
    80  	//         z = 9,
    81  	//       },
    82  	//   },
    83  	// }
    84  	//
    85  	// x {
    86  	// }
    87  	//
    88  	// print('\'test')
    89  	//
    90  	// foo = "5"..1 > "21"
    91  	//
    92  	// fn({
    93  	//   1,
    94  	//   9,
    95  	// })
    96  	//
    97  	// fn(function()
    98  	//   return 1
    99  	// end)
   100  	//
   101  	// return (x) + 1
   102  }