Maurice Makaay
5904da9677
Added some package docs.
2019-06-18 22:52:17 +00:00
Maurice Makaay
2293627232
Small code cleanup things, mainly backing up the changes.
2019-06-18 15:46:09 +00:00
Maurice Makaay
99654c2f9e
Simplified some internal code, which also fixes a bug with correct error reporting from within parsekit in various edge cases.
2019-06-17 13:59:31 +00:00
Maurice Makaay
cdfc4ce52c
More documentation and examples.
2019-06-12 16:17:13 +00:00
Maurice Makaay
1a280233b0
Got rid of the testify dependency. My testing needs are so basic, that there's no need for this full fledged testing library.
2019-06-12 15:25:15 +00:00
Maurice Makaay
cef6ae1bc4
Working on documentation.
2019-06-12 15:24:09 +00:00
Maurice Makaay
27c97ae902
Big overhaul on separating packages for code containment.
2019-06-12 14:30:46 +00:00
Maurice Makaay
1f0e0fcc17
Splitting up functionality in packages, intermediate step.
2019-06-11 22:23:30 +00:00
Maurice Makaay
0f7b4e0d26
Added a few syntactic sugar methods for ParseHandler.
2019-06-11 09:09:41 +00:00
Maurice Makaay
65895ac502
Making parsekit.reader both simpler and more complex (more complex by adopting some buffer allocation logic from the built-in bytes package, to not be copying memory all the time during the read operations.
2019-06-09 21:55:01 +00:00
Maurice Makaay
9656cd4449
The parsekit.reader.Reader now caches error messages that are returned from
...
the embedded io.Reader. When an error is returned, the read offset and the
error are stored. When later on, the same of a higher offset is requested,
the error is returned again. This way the code will work for Readers that do
not repeatedly return the correct error when calling the Read() method
multiple times arter a first error has occurred.
Note: I am not sure if there are any Reader implementations that wouldn't
return the same error message over and over again, but hardening the
parsekit Reader to support this is not hard, so let's just go for it.
2019-06-09 19:42:20 +00:00
Maurice Makaay
76336e883e
Removed the use of Error.Full(). The default Error() method now includes the extra data from Full() (line and column offset)
2019-06-09 15:20:44 +00:00
Maurice Makaay
add28feb33
In the spirit of Go, slimmed down the ParseAPI interface. I'm no longer using ParseAPI.On(..).<DoSomething>(), but now it's simply ParseAPI.<DoSomething>(). I also dropped the difference between a Stay() and an Accept(). All that is possible now is ParseAPI.Peek() and ParseAPI.Accept().
2019-06-09 10:25:49 +00:00
Maurice Makaay
9f5caa2024
Backup work.
2019-06-08 22:48:56 +00:00
Maurice Makaay
05ae55c487
Brought the examples up-to-date with the lateset code. All are working correctly now.
2019-06-07 16:20:32 +00:00
Maurice Makaay
40bad51064
Improvement a few TokanHandlers by letting them make use of the new MatchRuneByCallback method, instead of having them implement their own logic.
2019-06-07 15:57:53 +00:00
Maurice Makaay
9a5bf8b9af
Further code cleaning for the interaction between ParseAPI and TokenAPI. Extra atoms added, also one based on a callback which can accept single runes based on thhat callback function.
2019-06-07 15:48:49 +00:00
Maurice Makaay
98d2db0374
Moved Reader into its own package.
2019-06-07 10:55:55 +00:00
Maurice Makaay
6d92e1dc68
Merged functionality of p.Expects(string) and p.UnexpectedInput().
...
It is now simply p.UnexpectedInput(string). This makes the naming
of unexpected input not as magical, but explicit (which is a GoodThing).
With one of the earlier incarnations of parsekit it did make sense,
but it went in a way in which explicit is more idiomatic for the package.
2019-06-07 07:56:24 +00:00
Maurice Makaay
3094b09284
Adding documentation and getting the interactions between ParseAPI and TokenAPI cleaned up a bit.
2019-06-07 07:26:41 +00:00
Maurice Makaay
c0389283bd
Added input check for MatchIntegerBetween()
2019-06-05 22:21:34 +00:00
Maurice Makaay
3d791233e0
Added a lot of IP-address-related TokenHandlers, so we can now process IPv4 addresses, IPv6 addresses, CIDR netmasks, IPv4 dotted quad netmasks, IPv4Net (ipv4 + mask) and IPv6Mask (ipv6 + mask).
2019-06-05 22:16:09 +00:00
Maurice Makaay
05585db341
Normalizing error handling, to always include the caller location in errors. This makes debugging a lot easier for users of the package, because it doesn't say stuff like 'Method() was called incorrectly', but instead something like 'Method() was called incorrectlty at /path/to/file.go:1234'.
2019-06-05 10:07:50 +00:00
Maurice Makaay
75373e5ed5
Big simplification run once more, cleaned up code, added tests and examples, made stuff unexported where possible, to slim down the exported interface.
2019-06-04 23:15:02 +00:00
Maurice Makaay
4580962fb8
Backup a load of work on typed token support, making it easy to produce tokens directly from parser/combinator-based parsing rules.
2019-06-04 00:03:08 +00:00
Maurice Makaay
21f1aa597c
Made the panic() calls (which basically indicate parser implementation bugs) more useful by referencing from where illegal calls were made.
2019-05-29 07:24:27 +00:00
Maurice Makaay
2fa5b8d0f4
OCD ..OCD ...OCD ...
2019-05-29 00:01:24 +00:00
Maurice Makaay
1e7ec7553a
Tiny fix in variable naming, because the test had grown in a different direction.
2019-05-28 23:59:02 +00:00
Maurice Makaay
e1534f678e
Simplified calculator 2 example.
2019-05-28 23:51:19 +00:00
Maurice Makaay
11883b06ac
Added a unit test for the actual parser loop issue that I ran into myself. This one will not bite me again!
2019-05-28 23:13:28 +00:00
Maurice Makaay
d31d09abf0
Added crude loop protection to the parser, which should prevent parsers running in circles (happened to me a few times too).
2019-05-28 23:01:23 +00:00
Maurice Makaay
7aff3fc43e
Added a nice example that shows how a []string-based type can be turned into a parser that fills its own slice elements during parsing.
2019-05-28 14:38:04 +00:00
Maurice Makaay
2d851103e5
Cleanup of stuff that I don't need anymore, because it has been fully deprecated. Also added some tests for panic() calls in parsekit, which brings test coverage to 100%. It's not a goal as such, but it's good to know that I got there without cheaty tests :)
2019-05-28 13:41:58 +00:00
Maurice Makaay
3dfa99c965
Modified all examples and tests to make use of the new ideas on how to keep parsing state. After this commit, I can cleanup a lot of stuff from the emitting loop-based parser which was basically crap for complex parsers.
2019-05-28 10:42:46 +00:00
Maurice Makaay
980c18099e
A small change to the computation interpreter to get rid of one useless level of recursion.
2019-05-28 07:26:50 +00:00
Maurice Makaay
41f8733e99
Pfff, okay, so today I found a rather nice way of writing a parser that can hold some internal state, while stell holding on to the basic principle of having a function signature the applies to every parse handler in the system. By using methods instead of stand-alone functions, it is possible to let the accompanying struct hold on to the required state. Implemented this principle for the two calculator example projects. The rest is quite broken now, sorry :-p
2019-05-27 23:24:07 +00:00
Maurice Makaay
f7d1e28fa1
Dropped the whole channel support for the parser internals. It seems a nice idea to work with, but it's hard to predict how much buffering the channel should have to make all parsers work. When the buffer is too small, then a StateHandler that emits more items than can be buffered will end up in a deadlock and stall the application. It is easy enough to replace the channel with a slice of Items, so I did.
2019-05-26 11:32:45 +00:00
Maurice Makaay
d0d12dae22
Added a new example, yet another hello world.
2019-05-26 10:15:34 +00:00
Maurice Makaay
c6fde2cf4e
A big round of getting-ya-terminology-straight.
2019-05-26 09:25:34 +00:00
Maurice Makaay
2751c78003
Got rid of the full On()...etc chains for both code clarity and usability clarity. Working on good examples and shaving the API's accordingly.
2019-05-25 22:53:04 +00:00
Maurice Makaay
b0cd017b83
Removed old file.
2019-05-25 15:22:06 +00:00
Maurice Makaay
bb1e462892
Ah, found a good way to document larger examples which need function definitions and such. Let's see if this works in godoc nicely.
2019-05-25 14:37:38 +00:00
Maurice Makaay
8a6815332e
Example extended.
2019-05-24 23:55:10 +00:00
Maurice Makaay
e9c618580d
Example extended.
2019-05-24 23:53:04 +00:00
Maurice Makaay
723e2a0c38
Added complete example for a parser.
2019-05-24 23:41:47 +00:00
Maurice Makaay
070a215ac3
More documentation example testing.
2019-05-24 21:34:54 +00:00
Maurice Makaay
3e87e010fb
Banged some sense into the constructors. Instead of one convulated parsekit.New(), we now have parsekit.NewParser() and parsekit.NewMatcherWrapper(). ALso playing with adding examples to the documentation.
2019-05-24 20:50:31 +00:00
Maurice Makaay
6fe3c16a6d
Added some more modifiers (ModifyReplace and ModifyByCallback).
2019-05-24 15:57:54 +00:00
Maurice Makaay
c164f320cb
Implemented P.ExpectEndOfFile() and shortened some parser/combinator functions (since Go-people seem to like that better than a somewhat longer descriptive name)
2019-05-24 13:59:01 +00:00
Maurice Makaay
6ad4499971
Backup work, created a lot of tests for parser combinators and atoms. Pretty solid now!
2019-05-24 12:41:34 +00:00