~cypheon/kicad2spice

ref: 96e390bc4f914314da98ecdfd7bd775e620563e2 kicad2spice/lib/lex_tokenize.mll -rw-r--r-- 769 bytes
96e390bc — Johann Rudloff Implement correct pin order according to field "Spice_Node_Sequence" 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{
  open Lexing
  exception SyntaxError of string
}

let whitespace = [' ' '\t' '\n']
let wordsep = [' ' '\t' '\n' '"']

rule read =
  parse
  | whitespace + { read lexbuf }
  | '"' { read_string (Buffer.create 17) lexbuf }
  | (_ # wordsep) + { Some (lexeme lexbuf) }
  | eof { None }
and read_string buf =
  parse
  | '"' { Some (Buffer.contents buf) }
  | '\\' '"'
    {
      Buffer.add_char buf '\\';
      read_string buf lexbuf
    }
  | [^ '"' '\\']+
    { Buffer.add_string buf (Lexing.lexeme lexbuf);
      read_string buf lexbuf
    }

{
let rec tokenize_helper lexbuf acc =
  match read lexbuf with
    Some s -> tokenize_helper lexbuf (s::acc)
  | None -> List.rev acc

let tokenize s =
  let lexbuf = Lexing.from_string s in
  tokenize_helper lexbuf []
}