import "go/printer"

Overview

Index

Examples

概观

Package printer实现了AST节点的打印。

索引

func Fprint(output io.Writer, fset *token.FileSet, node interface{}) error

type CommentedNode

type Config

func (cfg *Config) Fprint(output io.Writer, fset *token.FileSet, node interface{}) error

type Mode

例子

Fprint

包文件

nodes.go printer.go

func Fprint

func Fprint(output io.Writer, fset *token.FileSet, node interface{}) error

Fprint“漂亮地”输出一个AST节点。它使用默认设置调用Config.Fprint。请注意,gofmt使用制表符缩进但使用空格对齐; 使用format.Node(包go /格式)来匹配gofmt的输出。

例子

代码:

// Parse source file and extract the AST without comments for// this function, with position information referring to the// file set fset.funcAST, fset := parseFunc("example_test.go", "ExampleFprint")// Print the function body into buffer buf.// The file set is provided to the printer so that it knows// about the original source formatting and can add additional// line breaks where they were present in the source.var buf bytes.Buffer

printer.Fprint(&buf, fset, funcAST.Body)// Remove braces {} enclosing the function body, unindent,// and trim leading and trailing white space.s := buf.String()s = s[1 : len(s)-1]s = strings.TrimSpace(strings.Replace(s, "\n\t", "\n", -1))// Print the cleaned-up body text to stdout.fmt.Println(s)

输出:

funcAST, fset := parseFunc("example_test.go", "ExampleFprint")var buf bytes.Buffer

printer.Fprint(&buf, fset, funcAST.Body)s := buf.String()s = s[1 : len(s)-1]s = strings.TrimSpace(strings.Replace(s, "\n\t", "\n", -1))fmt.Println(s)

type CommentedNode

CommentedNode捆绑了一个AST节点和相应的注释。它可以作为任何Fprint函数的参数提供。

type CommentedNode struct {

Node     interface{} // *ast.File, or ast.Expr, ast.Decl, ast.Spec, or ast.Stmt

Comments []*ast.CommentGroup}

type Config

Config节点控制Fprint的输出。

type Config struct {

Mode     Mode // default: 0

Tabwidth int  // default: 8

Indent   int  // default: 0 (all code is indented at least by this much)}

func (*Config) Fprint

func (cfg *Config) Fprint(output io.Writer, fset *token.FileSet, node interface{}) error

Fprint“漂亮地打印”AST节点以输出给定的配置cfg。位置信息相对于文件集fset进行解释。节点类型必须为ast.Expr,ast.Decl,ast.Spec或ast.Stmt的* ast.File,* CommentedNode,[] ast.Decl,[] ast.Stmt或赋值兼容。

type Mode

Mode值是一组标志(或0)。他们控制打印。

type Mode uint

const (

RawFormat Mode = 1 <

TabIndent                  // use tabs for indentation independent of UseSpaces

UseSpaces                  // use spaces instead of tabs for alignment

SourcePos                  // emit //line directives to preserve original source positions)

php printer使用手册,go/printer相关推荐

  1. 关于在nw里使用require('printer')和nw.require('printer')报错的问题

    公司项目为了兼容xp所以使用nw.js(0.14.7-sdk),用到了printer模块(第三方的c++打印模块),在引入该模块的时候,使用了require导致一直报cannot find modul ...

  2. php printer.dll扩展,php printer.dll下载

    php_printer.dll是一种win系统中非常重要的dll文件,许多的游戏或者软件运行都需要它的支持,特别是php的环境中.如果说你的计算机显示"计算机丢失php_printer.dl ...

  3. SQL-10-14 4-4 查询具有最高价格的机器的型号,机器包括PC、Laptop、Printer (10分)

    有2张表,为父子关系表: 1 Employee 表 id Name Age 1 张三 31 2 李四 28 3 王五 40 - 2 Wages 表 Emp_id | 工资项目 | 工资金额 | 1 | ...

  4. VB Printer对象

    VB Printer对象 2011-04-29 22:54:37|  分类: 编程设计 |字号 订阅 ===========Printer 的属性========== ■■■一般属性,与窗体属性同 ▲ ...

  5. Java 定义一个抽象的打印机类Printer,定义一个抽象类和具体的子类。

    定义一个抽象的打印机类Printer 有属性color,有抽象方法Print()方法:定义一个其具体的ColorPrinter子类,实现Print(),当color属性为"彩色", ...

  6. [导入][转]sap学习手册二

    SAP学习手册二 作者:sunxufeng 有没有调整IDES4.6的中文包参数的步骤呢? 在导入中文包后直接手工修改有关参数,不要用CZ10去修改假定为D盘,路径为D:usrsapC11syspro ...

  7. SAP. T-Code: su01用户维护 sap学习手册I

    1 Basis 1. Unix操作 更改口令 passwd eg. passwd orap34看当前路径 pwd 看sap或者oracle的进程 eg. ps -ef|grep sap或者 ora看命 ...

  8. 【转】SAP学习手册

    SAP学习手册 发表人:sunxufeng | 发表时间: 2006年三月27日, 17:20 有没有调整IDES4.6的中文包参数的步骤呢? 在导入中文包后直接手工修改有关参数,不要用CZ10去修改 ...

  9. [轉]SAP学习手册I

    1 Basis 1. Unix操作 更改口令 passwd eg. passwd orap34看当前路径 pwd 看sap或者oracle的进程 eg. ps -ef|grep sap或者 ora看命 ...

最新文章

  1. cisco配置静态NAT
  2. R语言ggplot2可视化时避免geom_bar对x轴进行排序实战:直接对因子变量进行提前排序后再进行可视化、使用scale_x_discrete函数限定因子顺序
  3. 为Android运行新的英特尔模拟器
  4. Linux最大线程数限制及当前线程数查询
  5. Java在远程方法调用中运用反射机制
  6. 微信又上线新功能,能让你更会聊天?
  7. Java学习笔记十:Java的数组以及操作数组
  8. linux matplotlib 中文显示乱码
  9. serv-u+win2008R2+cutFtp配置
  10. vs2010最佳配色选择_2010年代35部最佳电影
  11. ajax返回String类型导致的flowplayer报错p.replace is not a function问题
  12. 基于易班开放平台接入研究与探索
  13. 快来带您了解中秋节的前世今生
  14. Chaosblade 混动工程之网络延迟实践
  15. HISI3559A 使用yolov3 (VI-VPSS-VO)实时目标检测
  16. c++算法基础必刷题目——前缀和与差分
  17. Dell optiPlex麦克风显示未插入问题解决
  18. the Graph子图部署(使用Hosted Service)
  19. Azure Synapse Analytics (Azure SQL DW)性能优化指南(4)——使用结果集缓存优化性能
  20. 电脑无法显示移动硬盘文件内容的解决方法

热门文章

  1. vue3中reactive赋值失败
  2. 长生生物事件的反思:质量是生命
  3. 数码宝贝相遇服务器维修中,数码宝贝相遇修炼岛速刷心得及掉落汇总
  4. java的网络协议学习_协议简史:如何学习网络协议?
  5. 简书PC端私密文章放在哪?
  6. VoIP通话-基于SIP协议的Asterisk(零)-Demo
  7. 转200条装修小常识
  8. Intel® 64 and IA-32 Architectures Software Developer's Manual CHPTER 8 Multiple-processor management
  9. 中级工程师职称有什么作用?有含金量吗?为什么要办?甘建二
  10. 琢石成器之自动化去广告神器