I want to parse text with javascript. The syntax i want to parse is a markup language. this language has 2 main kind of markup:

```
$f56

```

mean the following characters will be of color `#F56`. Until the following `$` with 3 hex char it is using this color.

```
$i

```

Mean until the following `$z` (closing tag) the text is in italic. They are other one letter 
tags.

So basically this language is composed of 3 character long hexa tags for color and one letter long tags.

I can craft something ugly to parse my text, storing char position and current status of tags (formatting and color) but i'd like to learn proper parsing. Could you give me a few tips/principle to make a clean parser for this language ?