Charles Baker
5e01cd323e
Leave the RHS of a GrammarSymbolSet move default initialized
...
Previously the RHS was left as it was when, technically, it should be
restored to its default initialized state. This fix exchanges the
RHS GrammarSymbolSet values with their default initialized values to
correct that error.
2024-07-15 21:34:11 +12:00
Ilusha
4e000f92ef
Add Cmake targets
2024-07-14 17:07:43 +12:00
elushaX
efde50b76c
Fix GrammarSymbolSet's move and copy constructors
2024-07-14 17:07:00 +12:00
Charles Baker
7267c0a137
Build with Forge v0.9.7
2024-07-14 16:55:25 +12:00
Charles Baker
e5baa3920b
Merge branch 'error-on-empty-or-unterminated-literal-or-regex'
2023-07-16 18:18:00 +12:00
Charles Baker
7b1a3ab372
Test errors reported for empty literals and regular expressions
2023-07-16 18:15:49 +12:00
Charles Baker
919b0fe36b
Improve parser tests that check for errors
2023-07-16 18:15:49 +12:00
Charles Baker
638de559ca
Report errors for unterminated regular expressions
2023-07-16 18:15:49 +12:00
Charles Baker
b2224991c9
Advance position when encountering an unterminated literal
2023-07-16 18:15:49 +12:00
mingodad
031419b0cf
Add an error message for empty literal/regex declarations, also fix to accept "'\''" literal.
2023-07-16 18:15:49 +12:00
Charles Baker
6ab3cd01d3
Escape whitespace directive correctly in lalr_calculator_example.cpp
2023-07-16 18:15:45 +12:00
Charles Baker
eafaf02786
LINT: Remove trailing whitespace from lalr_examples.forge
2023-07-16 18:15:21 +12:00
Charles Baker
c0b8bd0bb5
Also check for a valid parser state machine in Parser::valid()
2023-07-16 15:35:11 +12:00
Charles Baker
4881754402
Avoid initializing Parser with invalid ParserStateMachine
...
When a grammar fails to generate a parser the ParserStateMachine has a
null start state. When this is passed to construct a Parser quietly
avoid creating any parser specific state, esp. ParserNode which will
assert if passed a null state.
2023-07-16 15:35:04 +12:00
mingodad
4ba3456df4
Reuse result of already called function.
2023-07-16 15:33:17 +12:00
mingodad
7f1ea72807
Reorder class member for better memory usage/alignment.
2023-07-16 15:32:33 +12:00
mingodad
a807827db8
Add preprocessor guards to allow build without threads/threadpool.
2023-07-16 15:31:44 +12:00
Charles Baker
3d1351c555
Add column information to errors
2023-07-16 15:30:55 +12:00
Charles Baker
d0baae1ccd
LINT: Formatting around adding columns to errors in Grammar.[ch]pp
2023-07-16 15:29:53 +12:00
Charles Baker
eb228024db
Calculate line and column inside GrammarParser::error() for simplicity
2023-07-16 15:29:53 +12:00
mingodad
29d91e8ec8
Add column info to GrammarSymbol and error messages
2023-07-16 15:29:53 +12:00
mingodad
16ebbc5683
Add column info to error messages in ErrorPolicy
2023-07-16 15:29:53 +12:00
mingodad
4aca034e26
Add 'std::' in several places as suggested by clang
2023-07-15 14:20:07 +12:00
Charles Baker
aeacb29cb2
Fix maximum calculation in GrammarSymbolSet::insert()
...
Fixes #36 "Improve performance of GrammarSymbolSet". Not reproduced
exactly because I didn't have the grammar to hand but it seems likely
this is the problem.
2023-06-08 05:24:01 +12:00
Charles Baker
b0a6fb6b24
Track and iterate only over set range in GrammarSymbolSet
...
FIX: Iterate over all elements when combining sets
2023-06-03 11:53:31 +12:00
Charles Baker
b72f97e34d
Use size_t for set elements in GrammarSymbolSet
2023-06-03 11:53:30 +12:00
Charles Baker
93160d6200
Avoid creating temporary strings adding symbols to Grammar
2023-06-03 11:52:52 +12:00
Charles Baker
6821f786b6
Add character encoding examples and documentation, e.g. parsing UTF-8
2023-06-03 11:50:15 +12:00
Charles Baker
e346baf911
Update README.md to describe parsing with different encodings
2023-06-03 11:45:55 +12:00
Charles Baker
071273032e
Update XML example to parser from UTF-8 to UTF-8 in memory
2023-06-03 11:45:55 +12:00
Charles Baker
0dc846f6eb
Update JSON example to parse from a UTF-8 encoded JSON file
...
This is an example of using Lalr to parse UTF-8 encoded input.
2023-06-03 11:45:55 +12:00
Charles Baker
d03a02d3e5
Use correct string for lexeme when debugging parsers
...
This works for UTF-8 encoded strings but debugging will fail when using
UTF-16 or UTF-32 as the printf() formatted string won't deal with null
characters embedded within the wider character encodings.
Committing this for now because it doesn't break any existing
functionality but does enable parsing of wider character inputs.
2023-05-29 21:20:23 +12:00
Charles Baker
1f85c9d00a
Explicitly link with pthread on Linux
2023-05-28 20:49:51 +12:00
Charles Baker
3d31f45a0f
Update lalr_examples/json.cpp now that arrays are parsed.
2023-05-28 20:46:43 +12:00
Charles Baker
9ce34162d1
Inline trivial methods in parser generator
2023-05-28 20:46:43 +12:00
Charles Baker
1f572973c3
Reduce memory usage by omitting labels in normal parsers
...
Labels are only used to add meaningful text to states in Graphviz DOT
graphs. But these strings can take lots of time and memory to generate
especially in large grammars like that for PostgreSQL. Therefore only
generate labels when they will be used.
2023-05-28 20:45:44 +12:00
Charles Baker
c7eea3b698
Reduce memory usage by removing vector from GrammarSymbolSet
2023-05-28 20:45:44 +12:00
Charles Baker
c9a6a297bf
Sanitize parser state labels
2023-05-28 20:45:44 +12:00
Charles Baker
a5db5713da
Remove unused GrammarSymbolLess
2023-05-28 20:45:44 +12:00
Charles Baker
faaafdcef6
Remove GrammarProduction pointer from GrammarItem
2023-05-28 20:45:44 +12:00
Charles Baker
9d90804ae2
Use a vector of active GrammarStates to track new states
...
The previous algorithm would loop through all states but only process
those that didn't have their processed flag set. Much faster to only
iterate through those states that haven't been processed.
2023-05-26 22:07:34 +12:00
Charles Baker
ebe173cb12
Parse arrays in the JSON example
2023-05-26 21:53:01 +12:00
Charles Baker
c5a7c1728d
Generate errors for missing lexical action handlers
2023-05-21 21:00:37 +12:00
Charles Baker
77602f9052
Test that parsers with missing lexical action handlers generate errors
2023-05-21 20:15:29 +12:00
Charles Baker
d8948dd936
Report missing action handlers from Parser::valid()
2023-05-21 20:15:12 +12:00
Charles Baker
184a8b34c0
Report missing lexical action handlers from Lexer::valid()
2023-05-21 20:04:14 +12:00
Charles Baker
e56556f390
Move Parser::fire_{error,print}() and Parser::is_debug_enabled() to const member section
2023-05-21 20:03:36 +12:00
Charles Baker
b7b7c4d61e
Move Lexer::set_action_handler() to non-const member section
2023-05-21 19:53:56 +12:00
Charles Baker
5ce357e651
Treat empty character classes in a regular expression as an error
2023-05-20 22:15:47 +12:00
Charles Baker
aaea898aab
Allow most metacharacters in character classes, e.g. allow "[+-]"
...
Allows most metacharacters, e.g. "*+()[", to appear unescaped within a
character class. This, along with hyphens at the end, allows "[+-]" to
match a plus or a minus.
2023-05-20 22:15:47 +12:00