~cypheon/kicad2spice

ref: 96e390bc4f914314da98ecdfd7bd775e620563e2 kicad2spice/lib/lex_sch_legacy.mll -rw-r--r-- 2.1 KiB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{
  open Lexing
  open Sch_legacy
  exception SyntaxError of string
}

let int = '-'? ['0'-'9'] ['0'-'9']*
let unquoted_string = [ ^ ' ' '\t' '\n' '"' ] +

rule read =
  parse
  | "EESchema Schematic File Version" { MAGIC_HEADER }
  | int { INT (int_of_string (lexeme lexbuf)) }
  | '"' { read_string (Buffer.create 17) lexbuf }
  | "LIBS:" [ ^ '\n' ] + { LIBS (lexeme lexbuf) }
  | "encoding" { ENCODING }
  | "Sheet" { SHEET }
  | "EELAYER" { EELAYER }
  | "END" { END }
  | "$Descr " [^ ' ' '\n']+ ' ' [^ ' ' '\n']+ ' ' [^ ' ' '\n']+ { START_DESCR (lexeme lexbuf) }
  | "$EndDescr" { END_DESCR }
  | "$Comp\n" { new_line lexbuf; read_component_line [] lexbuf }
  | "Wire " [ ^ '\n' ]+ '\n' { new_line lexbuf; read_wire_line (lexeme lexbuf) lexbuf }
  | "Connection ~ " [ ^ '\n' ]+ '\n' { new_line lexbuf; CONNECTION (lexeme lexbuf) }
  | "$EndSCHEMATC" { END_SCHEMATIC }
  | '\n' { new_line lexbuf; NEWLINE }
  | ' '+ { read lexbuf }
  | unquoted_string { STRING_UNQUOTED (lexeme lexbuf) }
  | eof { EOF }
and read_component_line lines =
  parse
  | "L " [ ^ '\n' ] + '\n' { new_line lexbuf; read_component_line (lines @ [lexeme lexbuf]) lexbuf }
  | "U " [ ^ '\n' ] + '\n' { new_line lexbuf; read_component_line (lines @ [lexeme lexbuf]) lexbuf }
  | "P " [ ^ '\n' ] + '\n' { new_line lexbuf; read_component_line (lines @ [lexeme lexbuf]) lexbuf }
  | "F " [ ^ '\n' ] + '\n' { new_line lexbuf; read_component_line (lines @ [lexeme lexbuf]) lexbuf }
  | "\t" [ ^ '\n' ] + '\n' { new_line lexbuf; read_component_line (lines @ [lexeme lexbuf]) lexbuf }
  | "$EndComp\n" { new_line lexbuf; COMPONENT lines }
and read_wire_line wire_type =
  parse
  | '\t' int ' '+ int ' '+ int ' '+ int ' '* '\n' {new_line lexbuf; WIRE (wire_type, lexeme lexbuf)}
and read_string buf =
  parse
  | '"' { STRING (Buffer.contents buf) }
  | '\\' '"'
    {
      Buffer.add_char buf '\\';
      read_string buf lexbuf
    }
  | [^ '"' '\\']+
    { Buffer.add_string buf (lexeme lexbuf);
      read_string buf lexbuf
    }
and tokenize =
  parse
  | unquoted_string { STRING_UNQUOTED (lexeme lexbuf) }
  | '"' { read_string (Buffer.create 17) lexbuf }
  | [' ' '\t' '\n']+ { read lexbuf }
  | eof { EOF }