~cypheon/kicad2spice

492fec0f3fa5f4575f281c30ffc058f7920f3d29 — Johann Rudloff 4 years ago 8943c62
Remove custom next_line function and use Lexing.new_line
2 files changed, 13 insertions(+), 27 deletions(-)

M lib/lex_lib.mll
M lib/lex_sch_legacy.mll
M lib/lex_lib.mll => lib/lex_lib.mll +2 -9
@@ 6,13 6,6 @@
  let is_at_bol lexbuf =
    lexbuf.lex_start_p.pos_cnum = lexbuf.lex_start_p.pos_bol

  let next_line lexbuf =
    let pos = lexbuf.lex_curr_p in
    lexbuf.lex_curr_p <-
      { pos with pos_bol = lexbuf.lex_curr_p.pos_cnum;
                 pos_lnum = pos.pos_lnum + 1
      }

}

let space = [' ' '\t']


@@ 27,7 20,7 @@ rule read =
  | "DRAW" { if is_at_bol lexbuf then DRAW_START else STRING (lexeme lexbuf) }
  | "ENDDRAW" { if is_at_bol lexbuf then DRAW_END else STRING (lexeme lexbuf) }
  | 'F' (_ # space) ' ' { FIELD (lexeme lexbuf) }
  | '\n' { next_line lexbuf; NEWLINE }
  | '\n' { new_line lexbuf; NEWLINE }
  | space { read lexbuf }
  | [ ^ '"' ' ' '\t' '\n' ]+ {
    if is_at_bol lexbuf && (lexeme_char lexbuf 0) = '#'


@@ 52,4 45,4 @@ and read_string buf =
    }
and read_comment =
  parse
  | [ ^ '\n' ]* '\n' { next_line lexbuf; read lexbuf }
  | [ ^ '\n' ]* '\n' { new_line lexbuf; read lexbuf }

M lib/lex_sch_legacy.mll => lib/lex_sch_legacy.mll +11 -18
@@ 2,13 2,6 @@
  open Lexing
  open Sch_legacy
  exception SyntaxError of string

  let next_line lexbuf =
  let pos = lexbuf.lex_curr_p in
  lexbuf.lex_curr_p <-
    { pos with pos_bol = lexbuf.lex_curr_p.pos_cnum;
               pos_lnum = pos.pos_lnum + 1
    }
}

let int = '-'? ['0'-'9'] ['0'-'9']*


@@ 26,25 19,25 @@ rule read =
  | "END" { END }
  | "$Descr " [^ ' ' '\n']+ ' ' [^ ' ' '\n']+ ' ' [^ ' ' '\n']+ { START_DESCR (lexeme lexbuf) }
  | "$EndDescr" { END_DESCR }
  | "$Comp\n" { next_line lexbuf; read_component_line [] lexbuf }
  | "Wire " [ ^ '\n' ]+ '\n' { next_line lexbuf; read_wire_line (lexeme lexbuf) lexbuf }
  | "Connection ~ " [ ^ '\n' ]+ '\n' { next_line lexbuf; CONNECTION (lexeme lexbuf) }
  | "$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' { next_line lexbuf; NEWLINE }
  | '\n' { new_line lexbuf; NEWLINE }
  | ' '+ { read lexbuf }
  | unquoted_string { STRING_UNQUOTED (Lexing.lexeme lexbuf) }
  | eof { EOF }
and read_component_line lines =
  parse
  | "L " [ ^ '\n' ] + '\n' { next_line lexbuf; read_component_line (lines @ [lexeme lexbuf]) lexbuf }
  | "U " [ ^ '\n' ] + '\n' { next_line lexbuf; read_component_line (lines @ [lexeme lexbuf]) lexbuf }
  | "P " [ ^ '\n' ] + '\n' { next_line lexbuf; read_component_line (lines @ [lexeme lexbuf]) lexbuf }
  | "F " [ ^ '\n' ] + '\n' { next_line lexbuf; read_component_line (lines @ [lexeme lexbuf]) lexbuf }
  | "\t" [ ^ '\n' ] + '\n' { next_line lexbuf; read_component_line (lines @ [lexeme lexbuf]) lexbuf }
  | "$EndComp\n" { next_line lexbuf; COMPONENT lines }
  | "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' {next_line lexbuf; WIRE (wire_type, lexeme lexbuf)}
  | '\t' int ' '+ int ' '+ int ' '+ int ' '* '\n' {new_line lexbuf; WIRE (wire_type, lexeme lexbuf)}
and read_string buf =
  parse
  | '"' { STRING (Buffer.contents buf) }