~cypheon/kicad2spice

ref: 96e390bc4f914314da98ecdfd7bd775e620563e2 kicad2spice/lib/lex_sexp.mll -rw-r--r-- 815 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
{
  open Lexing
  open Parse_sexp
  exception SyntaxError of string

}

let space = [' ' '\t']
let unquoted = [ ^ ' ' '\n' '\r' '\t' '"' '(' ')']

rule read =
  parse
  | '(' { LPAREN }
  | ')' { RPAREN }
  | '\n' { new_line lexbuf; read lexbuf }
  | '"' { read_string (Buffer.create 17) lexbuf }
  | unquoted + { QUOTED_STRING (lexeme lexbuf) }
  | space { read lexbuf }
  | eof { EOF }
  | _ { failwith (Printf.sprintf "unexpected character: line %d:%d" lexbuf.lex_curr_p.pos_lnum (lexbuf.lex_curr_p.pos_cnum - lexbuf.lex_curr_p.pos_bol + 1) )}

and read_string buf =
  parse
  | '"' { QUOTED_STRING (Buffer.contents buf) }
  | '\\' '"'
    {
      Buffer.add_char buf '\\';
      read_string buf lexbuf
    }
  | [^ '"' '\\' '\n']+
    { Buffer.add_string buf (lexeme lexbuf);
      read_string buf lexbuf
    }