From 492fec0f3fa5f4575f281c30ffc058f7920f3d29 Mon Sep 17 00:00:00 2001 From: Johann Rudloff Date: Sat, 13 Jul 2019 16:37:35 +0200 Subject: [PATCH] Remove custom next_line function and use Lexing.new_line --- lib/lex_lib.mll | 11 ++--------- lib/lex_sch_legacy.mll | 29 +++++++++++------------------ 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/lib/lex_lib.mll b/lib/lex_lib.mll index 32e9d83..ac59682 100644 --- a/lib/lex_lib.mll +++ b/lib/lex_lib.mll @@ -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 } diff --git a/lib/lex_sch_legacy.mll b/lib/lex_sch_legacy.mll index 550a1a7..66df657 100644 --- a/lib/lex_sch_legacy.mll +++ b/lib/lex_sch_legacy.mll @@ -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) } -- 2.45.2