Example #1
0
        private string getToken(Line line, int ad)
        {
            var tokens = line.Tokens;

            string id = null;

            if (tokens.Count > 0) {
                var last = tokens[tokens.Count - 1];
                if (ad == (last.ad + last.len)) {
                    if (last.type == TokenType.MultiLine) {
                        //if (last.mtype == MultiLineType.End) {
                        if (line.GetBlock(getPartition(last.id).Parent.ID).commentTransition == 0) {
                            var parent = getPartition(last.id);
                            if (parent == null) {
                                id = Document.DEFAULT_ID;
                            }
                            else {
                                id = parent.ID;
                            }
                        }
                        else {
                            id = last.id;
                        }
                    }
                    else {
                        id = last.id;
                    }
                }
            }

            if (id == null) {

                foreach (var token in tokens) {
                    if (token.ad <= ad && ad < (token.ad + token.len)) {
                        id = token.id;
                        break;
                    }
                }
            }

            if (id == null) {
                id = Document.DEFAULT_ID;
            }
            else if (id != Document.DEFAULT_ID) {
                var pa = getPartition(id).Parent;
                if (pa != null) {
                    id = pa.ID;
                }
                if (id == null) {
                    id = Document.DEFAULT_ID;
                }
            }

            return id;
        }