Exemplo n.º 1
0
func MakeReport(tree *models.TreeNode) {
	newTree := models.NewTreeNode()
	treeRebuilding(tree, newTree)
	fmt.Println("-----Rebuilded:")
	fmt.Println(*tree)
	storeResult(htmlHead + makeList(newTree, true) + htmlEnd)
	fmt.Println(*newTree)
}
Exemplo n.º 2
0
func treeRebuilding(tree models.PTreeNode, newTree models.PTreeNode) {
	rebuildChilds := func(parent models.PTreeNode) {
		for _, child := range tree.ChildList {
			rebuildTree(*child, parent)
		}
	}

	switch (*tree).Type() {
	case models.ST_SEQ:
		rebuildChilds(newTree)
	default:
		result := models.NewTreeNode()
		(*result).StringElement = tree.StringElement
		rebuildChilds(result)
		(*newTree).AddTreeNode(result)
	}
	return
}
Exemplo n.º 3
0
func NewIterator(value int) *SeqIterator {
	return &SeqIterator{value, nil, models.NewTreeNode()}
}
Exemplo n.º 4
0
//Main syntax parsing function
func Translate(word *models.StringElement, parentCursor *SeqIterator) (result bool) {
	deepInc()
	defer deepDec()

	cursor, element, error := GetCurrent(parentCursor)
	if isError(error) {
		return false
	}
	cursor.buffer.StringElement = *word
	switch word.Type() {
	case models.ST_CLASS:
		output.Par.SendPair(deep-1, COL_BLUE_B, "CLASS", word.Value,
			"curs.i", strconv.Itoa(cursor.int), (*element.Value).String())
		result = lexer.GetClassByName(word.Value) == element.Cat
	case models.ST_TERM:
		output.Par.SendPair(deep-1, COL_BLUE_B, "TERM", word.Value, (*element.Value).String())
		result = element.Name == word.Value
	case models.ST_RULE:
		output.Par.Send(deep-1, COL_BLUE_B, "RULE", word.Value)
		result = Translate(&GetRule(word.Value).TopWord, cursor)
	case models.ST_SEQ:
		output.Par.SendPair(deep, COL_BLUE_U, "SEQ", deep,
			"O", word.Optional,
			"C", word.Choises, "I", word.Iterative)
		checkChilds := func(curs *SeqIterator) bool {
			isLast := func(n int) bool {
				if n == len(word.Words)-1 {
					return true
				} else {
					return false
				}
			}
			for i, child := range word.Words {
				childResult := Translate(&child, curs)
				if word.Choises {
					if childResult {
						return true
					} else if isLast(i) {
						return false
					}
				} else {
					if childResult {
						if isLast(i) {
							return true
						}
					} else {
						return false
					}
				}
			}
			return false
		}

		if word.Iterative {
			Nrep := 0
			cycleCursor, error := InitIter(cursor)
			cycleCursor.buffer.XMLName.Local = string(models.ST_SEQ)
			if !isError(error) {
				for iterSucc := true; iterSucc; {
					iterSucc = checkChilds(cycleCursor)
					output.Par.SendPair(deep, COL_RED, iterSucc,
						Nrep, cursor.int, cycleCursor.int)
					if iterSucc {
						Nrep++
					}
				}
			}
			if Nrep > 0 {
				cycleCursor.ApplyToParent()
				result = true
			} else {
				result = false
			}
		} else {
			result = checkChilds(cursor)
		}
		if word.Optional && !result {
			result = true
			cursor.buffer = models.NewTreeNode()
			cursor.buffer.XMLName.Local = string(models.ST_SEQ)
			output.Par.Send(0, COL_DEEP_LIM, "OPTIONAL")
		}
	}
	if result {
		if word.Type() == models.ST_RULE ||
			word.Type() == models.ST_SEQ {
			cursor.ApplyToParent()
		} else {
			fmt.Println("Add to parent", *word, "|", *element)
			cursor.AddToParent(word, element)
		}
		output.Par.SendPair(deep, COL_GREEN, "RES", result, word.Type()) //TODO print output for failures too
	}
	return
}