Documentation
¶
Index ¶
- Variables
- func ExtractExpectedStructure(stream *lexer.TokenStream, dest *[]*lexer.Token, exp *Expectation) error
- func ExtractOneOfExpectedStructure(stream *lexer.TokenStream, dest *[]*lexer.Token, exps *OneOfExpectations) error
- func TokenizeAll(data []byte) ([]*lexer.Token, error)
- type Expectation
- type ExpectationEntry
- type Extractable
- type ExtractionError
- type OneOfExpectations
- type Relocator
- type Statement
- type StatementKind
Constants ¶
This section is empty.
Variables ¶
var (
ErrExpectedLineEnd = fmt.Errorf("expected line end")
)
Functions ¶
func ExtractExpectedStructure ¶
func ExtractExpectedStructure(stream *lexer.TokenStream, dest *[]*lexer.Token, exp *Expectation) error
ExtractExpectedStructure attempts to extract a subset of Tokens from a TokenStream, storing the results in dest. dest must have a capacity large enough to store all the expected tokens.
Because append is used, dest MUST NOT need to grow.
func ExtractOneOfExpectedStructure ¶
func ExtractOneOfExpectedStructure(stream *lexer.TokenStream, dest *[]*lexer.Token, exps *OneOfExpectations) error
ExtractOneOfExpectedStructure functions similar to ExtractExpectedStructure, but instead extracts the first matching expectation from OneOfExpectations.
Types ¶
type Expectation ¶
type Expectation struct {
// contains filtered or unexported fields
}
Expectation is an aggregate of ExpectationEntries that matches multiple expected Tokens.
func NewExpectation ¶
func NewExpectation(description string, entries ...ExpectationEntry) *Expectation
func (*Expectation) Description ¶
func (e *Expectation) Description() string
func (*Expectation) Extract ¶
func (e *Expectation) Extract(stream *lexer.TokenStream, dest *[]*lexer.Token) error
func (*Expectation) ExtractionCount ¶
func (e *Expectation) ExtractionCount() int
ExtractionCount returns the number of captured (e.g. not ignored) Tokens that its pattern describes
type ExpectationEntry ¶
type ExpectationEntry interface { Matches(kind lexer.TokenKind) bool Keep() bool Describe() string }
ExpectationEntry describes a possible token expectation that can be matched within stream of many Tokens.
func Expect ¶
func Expect(kind lexer.TokenKind) ExpectationEntry
Expect returns an ExpectationEntry that captures an expected TokenKind
func ExpectAny ¶
func ExpectAny(kinds ...lexer.TokenKind) ExpectationEntry
ExpectAny returns an ExpectationEntry that captures one of any given TokenKind
func ExpectAnyIgnore ¶
func ExpectAnyIgnore(kinds ...lexer.TokenKind) ExpectationEntry
ExpectAnyIgnore returns an ExpectationEntry that expects but ignores one of any given TokenKind
func ExpectIgnore ¶
func ExpectIgnore(kind lexer.TokenKind) ExpectationEntry
ExpectIgnore returns an ExpectationEntry that expects but ignores a TokenKind
type Extractable ¶
type ExtractionError ¶
type ExtractionError struct {
// contains filtered or unexported fields
}
func (*ExtractionError) Error ¶
func (ee *ExtractionError) Error() string
type OneOfExpectations ¶
type OneOfExpectations struct {
// contains filtered or unexported fields
}
func OneOf ¶
func OneOf(expectations ...*Expectation) *OneOfExpectations
func (*OneOfExpectations) Description ¶
func (o *OneOfExpectations) Description() string
func (*OneOfExpectations) Extract ¶
func (o *OneOfExpectations) Extract(stream *lexer.TokenStream, dest *[]*lexer.Token) error
func (*OneOfExpectations) ExtractionCount ¶
func (o *OneOfExpectations) ExtractionCount() int
type Statement ¶
type Statement struct { Body []*lexer.Token Kind StatementKind }
Statement is the most basic element of an Orange assembly program.
It can describe:
- An instruction (e.g. ADD r3, r2, r1)
- A directive (e.g. a label declaration)
func ParseTokens ¶
ParseTokens aggregates tokens from the input stream into statements.
We make the following classification of all complete statements within Orange assembly:
All (meaningful) tokens belong to one of two types:
- Instructions
- Directives
Thus, we will iterate over the input token stream and aggregate each token to a specific instruction or directive.
For example, given the input token stream state of
[MOVZ, REGISTER, COMMA, BASE_10_IMM, COMMENT, LINE_END, ...]
We will extract MOVZ, inspect the token, determine that the instruction should contain a register and an immediate, and remove them from the stream.
The LINE_END token is used to enforce assembly programs to have each instruction on a separate line. This is not a limitation of the parsing, but a deliberate design choice. Therefore, we must reach a LINE_END token before beginning parsing of another Statement.
type StatementKind ¶
type StatementKind uint8
const ( InstructionStatement StatementKind = iota DirectiveStatement )