Privated parsingOperation
This commit is contained in:
parent
89b432c6fd
commit
b92a3dcba3
@ -16,7 +16,7 @@ var validArgumentStartTokens = []lexer.TokenKind {
|
|||||||
lexer.TokenKindLParen,
|
lexer.TokenKindLParen,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (parser *ParsingOperation) parseArgument () (argument Argument, err error) {
|
func (parser *parsingOperation) parseArgument () (argument Argument, err error) {
|
||||||
argument.location = parser.token.Location()
|
argument.location = parser.token.Location()
|
||||||
|
|
||||||
err = parser.expect(validArgumentStartTokens...)
|
err = parser.expect(validArgumentStartTokens...)
|
||||||
|
@ -4,7 +4,7 @@ import "git.tebibyte.media/arf/arf/lexer"
|
|||||||
import "git.tebibyte.media/arf/arf/infoerr"
|
import "git.tebibyte.media/arf/arf/infoerr"
|
||||||
|
|
||||||
// parse body parses the body of an arf file, after the metadata header.
|
// parse body parses the body of an arf file, after the metadata header.
|
||||||
func (parser *ParsingOperation) parseBody () (err error) {
|
func (parser *parsingOperation) parseBody () (err error) {
|
||||||
for {
|
for {
|
||||||
err = parser.expect(lexer.TokenKindName)
|
err = parser.expect(lexer.TokenKindName)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
@ -4,7 +4,7 @@ import "git.tebibyte.media/arf/arf/types"
|
|||||||
import "git.tebibyte.media/arf/arf/lexer"
|
import "git.tebibyte.media/arf/arf/lexer"
|
||||||
|
|
||||||
// parseData parses a data section.
|
// parseData parses a data section.
|
||||||
func (parser *ParsingOperation) parseDataSection () (
|
func (parser *parsingOperation) parseDataSection () (
|
||||||
section DataSection,
|
section DataSection,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
|
@ -2,7 +2,7 @@ package parser
|
|||||||
|
|
||||||
import "git.tebibyte.media/arf/arf/lexer"
|
import "git.tebibyte.media/arf/arf/lexer"
|
||||||
|
|
||||||
func (parser *ParsingOperation) parseDereference () (
|
func (parser *parsingOperation) parseDereference () (
|
||||||
dereference Dereference,
|
dereference Dereference,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
|
@ -5,7 +5,7 @@ import "git.tebibyte.media/arf/arf/lexer"
|
|||||||
import "git.tebibyte.media/arf/arf/infoerr"
|
import "git.tebibyte.media/arf/arf/infoerr"
|
||||||
|
|
||||||
// parseEnumSection parses an enumerated type section.
|
// parseEnumSection parses an enumerated type section.
|
||||||
func (parser *ParsingOperation) parseEnumSection () (
|
func (parser *parsingOperation) parseEnumSection () (
|
||||||
section EnumSection,
|
section EnumSection,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
@ -51,7 +51,7 @@ func (parser *ParsingOperation) parseEnumSection () (
|
|||||||
|
|
||||||
// parseEnumMembers parses a list of members for an enum section. Indentation
|
// parseEnumMembers parses a list of members for an enum section. Indentation
|
||||||
// level is assumed.
|
// level is assumed.
|
||||||
func (parser *ParsingOperation) parseEnumMembers (
|
func (parser *parsingOperation) parseEnumMembers (
|
||||||
into *EnumSection,
|
into *EnumSection,
|
||||||
) (
|
) (
|
||||||
err error,
|
err error,
|
||||||
@ -70,7 +70,7 @@ func (parser *ParsingOperation) parseEnumMembers (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parseEnumMember parses a single enum member. Indenttion level is assumed.
|
// parseEnumMember parses a single enum member. Indenttion level is assumed.
|
||||||
func (parser *ParsingOperation) parseEnumMember () (
|
func (parser *parsingOperation) parseEnumMember () (
|
||||||
member EnumMember,
|
member EnumMember,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
|
@ -5,7 +5,7 @@ import "git.tebibyte.media/arf/arf/lexer"
|
|||||||
import "git.tebibyte.media/arf/arf/infoerr"
|
import "git.tebibyte.media/arf/arf/infoerr"
|
||||||
|
|
||||||
// parseFaceSection parses an interface section.
|
// parseFaceSection parses an interface section.
|
||||||
func (parser *ParsingOperation) parseFaceSection () (
|
func (parser *parsingOperation) parseFaceSection () (
|
||||||
section FaceSection,
|
section FaceSection,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
@ -65,7 +65,7 @@ func (parser *ParsingOperation) parseFaceSection () (
|
|||||||
|
|
||||||
// parseFaceBehaviors parses a list of interface behaviors for an object
|
// parseFaceBehaviors parses a list of interface behaviors for an object
|
||||||
// interface.
|
// interface.
|
||||||
func (parser *ParsingOperation) parseFaceBehaviors () (
|
func (parser *parsingOperation) parseFaceBehaviors () (
|
||||||
behaviors map[string] FaceBehavior,
|
behaviors map[string] FaceBehavior,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
@ -101,7 +101,7 @@ func (parser *ParsingOperation) parseFaceBehaviors () (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parseFaceBehavior parses a single interface behavior.
|
// parseFaceBehavior parses a single interface behavior.
|
||||||
func (parser *ParsingOperation) parseFaceBehavior (
|
func (parser *parsingOperation) parseFaceBehavior (
|
||||||
indent int,
|
indent int,
|
||||||
) (
|
) (
|
||||||
behavior FaceBehavior,
|
behavior FaceBehavior,
|
||||||
@ -125,7 +125,7 @@ func (parser *ParsingOperation) parseFaceBehavior (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (parser *ParsingOperation) parseFaceBehaviorArguments (
|
func (parser *parsingOperation) parseFaceBehaviorArguments (
|
||||||
indent int,
|
indent int,
|
||||||
) (
|
) (
|
||||||
inputs []Declaration,
|
inputs []Declaration,
|
||||||
|
@ -5,7 +5,7 @@ import "git.tebibyte.media/arf/arf/lexer"
|
|||||||
import "git.tebibyte.media/arf/arf/infoerr"
|
import "git.tebibyte.media/arf/arf/infoerr"
|
||||||
|
|
||||||
// parseFunc parses a function section.
|
// parseFunc parses a function section.
|
||||||
func (parser *ParsingOperation) parseFuncSection () (
|
func (parser *parsingOperation) parseFuncSection () (
|
||||||
section FuncSection,
|
section FuncSection,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
@ -75,7 +75,7 @@ func (parser *ParsingOperation) parseFuncSection () (
|
|||||||
|
|
||||||
// parseFuncArguments parses a function's inputs, outputs, and reciever if that
|
// parseFuncArguments parses a function's inputs, outputs, and reciever if that
|
||||||
// exists.
|
// exists.
|
||||||
func (parser *ParsingOperation) parseFuncArguments (
|
func (parser *parsingOperation) parseFuncArguments (
|
||||||
into *FuncSection,
|
into *FuncSection,
|
||||||
) (
|
) (
|
||||||
err error,
|
err error,
|
||||||
|
@ -3,7 +3,7 @@ package parser
|
|||||||
import "git.tebibyte.media/arf/arf/lexer"
|
import "git.tebibyte.media/arf/arf/lexer"
|
||||||
|
|
||||||
// parseList parses a parenthetically delimited list of arguments.
|
// parseList parses a parenthetically delimited list of arguments.
|
||||||
func (parser *ParsingOperation) parseList () (list List, err error) {
|
func (parser *parsingOperation) parseList () (list List, err error) {
|
||||||
list.location = parser.token.Location()
|
list.location = parser.token.Location()
|
||||||
|
|
||||||
err = parser.expect(lexer.TokenKindLParen)
|
err = parser.expect(lexer.TokenKindLParen)
|
||||||
|
@ -6,7 +6,7 @@ import "git.tebibyte.media/arf/arf/lexer"
|
|||||||
import "git.tebibyte.media/arf/arf/infoerr"
|
import "git.tebibyte.media/arf/arf/infoerr"
|
||||||
|
|
||||||
// parseMeta parsese the metadata header at the top of an arf file.
|
// parseMeta parsese the metadata header at the top of an arf file.
|
||||||
func (parser *ParsingOperation) parseMeta () (err error) {
|
func (parser *parsingOperation) parseMeta () (err error) {
|
||||||
cwd, _ := os.Getwd()
|
cwd, _ := os.Getwd()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -3,7 +3,7 @@ package parser
|
|||||||
import "git.tebibyte.media/arf/arf/lexer"
|
import "git.tebibyte.media/arf/arf/lexer"
|
||||||
|
|
||||||
// parseIdentifier parses an identifier made out of dot separated names.
|
// parseIdentifier parses an identifier made out of dot separated names.
|
||||||
func (parser *ParsingOperation) parseIdentifier () (
|
func (parser *parsingOperation) parseIdentifier () (
|
||||||
identifier Identifier,
|
identifier Identifier,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
|
@ -7,8 +7,8 @@ import "git.tebibyte.media/arf/arf/file"
|
|||||||
import "git.tebibyte.media/arf/arf/lexer"
|
import "git.tebibyte.media/arf/arf/lexer"
|
||||||
import "git.tebibyte.media/arf/arf/infoerr"
|
import "git.tebibyte.media/arf/arf/infoerr"
|
||||||
|
|
||||||
// ParsingOperation holds information about an ongoing parsing operation.
|
// parsingOperation holds information about an ongoing parsing operation.
|
||||||
type ParsingOperation struct {
|
type parsingOperation struct {
|
||||||
modulePath string
|
modulePath string
|
||||||
token lexer.Token
|
token lexer.Token
|
||||||
tokens []lexer.Token
|
tokens []lexer.Token
|
||||||
@ -34,7 +34,7 @@ func Fetch (modulePath string, skim bool) (tree SyntaxTree, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// miss, so parse the module.
|
// miss, so parse the module.
|
||||||
parser := ParsingOperation {
|
parser := parsingOperation {
|
||||||
modulePath: modulePath,
|
modulePath: modulePath,
|
||||||
skimming: skim,
|
skimming: skim,
|
||||||
tree: SyntaxTree {
|
tree: SyntaxTree {
|
||||||
@ -76,7 +76,7 @@ func Fetch (modulePath string, skim bool) (tree SyntaxTree, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parse parses a file and adds it to the syntax tree.
|
// parse parses a file and adds it to the syntax tree.
|
||||||
func (parser *ParsingOperation) parse (sourceFile *file.File) (err error) {
|
func (parser *parsingOperation) parse (sourceFile *file.File) (err error) {
|
||||||
var tokens []lexer.Token
|
var tokens []lexer.Token
|
||||||
tokens, err = lexer.Tokenize(sourceFile)
|
tokens, err = lexer.Tokenize(sourceFile)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
@ -99,7 +99,7 @@ func (parser *ParsingOperation) parse (sourceFile *file.File) (err error) {
|
|||||||
// expect takes in a list of allowed token kinds, and returns an error if the
|
// expect takes in a list of allowed token kinds, and returns an error if the
|
||||||
// current token isn't one of them. If the length of allowed is zero, this
|
// current token isn't one of them. If the length of allowed is zero, this
|
||||||
// function will not return an error.
|
// function will not return an error.
|
||||||
func (parser *ParsingOperation) expect (allowed ...lexer.TokenKind) (err error) {
|
func (parser *parsingOperation) expect (allowed ...lexer.TokenKind) (err error) {
|
||||||
if len(allowed) == 0 { return }
|
if len(allowed) == 0 { return }
|
||||||
|
|
||||||
for _, kind := range allowed {
|
for _, kind := range allowed {
|
||||||
@ -129,7 +129,7 @@ func (parser *ParsingOperation) expect (allowed ...lexer.TokenKind) (err error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// nextToken is the same as expect, but it advances to the next token first.
|
// nextToken is the same as expect, but it advances to the next token first.
|
||||||
func (parser *ParsingOperation) nextToken (allowed ...lexer.TokenKind) (err error) {
|
func (parser *parsingOperation) nextToken (allowed ...lexer.TokenKind) (err error) {
|
||||||
parser.tokenIndex ++
|
parser.tokenIndex ++
|
||||||
if parser.tokenIndex >= len(parser.tokens) { return io.EOF }
|
if parser.tokenIndex >= len(parser.tokens) { return io.EOF }
|
||||||
parser.token = parser.tokens[parser.tokenIndex]
|
parser.token = parser.tokens[parser.tokenIndex]
|
||||||
@ -140,7 +140,7 @@ func (parser *ParsingOperation) nextToken (allowed ...lexer.TokenKind) (err erro
|
|||||||
|
|
||||||
// previousToken goes back one token. If the parser is already at the beginning,
|
// previousToken goes back one token. If the parser is already at the beginning,
|
||||||
// this does nothing.
|
// this does nothing.
|
||||||
func (parser *ParsingOperation) previousToken () {
|
func (parser *parsingOperation) previousToken () {
|
||||||
parser.tokenIndex --
|
parser.tokenIndex --
|
||||||
if parser.tokenIndex < 0 { parser.tokenIndex = 0 }
|
if parser.tokenIndex < 0 { parser.tokenIndex = 0 }
|
||||||
parser.token = parser.tokens[parser.tokenIndex]
|
parser.token = parser.tokens[parser.tokenIndex]
|
||||||
@ -149,7 +149,7 @@ func (parser *ParsingOperation) previousToken () {
|
|||||||
|
|
||||||
// skipIndentLevel advances the parser, ignoring every line with an indentation
|
// skipIndentLevel advances the parser, ignoring every line with an indentation
|
||||||
// equal to or greater than the specified indent.
|
// equal to or greater than the specified indent.
|
||||||
func (parser *ParsingOperation) skipIndentLevel (indent int) (err error) {
|
func (parser *parsingOperation) skipIndentLevel (indent int) (err error) {
|
||||||
braceLevel := 0
|
braceLevel := 0
|
||||||
parenLevel := 0
|
parenLevel := 0
|
||||||
bracketLevel := 0
|
bracketLevel := 0
|
||||||
@ -187,7 +187,7 @@ func (parser *ParsingOperation) skipIndentLevel (indent int) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// skipWhitespace skips over newlines and indent tokens.
|
// skipWhitespace skips over newlines and indent tokens.
|
||||||
func (parser *ParsingOperation) skipWhitespace () (err error) {
|
func (parser *parsingOperation) skipWhitespace () (err error) {
|
||||||
for {
|
for {
|
||||||
isWhitespace :=
|
isWhitespace :=
|
||||||
parser.token.Is(lexer.TokenKindIndent) ||
|
parser.token.Is(lexer.TokenKindIndent) ||
|
||||||
|
@ -87,7 +87,7 @@ var controlFlowKinds = []PhraseKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parseBlock parses an indented block of phrases
|
// parseBlock parses an indented block of phrases
|
||||||
func (parser *ParsingOperation) parseBlock (
|
func (parser *parsingOperation) parseBlock (
|
||||||
indent int,
|
indent int,
|
||||||
) (
|
) (
|
||||||
block Block,
|
block Block,
|
||||||
@ -108,7 +108,7 @@ func (parser *ParsingOperation) parseBlock (
|
|||||||
// parseBlockLevelPhrase parses a phrase that is not being used as an argument
|
// parseBlockLevelPhrase parses a phrase that is not being used as an argument
|
||||||
// to something else. This method is allowed to do things like parse return
|
// to something else. This method is allowed to do things like parse return
|
||||||
// directions, and indented blocks beneath the phrase.
|
// directions, and indented blocks beneath the phrase.
|
||||||
func (parser *ParsingOperation) parseBlockLevelPhrase (
|
func (parser *parsingOperation) parseBlockLevelPhrase (
|
||||||
indent int,
|
indent int,
|
||||||
) (
|
) (
|
||||||
phrase Phrase,
|
phrase Phrase,
|
||||||
@ -226,7 +226,7 @@ func (parser *ParsingOperation) parseBlockLevelPhrase (
|
|||||||
// parseArgumentLevelPhrase parses a phrase that is being used as an argument to
|
// parseArgumentLevelPhrase parses a phrase that is being used as an argument to
|
||||||
// something. It is forbidden from using return direction, and it must be
|
// something. It is forbidden from using return direction, and it must be
|
||||||
// delimited by brackets.
|
// delimited by brackets.
|
||||||
func (parser *ParsingOperation) parseArgumentLevelPhrase () (
|
func (parser *parsingOperation) parseArgumentLevelPhrase () (
|
||||||
phrase Phrase,
|
phrase Phrase,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
@ -277,7 +277,7 @@ func (parser *ParsingOperation) parseArgumentLevelPhrase () (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parsePhraseCommand parses the command argument of a phrase.
|
// parsePhraseCommand parses the command argument of a phrase.
|
||||||
func (parser *ParsingOperation) parsePhraseCommand () (
|
func (parser *parsingOperation) parsePhraseCommand () (
|
||||||
command Argument,
|
command Argument,
|
||||||
kind PhraseKind,
|
kind PhraseKind,
|
||||||
operator lexer.TokenKind,
|
operator lexer.TokenKind,
|
||||||
|
@ -4,7 +4,7 @@ import "git.tebibyte.media/arf/arf/lexer"
|
|||||||
import "git.tebibyte.media/arf/arf/infoerr"
|
import "git.tebibyte.media/arf/arf/infoerr"
|
||||||
|
|
||||||
// parseType parses a type notation of the form Name, {Name}, etc.
|
// parseType parses a type notation of the form Name, {Name}, etc.
|
||||||
func (parser *ParsingOperation) parseType () (what Type, err error) {
|
func (parser *parsingOperation) parseType () (what Type, err error) {
|
||||||
err = parser.expect(lexer.TokenKindName, lexer.TokenKindLBrace)
|
err = parser.expect(lexer.TokenKindName, lexer.TokenKindLBrace)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
what.location = parser.token.Location()
|
what.location = parser.token.Location()
|
||||||
|
@ -5,7 +5,7 @@ import "git.tebibyte.media/arf/arf/lexer"
|
|||||||
|
|
||||||
// parseTypeSection parses a type definition. It can inherit from other types,
|
// parseTypeSection parses a type definition. It can inherit from other types,
|
||||||
// and define new members on them.
|
// and define new members on them.
|
||||||
func (parser *ParsingOperation) parseTypeSection () (
|
func (parser *parsingOperation) parseTypeSection () (
|
||||||
section TypeSection,
|
section TypeSection,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
@ -72,7 +72,7 @@ func (parser *ParsingOperation) parseTypeSection () (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parseTypeSectionMember parses a type section member variable.
|
// parseTypeSectionMember parses a type section member variable.
|
||||||
func (parser *ParsingOperation) parseTypeSectionMember () (
|
func (parser *parsingOperation) parseTypeSectionMember () (
|
||||||
member TypeSectionMember,
|
member TypeSectionMember,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
|
Reference in New Issue
Block a user