Commit Graph

223 Commits

Author SHA1 Message Date
Jørgen Kvalsvik
728a9c2e69 Short circuit when line terminator is found first
The termination logic would sometimes need to scan the full line to see
if some terminating condition was found inside quotes. Plenty of
comments in a file start on the first character of a line, meaning this
scan is unnecessary.
2016-10-20 15:11:44 +02:00
Jørgen Kvalsvik
db66f0302c Explicit bool conversion in isRecognizedKeyword 2016-10-06 13:17:23 +02:00
Liu Ming
756b4d1edd argument of warning() method is msg, filename, linenumber. 2016-08-29 14:01:14 +08:00
Joakim Hove
9bcdadd443 Merge pull request #890 from pgdr/transmult-and-shared_ptrs
Removing some use of shared_ptr
2016-08-09 09:32:41 +02:00
Pål Grønås Drange
41b158bb2b Shortified names, instead of state.getEclipseConfig().getSummaryConfig(), use state.cfg().summary() 2016-08-08 11:39:59 +02:00
Jørgen Kvalsvik
db33a9cc55 Prefer function objects in Parser::clean
Implementing these checks as function objects improves performance
slightly (5% or so according to my measurements), probably due to the
functions being inlined rather than reduced to function pointers.
2016-08-08 09:42:41 +02:00
Jørgen Kvalsvik
f571f21171 is_separator includes comma
This deprecates the comma replace function in the reader.
2016-08-04 16:05:53 +02:00
Jørgen Kvalsvik
adc602f6aa Manually copy over append in Parser.clean
Book keeping internally in the string class is rather unnecessary and
performed a lot (once per line in the input). Performing a manual copy
without string encumbered book keeping (essentially using the string as
a raw char* buffer) gives some performance, which scales well with the
lines in each deck.
2016-08-04 16:05:53 +02:00
Jørgen Kvalsvik
616e810858 Fix warnings in Parser 2016-07-13 23:40:09 +02:00
Joakim Hove
10bf441076 Added ParseContext::PARSE_MISSING_INCLUDE 2016-06-15 17:34:44 +02:00
Jørgen Kvalsvik
eeba4f37e6 Expand on possible failure case in parser 2016-06-14 14:44:46 +02:00
Jørgen Kvalsvik
f56a2d61d0 Strip commas from the input deck
Some decks use comma to separate items in a record, but the comma adds
no extra information and is essentially ignored. Post-process the file
after cleaning it and replace all commas with whitespace.

Considering the record "foo bar , , , baz" / baz will silently be moved
to the third item, but handling that situation is a **lot** more
difficult and time consuming and not worth the effort for now.
Additionally, we have yet to receive decks that fail in such a manner,
nor are we sure if it is even a valid record in Eclipse.
2016-06-14 12:57:05 +02:00
Jørgen Kvalsvik
726b0d0957 Implement InputStack with std::stack
Save some implementation by using std::stack as interface and
implementation for InputStack. Remove the vector pair of file and file*
and just use file directly.
2016-05-24 12:40:40 +02:00
Liu Ming
14c33394f4 add MessageContainer argument for logging messages. 2016-05-14 08:42:40 +02:00
Liu Ming
e538ed43dc log messages before handleError. 2016-05-14 08:42:40 +02:00
Pål Grønås Drange
091dc196f3 Added parse functions for Parser, for simpler creation of state and grids 2016-05-06 12:21:41 +02:00
Joakim Hove
350297e8ec Merge pull request #792 from jokva/bugfixes
Bugfixes
2016-05-04 09:30:30 +02:00
Jørgen Kvalsvik
1f2c2ba98d Name cases where TITLE is unset
When the TITLE keyword was present in the deck, but no parameter was
given the parser would consume the next keyword as the simulation TITLE.
Override this by writing a default TITLE if it's unset.
2016-05-03 15:42:30 +02:00
Pål Grønås Drange
672b240e00 fixed bug in Parser, use openRootFile 2016-05-03 15:22:34 +02:00
Jørgen Kvalsvik
41fc16ad92 Keep ParserKeyword instances; internalName removed
Internal names are deprecated, and instead added ParserKeyword instances
are maintained and kept for the lifetime of the ParserKeyword instance.
Querying keyword existence from python picks up on Deck names, expected
to always be the intended case, instead of internal names.
2016-05-03 12:59:57 +02:00
Jørgen Kvalsvik
ba5983483e Throw on error from fread 2016-05-03 09:30:57 +02:00
Jørgen Kvalsvik
dcc3668fdd Rename strip_after -> find_terimnator 2016-05-03 09:30:57 +02:00
Jørgen Kvalsvik
8cb64dad72 Encapsulate ParserState's internals. 2016-05-03 09:30:57 +02:00
Jørgen Kvalsvik
ff301622b6 Append newline to input; remove branch in getline
By allowing getline to assume that the next line always starts after the
found \n *or* that after the found newline is the \0, we can avoid a
branch and potential stall.
2016-05-03 09:30:57 +02:00
Jørgen Kvalsvik
8014ec817c Prefer empty over size 2016-05-03 09:30:56 +02:00
Jørgen Kvalsvik
a7d18cd8df Reindentation. 2016-05-03 09:30:56 +02:00
Jørgen Kvalsvik
de3db110c9 Replace static with anon namespace
This is done to hide symbols such as class definitions in addition to
functions.
2016-05-03 09:30:56 +02:00
Jørgen Kvalsvik
de691c0bd5 Replace ParserState shared_ptr with auto var 2016-05-03 09:30:56 +02:00
Jørgen Kvalsvik
64291e6cca Moved parseState out of Parser; source-file only
This function is not an obvious member of Parser, as it is just as
reliant on ParserState which is source-file private to Parser. Moves to
source file only, without externally-visible private symbol table entry.
2016-05-03 09:30:56 +02:00
Jørgen Kvalsvik
9031ca9406 Make tryParseKeyword/createRawKeyword non-visible
tryParseKeyword and createRawKeyword don't use anything non-public and
does not rely on any non-public parser state, so they are now
implemented as functions private/static in Parser.cpp
2016-05-03 09:19:23 +02:00
Jørgen Kvalsvik
6df67c7de2 Encapsulate getline behaviour onto ParserState
A getline implementation that carries mostly the same assumptions as
istream::getline. Requires ParserState::done() to always be checked (for
negative) to safely retrieve the next line.

Enables tryParseKeywords and friend to only maintain a high level view
of the parsing procedure, and not deal with stream positioning.
2016-05-03 09:19:23 +02:00
Jørgen Kvalsvik
9cf2c9fd98 Formalised stack semantics for input in parser
Moves the storage/lifetime components of ParserState into its own
helper utility class. Splits the implementation responsibility so that
all input data and state is handled by the InputStack, and "global"
information is managed directly by ParserState.
2016-05-03 09:19:22 +02:00
Jørgen Kvalsvik
120a30e94b Replace std::isspace in parser; add \r to is_sep 2016-05-03 09:16:28 +02:00
Jørgen Kvalsvik
07eea89c34 Remove redundant overloads
These overloads were written to allow testing, but with string_view
accepting char* they're unecessary and confusing.
2016-05-03 09:16:28 +02:00
Jørgen Kvalsvik
6b64796d49 Add char* constructor to string_view
Mostly relevant for testing, this enables string_view to work as
expected with string literals.
2016-05-03 09:16:28 +02:00
Jørgen Kvalsvik
cb29336a44 Remove all non-data before parsing begins
Perform a pre-pass over the input and remove everything that isn't
interesting. Preserves empty lines to provide accurate line number for
diagnostics/error output.
2016-05-03 09:16:27 +02:00
Jørgen Kvalsvik
a1ae0e0067 Updated various functions to accept string_view
To take advantage of parser's internal string_view representation of
keyword names, several signatures have been updated to accept
string_view.
2016-05-03 09:16:27 +02:00
Jørgen Kvalsvik
82b1901841 Parser keyword maps uses string_view for keys
The use of string_view for keys allows comparison with keywords from the
file buffers to be compared directly, instead of having to go via
std::string. This removes the need for a series of (inherently)
unecessary copies.
2016-05-03 09:16:27 +02:00
Jørgen Kvalsvik
096e843d08 Moved special-casing of TITLE to RawKeyword
Replaces the special-casing of the TITLE keyword where a terminating
slash is added onto the record with a non-mutating version.
2016-05-03 09:16:27 +02:00
Jørgen Kvalsvik
7d29d63bea Replace string with string_view in inner parser
Several inner parser functions modified to use string_view, to reduce
unecessary copying (and indirectly allocationg) related to passing
strings around.
2016-05-03 09:16:27 +02:00
Jørgen Kvalsvik
1edc6887be Replace parser stringstreams with string_view
Replaces the parser's dependence on streams with string_view, which
won't copy to its internal buffers. Involves hand-rolling std::getline
for string_view to preserve stream-like behaviour.
2016-05-03 09:16:27 +02:00
Jørgen Kvalsvik
e5ee6105b7 Remove parseStream support; strict input reading
Replaces the external stream-support by reading the entire contents of
input files at once, rather than lazily through streams. Uses
stringstreams internally, but keeps the entire file in memory through
std::string

openString/File has been renamed to loadString/File
2016-05-03 09:16:27 +02:00
Jørgen Kvalsvik
4d7f97d322 Refactor ParseState to use explicit stack
Rewrites ParseState to use an explicit stack of open file streams
instead of spawning multiple ParseState objects. While recursion is
*the* most elegant to solve a typical include-file system, the global
nature of eclipse declarations make this clumsy (at best). Instead,
maintain an explicit stack of open files and logically parse the input
as if it was all concatenated into one large file.

Also adds some convenient ways of accessing the current (and
interesting) top of the stack.
2016-05-03 09:15:46 +02:00
Jørgen Kvalsvik
83555a52a1 Minor restructuring in Parser::getKeyword* 2016-05-03 09:15:46 +02:00
Jørgen Kvalsvik
fb8e8b09c1 Parser::applyUnitsToDeck restructured control flow 2016-05-03 09:15:45 +02:00
Jørgen Kvalsvik
cb8e21de01 Restructure createRawKeyword.
Restructures createRawKeyword to use multiple return statements over
if-else and updating variables, reducing indentation to have fewer
contemporary branches.
2016-05-03 09:15:23 +02:00
Jørgen Kvalsvik
bdce26480a createRawKeyword return on unmet preconditions
Changes the control flow of Parser::createRawKeyword to return on
failing to meet preconditions, rather than if-else block. Reduces
indentation and concurrent code paths.
2016-05-03 09:15:23 +02:00
Jørgen Kvalsvik
1330bfc681 parseState use return over break for control flow
Makes the actual effects of the various condtions more clear by
emphasising the return of the function rather than some possible action
after the loop.
2016-05-03 09:15:23 +02:00
Jørgen Kvalsvik
28f297f854 Reduce indentation in parseState
Restructures the per-iteration check of whether or not to continue
parsing to happen first and be an early-break, instead of this flow
being handled by if-else.
2016-05-03 09:15:23 +02:00
Jørgen Kvalsvik
86a5a89429 ParseState early abort over if-else
A small syntactic change that reduces indentation by a level. Checks the
preconditions first and throws if they aren't met (i.e. stream is
broken).
2016-05-03 09:15:23 +02:00