github.com/elves/Elvish@v0.12.0/parse/boilerplate.go (about)

     1  package parse
     2  
     3  func IsChunk(n Node) bool {
     4  	_, ok := n.(*Chunk)
     5  	return ok
     6  }
     7  
     8  func GetChunk(n Node) *Chunk {
     9  	if nn, ok := n.(*Chunk); ok {
    10  		return nn
    11  	}
    12  	return nil
    13  }
    14  
    15  func (n *Chunk) addToPipelines(ch *Pipeline) {
    16  	n.Pipelines = append(n.Pipelines, ch)
    17  	addChild(n, ch)
    18  }
    19  
    20  func ParseChunk(ps *Parser) *Chunk {
    21  	n := &Chunk{node: node{begin: ps.pos}}
    22  	n.parse(ps)
    23  	n.end = ps.pos
    24  	n.sourceText = ps.src[n.begin:n.end]
    25  	return n
    26  }
    27  
    28  func IsPipeline(n Node) bool {
    29  	_, ok := n.(*Pipeline)
    30  	return ok
    31  }
    32  
    33  func GetPipeline(n Node) *Pipeline {
    34  	if nn, ok := n.(*Pipeline); ok {
    35  		return nn
    36  	}
    37  	return nil
    38  }
    39  
    40  func (n *Pipeline) addToForms(ch *Form) {
    41  	n.Forms = append(n.Forms, ch)
    42  	addChild(n, ch)
    43  }
    44  
    45  func ParsePipeline(ps *Parser) *Pipeline {
    46  	n := &Pipeline{node: node{begin: ps.pos}}
    47  	n.parse(ps)
    48  	n.end = ps.pos
    49  	n.sourceText = ps.src[n.begin:n.end]
    50  	return n
    51  }
    52  
    53  func IsForm(n Node) bool {
    54  	_, ok := n.(*Form)
    55  	return ok
    56  }
    57  
    58  func GetForm(n Node) *Form {
    59  	if nn, ok := n.(*Form); ok {
    60  		return nn
    61  	}
    62  	return nil
    63  }
    64  
    65  func (n *Form) addToAssignments(ch *Assignment) {
    66  	n.Assignments = append(n.Assignments, ch)
    67  	addChild(n, ch)
    68  }
    69  
    70  func (n *Form) setHead(ch *Compound) {
    71  	n.Head = ch
    72  	addChild(n, ch)
    73  }
    74  
    75  func (n *Form) addToVars(ch *Compound) {
    76  	n.Vars = append(n.Vars, ch)
    77  	addChild(n, ch)
    78  }
    79  
    80  func (n *Form) addToArgs(ch *Compound) {
    81  	n.Args = append(n.Args, ch)
    82  	addChild(n, ch)
    83  }
    84  
    85  func (n *Form) addToOpts(ch *MapPair) {
    86  	n.Opts = append(n.Opts, ch)
    87  	addChild(n, ch)
    88  }
    89  
    90  func (n *Form) addToRedirs(ch *Redir) {
    91  	n.Redirs = append(n.Redirs, ch)
    92  	addChild(n, ch)
    93  }
    94  
    95  func (n *Form) setExitusRedir(ch *ExitusRedir) {
    96  	n.ExitusRedir = ch
    97  	addChild(n, ch)
    98  }
    99  
   100  func ParseForm(ps *Parser) *Form {
   101  	n := &Form{node: node{begin: ps.pos}}
   102  	n.parse(ps)
   103  	n.end = ps.pos
   104  	n.sourceText = ps.src[n.begin:n.end]
   105  	return n
   106  }
   107  
   108  func IsAssignment(n Node) bool {
   109  	_, ok := n.(*Assignment)
   110  	return ok
   111  }
   112  
   113  func GetAssignment(n Node) *Assignment {
   114  	if nn, ok := n.(*Assignment); ok {
   115  		return nn
   116  	}
   117  	return nil
   118  }
   119  
   120  func (n *Assignment) setLeft(ch *Indexing) {
   121  	n.Left = ch
   122  	addChild(n, ch)
   123  }
   124  
   125  func (n *Assignment) setRight(ch *Compound) {
   126  	n.Right = ch
   127  	addChild(n, ch)
   128  }
   129  
   130  func ParseAssignment(ps *Parser) *Assignment {
   131  	n := &Assignment{node: node{begin: ps.pos}}
   132  	n.parse(ps)
   133  	n.end = ps.pos
   134  	n.sourceText = ps.src[n.begin:n.end]
   135  	return n
   136  }
   137  
   138  func IsExitusRedir(n Node) bool {
   139  	_, ok := n.(*ExitusRedir)
   140  	return ok
   141  }
   142  
   143  func GetExitusRedir(n Node) *ExitusRedir {
   144  	if nn, ok := n.(*ExitusRedir); ok {
   145  		return nn
   146  	}
   147  	return nil
   148  }
   149  
   150  func (n *ExitusRedir) setDest(ch *Compound) {
   151  	n.Dest = ch
   152  	addChild(n, ch)
   153  }
   154  
   155  func ParseExitusRedir(ps *Parser) *ExitusRedir {
   156  	n := &ExitusRedir{node: node{begin: ps.pos}}
   157  	n.parse(ps)
   158  	n.end = ps.pos
   159  	n.sourceText = ps.src[n.begin:n.end]
   160  	return n
   161  }
   162  
   163  func IsRedir(n Node) bool {
   164  	_, ok := n.(*Redir)
   165  	return ok
   166  }
   167  
   168  func GetRedir(n Node) *Redir {
   169  	if nn, ok := n.(*Redir); ok {
   170  		return nn
   171  	}
   172  	return nil
   173  }
   174  
   175  func (n *Redir) setLeft(ch *Compound) {
   176  	n.Left = ch
   177  	addChild(n, ch)
   178  }
   179  
   180  func (n *Redir) setRight(ch *Compound) {
   181  	n.Right = ch
   182  	addChild(n, ch)
   183  }
   184  
   185  func ParseRedir(ps *Parser, dest *Compound) *Redir {
   186  	n := &Redir{node: node{begin: ps.pos}}
   187  	n.parse(ps, dest)
   188  	n.end = ps.pos
   189  	n.sourceText = ps.src[n.begin:n.end]
   190  	return n
   191  }
   192  
   193  func IsCompound(n Node) bool {
   194  	_, ok := n.(*Compound)
   195  	return ok
   196  }
   197  
   198  func GetCompound(n Node) *Compound {
   199  	if nn, ok := n.(*Compound); ok {
   200  		return nn
   201  	}
   202  	return nil
   203  }
   204  
   205  func (n *Compound) addToIndexings(ch *Indexing) {
   206  	n.Indexings = append(n.Indexings, ch)
   207  	addChild(n, ch)
   208  }
   209  
   210  func ParseCompound(ps *Parser, ctx ExprCtx) *Compound {
   211  	n := &Compound{node: node{begin: ps.pos}}
   212  	n.parse(ps, ctx)
   213  	n.end = ps.pos
   214  	n.sourceText = ps.src[n.begin:n.end]
   215  	return n
   216  }
   217  
   218  func IsIndexing(n Node) bool {
   219  	_, ok := n.(*Indexing)
   220  	return ok
   221  }
   222  
   223  func GetIndexing(n Node) *Indexing {
   224  	if nn, ok := n.(*Indexing); ok {
   225  		return nn
   226  	}
   227  	return nil
   228  }
   229  
   230  func (n *Indexing) setHead(ch *Primary) {
   231  	n.Head = ch
   232  	addChild(n, ch)
   233  }
   234  
   235  func (n *Indexing) addToIndicies(ch *Array) {
   236  	n.Indicies = append(n.Indicies, ch)
   237  	addChild(n, ch)
   238  }
   239  
   240  func ParseIndexing(ps *Parser, ctx ExprCtx) *Indexing {
   241  	n := &Indexing{node: node{begin: ps.pos}}
   242  	n.parse(ps, ctx)
   243  	n.end = ps.pos
   244  	n.sourceText = ps.src[n.begin:n.end]
   245  	return n
   246  }
   247  
   248  func IsArray(n Node) bool {
   249  	_, ok := n.(*Array)
   250  	return ok
   251  }
   252  
   253  func GetArray(n Node) *Array {
   254  	if nn, ok := n.(*Array); ok {
   255  		return nn
   256  	}
   257  	return nil
   258  }
   259  
   260  func (n *Array) addToCompounds(ch *Compound) {
   261  	n.Compounds = append(n.Compounds, ch)
   262  	addChild(n, ch)
   263  }
   264  
   265  func ParseArray(ps *Parser, allowSemicolon bool) *Array {
   266  	n := &Array{node: node{begin: ps.pos}}
   267  	n.parse(ps, allowSemicolon)
   268  	n.end = ps.pos
   269  	n.sourceText = ps.src[n.begin:n.end]
   270  	return n
   271  }
   272  
   273  func IsPrimary(n Node) bool {
   274  	_, ok := n.(*Primary)
   275  	return ok
   276  }
   277  
   278  func GetPrimary(n Node) *Primary {
   279  	if nn, ok := n.(*Primary); ok {
   280  		return nn
   281  	}
   282  	return nil
   283  }
   284  
   285  func (n *Primary) addToElements(ch *Compound) {
   286  	n.Elements = append(n.Elements, ch)
   287  	addChild(n, ch)
   288  }
   289  
   290  func (n *Primary) setChunk(ch *Chunk) {
   291  	n.Chunk = ch
   292  	addChild(n, ch)
   293  }
   294  
   295  func (n *Primary) addToMapPairs(ch *MapPair) {
   296  	n.MapPairs = append(n.MapPairs, ch)
   297  	addChild(n, ch)
   298  }
   299  
   300  func (n *Primary) addToBraced(ch *Compound) {
   301  	n.Braced = append(n.Braced, ch)
   302  	addChild(n, ch)
   303  }
   304  
   305  func ParsePrimary(ps *Parser, ctx ExprCtx) *Primary {
   306  	n := &Primary{node: node{begin: ps.pos}}
   307  	n.parse(ps, ctx)
   308  	n.end = ps.pos
   309  	n.sourceText = ps.src[n.begin:n.end]
   310  	return n
   311  }
   312  
   313  func IsMapPair(n Node) bool {
   314  	_, ok := n.(*MapPair)
   315  	return ok
   316  }
   317  
   318  func GetMapPair(n Node) *MapPair {
   319  	if nn, ok := n.(*MapPair); ok {
   320  		return nn
   321  	}
   322  	return nil
   323  }
   324  
   325  func (n *MapPair) setKey(ch *Compound) {
   326  	n.Key = ch
   327  	addChild(n, ch)
   328  }
   329  
   330  func (n *MapPair) setValue(ch *Compound) {
   331  	n.Value = ch
   332  	addChild(n, ch)
   333  }
   334  
   335  func ParseMapPair(ps *Parser) *MapPair {
   336  	n := &MapPair{node: node{begin: ps.pos}}
   337  	n.parse(ps)
   338  	n.end = ps.pos
   339  	n.sourceText = ps.src[n.begin:n.end]
   340  	return n
   341  }
   342  
   343  func IsSep(n Node) bool {
   344  	_, ok := n.(*Sep)
   345  	return ok
   346  }
   347  
   348  func GetSep(n Node) *Sep {
   349  	if nn, ok := n.(*Sep); ok {
   350  		return nn
   351  	}
   352  	return nil
   353  }