revert-complexity #7
|
@ -12,8 +12,7 @@ func (parser *ParsingOperation) parseFaceSection () (
|
||||||
err = parser.expect(lexer.TokenKindName)
|
err = parser.expect(lexer.TokenKindName)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
section.behaviors = make(map[string] FaceBehavior)
|
section.location = parser.token.Location()
|
||||||
section.location = parser.token.Location()
|
|
||||||
|
|
||||||
// get permission
|
// get permission
|
||||||
err = parser.nextToken(lexer.TokenKindPermission)
|
err = parser.nextToken(lexer.TokenKindPermission)
|
||||||
|
@ -32,24 +31,59 @@ func (parser *ParsingOperation) parseFaceSection () (
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
section.inherits, err = parser.parseIdentifier()
|
section.inherits, err = parser.parseIdentifier()
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
err = parser.nextToken(lexer.TokenKindNewline)
|
err = parser.expect(lexer.TokenKindNewline)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
err = parser.nextToken()
|
err = parser.nextToken()
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
|
if !parser.token.Is(lexer.TokenKindIndent) { return }
|
||||||
|
if parser.token.Value().(int) != 1 { return }
|
||||||
|
|
||||||
|
err = parser.nextToken (
|
||||||
|
lexer.TokenKindName,
|
||||||
|
lexer.TokenKindGreaterThan,
|
||||||
|
lexer.TokenKindLessThan)
|
||||||
|
if err != nil { return }
|
||||||
|
|
||||||
|
if parser.token.Is(lexer.TokenKindName) {
|
||||||
|
// parse type interface
|
||||||
|
parser.previousToken()
|
||||||
|
section.behaviors, err = parser.parseFaceBehaviors()
|
||||||
|
if err != nil { return }
|
||||||
|
} else {
|
||||||
|
// parse function interface
|
||||||
|
parser.previousToken()
|
||||||
|
section.inputs,
|
||||||
|
section.outputs, err = parser.parseFaceBehaviorArguments(1)
|
||||||
|
if err != nil { return }
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// parseFaceBehaviors parses a list of interface behaviors for an object
|
||||||
|
// interface.
|
||||||
|
func (parser *ParsingOperation) parseFaceBehaviors () (
|
||||||
|
behaviors map[string] FaceBehavior,
|
||||||
|
err error,
|
||||||
|
) {
|
||||||
// parse members
|
// parse members
|
||||||
|
behaviors = make(map[string] FaceBehavior)
|
||||||
for {
|
for {
|
||||||
// if we've left the block, stop parsing
|
// if we've left the block, stop parsing
|
||||||
if !parser.token.Is(lexer.TokenKindIndent) { return }
|
if !parser.token.Is(lexer.TokenKindIndent) { return }
|
||||||
if parser.token.Value().(int) != 1 { return }
|
if parser.token.Value().(int) != 1 { return }
|
||||||
|
|
||||||
// parse behavior
|
err = parser.nextToken(lexer.TokenKindName)
|
||||||
behaviorBeginning := parser.token.Location()
|
behaviorBeginning := parser.token.Location()
|
||||||
|
if err != nil { return }
|
||||||
|
|
||||||
|
// parse behavior
|
||||||
var behavior FaceBehavior
|
var behavior FaceBehavior
|
||||||
behavior, err = parser.parseFaceBehavior()
|
behavior, err = parser.parseFaceBehavior(1)
|
||||||
|
|
||||||
// add to section
|
// add to section
|
||||||
_, exists := section.behaviors[behavior.name]
|
_, exists := behaviors[behavior.name]
|
||||||
if exists {
|
if exists {
|
||||||
err = infoerr.NewError (
|
err = infoerr.NewError (
|
||||||
behaviorBeginning,
|
behaviorBeginning,
|
||||||
|
@ -58,23 +92,21 @@ func (parser *ParsingOperation) parseFaceSection () (
|
||||||
infoerr.ErrorKindError)
|
infoerr.ErrorKindError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
section.behaviors[behavior.name] = behavior
|
behaviors[behavior.name] = behavior
|
||||||
|
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseFaceBehavior parses a single interface behavior. Indentation level is
|
// parseFaceBehavior parses a single interface behavior.
|
||||||
// assumed.
|
func (parser *ParsingOperation) parseFaceBehavior (
|
||||||
func (parser *ParsingOperation) parseFaceBehavior () (
|
indent int,
|
||||||
|
) (
|
||||||
behavior FaceBehavior,
|
behavior FaceBehavior,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
err = parser.expect(lexer.TokenKindIndent)
|
|
||||||
if err != nil { return }
|
|
||||||
|
|
||||||
// get name
|
// get name
|
||||||
err = parser.nextToken(lexer.TokenKindName)
|
err = parser.expect(lexer.TokenKindName)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
behavior.name = parser.token.Value().(string)
|
behavior.name = parser.token.Value().(string)
|
||||||
|
|
||||||
|
@ -83,10 +115,26 @@ func (parser *ParsingOperation) parseFaceBehavior () (
|
||||||
err = parser.nextToken()
|
err = parser.nextToken()
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
|
behavior.inputs,
|
||||||
|
behavior.outputs,
|
||||||
|
err = parser.parseFaceBehaviorArguments(indent + 1)
|
||||||
|
if err != nil { return }
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (parser *ParsingOperation) parseFaceBehaviorArguments (
|
||||||
|
indent int,
|
||||||
|
) (
|
||||||
|
inputs []Declaration,
|
||||||
|
outputs []Declaration,
|
||||||
|
err error,
|
||||||
|
) {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// if we've left the block, stop parsing
|
// if we've left the behavior, stop parsing
|
||||||
if !parser.token.Is(lexer.TokenKindIndent) { return }
|
if !parser.token.Is(lexer.TokenKindIndent) { return }
|
||||||
if parser.token.Value().(int) != 2 { return }
|
if parser.token.Value().(int) != indent { return }
|
||||||
|
|
||||||
// get preceding symbol
|
// get preceding symbol
|
||||||
err = parser.nextToken (
|
err = parser.nextToken (
|
||||||
|
@ -115,13 +163,9 @@ func (parser *ParsingOperation) parseFaceBehavior () (
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
if kind == lexer.TokenKindGreaterThan {
|
if kind == lexer.TokenKindGreaterThan {
|
||||||
behavior.inputs = append (
|
inputs = append(inputs, declaration)
|
||||||
behavior.inputs,
|
|
||||||
declaration)
|
|
||||||
} else {
|
} else {
|
||||||
behavior.outputs = append (
|
outputs = append(outputs, declaration)
|
||||||
behavior.outputs,
|
|
||||||
declaration)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,18 +6,18 @@ func TestFace (test *testing.T) {
|
||||||
checkTree ("../tests/parser/face", false,
|
checkTree ("../tests/parser/face", false,
|
||||||
`:arf
|
`:arf
|
||||||
---
|
---
|
||||||
face ro ReadWriter:Face
|
face ro aReadWriter:Face
|
||||||
write
|
|
||||||
> data:{Byte ..}
|
|
||||||
< wrote:Int
|
|
||||||
< err:Error
|
|
||||||
read
|
read
|
||||||
> into:{Byte ..}
|
> into:{Byte ..}
|
||||||
< read:Int
|
< read:Int
|
||||||
< err:Error
|
< err:Error
|
||||||
face ro Destroyer:Face
|
write
|
||||||
|
> data:{Byte ..}
|
||||||
|
< wrote:Int
|
||||||
|
< err:Error
|
||||||
|
face ro bDestroyer:Face
|
||||||
destroy
|
destroy
|
||||||
face ro cFuncInterface
|
face ro cFuncInterface:Func
|
||||||
> something:Int
|
> something:Int
|
||||||
< someOutput:Int
|
< someOutput:Int
|
||||||
< otherOutput:String
|
< otherOutput:String
|
||||||
|
|
|
@ -191,6 +191,15 @@ type EnumSection struct {
|
||||||
members []EnumMember
|
members []EnumMember
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FaceKind determines if an interface is a type interface or an function
|
||||||
|
// interface.
|
||||||
|
type FaceKind int
|
||||||
|
|
||||||
|
const (
|
||||||
|
FaceKindType FaceKind = iota
|
||||||
|
FaceKindFunc
|
||||||
|
)
|
||||||
|
|
||||||
// FaceBehavior represents a behavior of an interface section.
|
// FaceBehavior represents a behavior of an interface section.
|
||||||
type FaceBehavior struct {
|
type FaceBehavior struct {
|
||||||
locatable
|
locatable
|
||||||
|
@ -207,7 +216,10 @@ type FaceSection struct {
|
||||||
permissionable
|
permissionable
|
||||||
inherits Identifier
|
inherits Identifier
|
||||||
|
|
||||||
|
kind FaceKind
|
||||||
|
|
||||||
behaviors map[string] FaceBehavior
|
behaviors map[string] FaceBehavior
|
||||||
|
FaceBehavior
|
||||||
}
|
}
|
||||||
|
|
||||||
// PhraseKind determines what semantic role a phrase plays.
|
// PhraseKind determines what semantic role a phrase plays.
|
||||||
|
|
|
@ -14,7 +14,7 @@ face ro aReadWriter:Face
|
||||||
face ro bDestroyer:Face
|
face ro bDestroyer:Face
|
||||||
destroy
|
destroy
|
||||||
|
|
||||||
face ro cFuncInterface
|
face ro cFuncInterface:Func
|
||||||
> something:Int
|
> something:Int
|
||||||
< someOutput:Int
|
< someOutput:Int
|
||||||
< otherOutput:String
|
< otherOutput:String
|
||||||
|
|
Reference in New Issue
Block a user