# Confusing behavior of sequence//3 and sequence//5 from dcg/high\_order

**URL:** <https://swi-prolog.discourse.group/t/confusing-behavior-of-sequence-3-and-sequence-5-from-dcg-high-order/1607>\
**Category:** Help!\
**Tags:** how-to\
**Created:** [December 12, 2019, 10:38am UTC](https://swi-prolog.discourse.group/t/confusing-behavior-of-sequence-3-and-sequence-5-from-dcg-high-order/1607 "2019-12-12T10:38:48Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [December 2, 2020, 10:53am UTC](https://swi-prolog.discourse.group/t/confusing-behavior-of-sequence-3-and-sequence-5-from-dcg-high-order/1607/8 "2020-12-02T10:53:56Z")

</div>

Yes, I know I am reviving a topic.

How do you suggest to parse a line-oriented text file, where each line _must_ end with a newline?

Here are different options I tried. I strongly suspect I am making a very basic mistake somewhere…

First, I thought that I can use sequence//5 with an empty Start, and both Sep and End a newline, like this:

```prolog
phrase(sequence("", line_dcg, "\n", "\n", List), Input)

```

This does not work for me. The problem seems to be that the Sep and the End are the same. Using `*` and ‘|’ so that it is easier to read:

```prolog
?- phrase(sequence("", integer, "*", "*", L), `1*2*`).
false.

?- phrase(sequence("", integer, "|", "*", L), `1|2*`).
L = [1, 2].

```

I guess sequence//3 suffers from the same problem?

```prolog
?- phrase(( sequence(integer, "|", L), "*" ), `1|2*`).
L = [1, 2].

?- phrase(( sequence(integer, "*", L), "*" ), `1*2*`).
false.

```

Finally, using sequence//2 with an “element DCG” that consumes the end-of-line:

```prolog
line(X) --> integer(X), "*".

```

and then:

```prolog
?- phrase(sequence(line, L), `1*2*`).
L = [1, 2] ;
false.

```

… and I guess that for parsing, I should cut after phrase?

```prolog
?- phrase(sequence(line, L), `1*2*`), !.
L = [1, 2].

```

---

_[View the full topic](https://swi-prolog.discourse.group/t/confusing-behavior-of-sequence-3-and-sequence-5-from-dcg-high-order/1607)._
