mewmew / uc

A compiler for the µC language.
58 stars 5 forks source link

parser: Node representation #48

Closed mewmew closed 8 years ago

mewmew commented 8 years ago

The current Node representation is defined as follows.

type Node interface {
    // Start returns the start position of the node within the input stream.
    Start() int
    // End returns the first character immediately after the node within the input
    // stream.
    End() int
}

The start position of a token is useful for error reporting (e.g. error at line:col, expected identifier got ";"), while the end position is useful for tools operating on the original input such as refactoring tools, which may reposition nodes (as defined by their start-end ranges) within the input.

For now, the main use of positional information will be for error reporting. Therefore, information about the end position of tokens is not recorded. This may be revisited in the future, once there are potential users who may benefit from having access to the end position of tokens.

mewmew commented 8 years ago

Closing for now, having settled for the minimal Node representation needed for good error reporting.

type Node interface {
    // Start returns the start position of the node within the input stream.
    Start() int
}