Пример #1
0
func (op *SemanticOperationNameParens) InPort(dat interface{}) {
	md := dat.(*data.MainData)
	res := md.ParseData.Result
	subRes := md.ParseData.SubResults
	subVals := res.Value.([]interface{})
	oper := &data.Operation{}

	if subVals[0] != nil {
		opNameVal := subVals[0].([]interface{})
		oper.Name = opNameVal[0].(string)
		oper.SrcPos = subRes[0].Pos
	}
	if subVals[3] != nil {
		oper.Type = subVals[3].(string)
		if subVals[0] == nil {
			oper.SrcPos = subRes[1].Pos
		}
	}
	if len(oper.Name) <= 0 && len(oper.Type) <= 0 {
		errPos := md.ParseData.SubResults[0].Pos
		gparselib.AddError(errPos, "At least an operation name or an operation type have to be provided",
			nil, md.ParseData)
	} else if len(oper.Name) <= 0 {
		oper.Name = strings.ToLower(oper.Type[0:1]) + oper.Type[1:]
	}
	res.Value = oper

	op.outPort(md)
}
Пример #2
0
func (op *SemanticPort) InPort(dat interface{}) {
	md := dat.(*data.MainData)
	pd := md.ParseData
	nameRes := pd.SubResults[0]

	if pd.SubResults[1].Value == nil {
		md.ParseData.Result.Value = data.NewPort(nameRes.Text, nameRes.Pos)
	} else {
		val := pd.SubResults[1].Value
		idx64 := val.([]interface{})[1].(uint64)
		if idx64 > uint64(math.MaxInt32) {
			errPos := pd.SubResults[1].Pos + 1
			gparselib.AddError(errPos, "Ridiculous large port index "+strconv.FormatUint(idx64, 10), nil, pd)
			md.ParseData.Result.ErrPos = -1 // just a semantic error, no syntax error!
			md.ParseData.Result.Value = nil
		} else {
			md.ParseData.Result.Value = data.NewIdxPort(nameRes.Text, int(idx64), nameRes.Pos)
		}
	}
	op.outPort(md)
}