@@ -29,7 +29,7 @@ them here: http://lpsolve.sourceforge.net
2929function Base. read! (io:: IO , model:: Model{T} ) where {T}
3030 if ! MOI. is_empty (model)
3131 error (" Cannot read in file because model is not empty." )
32- end
32+ end
3333 state = LexerState (io)
3434 cache = Cache (model)
3535 keyword = :UNKNOWN
@@ -215,6 +215,7 @@ function Base.read(state::LexerState, ::Type{Token})
215215end
216216
217217_is_idenfifier (c:: Char ) = ! (isspace (c) || c in (' +' , ' -' , ' *' , ' ^' , ' :' ))
218+ _is_number (c:: Char ) = isdigit (c) || c in (' .' , ' e' , ' E' , ' +' , ' -' )
218219
219220function Base. peek (state:: LexerState , :: Type{Token} , n:: Int = 1 )
220221 @assert n >= 1
@@ -240,7 +241,7 @@ function _peek_inner(state::LexerState)
240241 end
241242 elseif isdigit (c) || (c == ' -' && isdigit (peek (state, Char))) # Number
242243 buf = IOBuffer ()
243- while (c = peek (state, Char)) != = nothing && ( isdigit (c) || c in [ ' . ' , ' e ' , ' E ' , ' + ' , ' - ' ] )
244+ while (c = peek (state, Char)) != = nothing && _is_number (c )
244245 write (buf, c)
245246 read (state, Char)
246247 end
@@ -391,7 +392,7 @@ function _parse_quad_term(
391392 return _parse_quad_term (state, cache, prefix)
392393 elseif _next_token_is (state, _TOKEN_SUBTRACTION)
393394 read (state, Token)
394- return _parse_quad_term (state, cache, - prefix)
395+ return _parse_quad_term (state, cache, - prefix)
395396 end
396397 coef = prefix
397398 if _next_token_is (state, _TOKEN_NUMBER)
@@ -533,7 +534,6 @@ function _add_to_expression!(
533534 return
534535end
535536
536-
537537# EXPRESSION :=
538538# TERM (("+" | "-") TERM)*
539539function _parse_expression (state:: LexerState , cache:: Cache{T} ) where {T}
@@ -679,8 +679,8 @@ function _parse_bound(state, cache)
679679 x = _parse_variable (state, cache)
680680 _add_bound (cache, x, lhs_set)
681681 if _next_token_is (state, _TOKEN_GREATER_THAN) ||
682- _next_token_is (state, _TOKEN_LESS_THAN) ||
683- _next_token_is (state, _TOKEN_EQUAL_TO) # `a op x op b`
682+ _next_token_is (state, _TOKEN_LESS_THAN) ||
683+ _next_token_is (state, _TOKEN_EQUAL_TO) # `a op x op b`
684684 # We don't add MOI.Interval constraints to follow JuMP's convention of
685685 # separate bounds.
686686 rhs_set = _parse_set_suffix (state, cache)
696696# The newline character is required.
697697function _parse_sos_constraint (state:: LexerState , cache:: Cache{T} ) where {T}
698698 t = read (state, Token) # Si
699+ if ! (t. value == " S1" || t. value == " S2" )
700+ throw (UnexpectedToken (t))
701+ end
699702 _expect (read (state, Token), _TOKEN_COLON)
700703 _expect (read (state, Token), _TOKEN_COLON)
701704 f, w = MOI. VectorOfVariables (MOI. VariableIndex[]), T[]
@@ -715,18 +718,16 @@ function _parse_sos_constraint(state::LexerState, cache::Cache{T}) where {T}
715718end
716719
717720function _is_sos_constraint (state)
718- t = peek (state, Token, 1 )
719- return t. kind == _TOKEN_IDENTIFIER &&
720- (t. value == " S1" || t. value == " S2" ) &&
721- _next_token_is (state, _TOKEN_COLON, 2 ) &&
722- _next_token_is (state, _TOKEN_COLON, 3 )
721+ return _next_token_is (state, _TOKEN_IDENTIFIER, 1 ) &&
722+ _next_token_is (state, _TOKEN_COLON, 2 ) &&
723+ _next_token_is (state, _TOKEN_COLON, 3 )
723724end
724725
725726function _is_indicator_constraint (state)
726727 return _next_token_is (state, _TOKEN_IDENTIFIER, 1 ) &&
727- _next_token_is (state, _TOKEN_EQUAL_TO, 2 ) &&
728- _next_token_is (state, _TOKEN_NUMBER, 3 ) &&
729- _next_token_is (state, _TOKEN_IMPLIES, 4 )
728+ _next_token_is (state, _TOKEN_EQUAL_TO, 2 ) &&
729+ _next_token_is (state, _TOKEN_NUMBER, 3 ) &&
730+ _next_token_is (state, _TOKEN_IMPLIES, 4 )
730731end
731732
732733# INDICATOR_CONSTRAINT :=
0 commit comments