-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic parselets #10
Comments
Sounds like a cool feature, but what benefits does this have over passing parselets to a function? I mean specifically for tokays use case, which I thought of more as a scripting language, and thus having things work dynamically makes more sense to me. |
Tokay programs are executed in two stages:
I hope this clarifies things a bit. |
Commit fffeeda integrates the complete syntax for generic parselets and instances of generic parselets already. The generics feature is still pending, as further internal revisions are required. |
Parselets could be defined as generics when constant consumables are marked for being replaceable at a parselet's usage, which duplicates the parselet for the specific consumable.
Draft
The idea for generic parselets is to allow for replaceable constants defined with a special
<...>
-notation.The constants are held and replaced during compile-time, and turned into specific VM instructions on demand of their usage.
Definition
Generic is a generic parselet with the replaceable constants
P
,Q
andr
, whereP
andQ
are consumables, andQ
has_
-whitespace pre-defined,r
has constant0
pre-defined.Usage
These are example calls.
Builtin generics
Some generics should be available as built-ins, and could replace the current implementation eg of
Until : @<P, Escape: Void>
The Until-parselet could be a generic built-in parselet to parse data until a specific token or parselet occurs.
'"' Until<'"', Escape: '\\'> '"'
parse strings like"Hello World"
or with escape sequences like"Hello\nWorld"
String: @<Start, End: Void, Escape: Void>
Until<Not<Char<A-Za-z_>]>>
parse anything consisting not ofChar<A-Za-z_>
Until<EOF>
read all until EOFLine
built-in #38 refers to aLine
parselet for matching input linesRepeat : @<P> min=1, max=0
This is a simple programmatic sequential repetition. For several reasons, repetitions can also be expressed on a specialized token-level or by the grammar itself using left- and right-recursive structures, resulting in left- or right-leaning parse trees.
Used by optional, positive and kleene modifiers.
Replacement for current repeat-construct.
Not : @<P>
This parser runs its sub-parser and returns its negated result, so that an accept becomes
rejected and vice-versa.
Replacement for current not-construct.
Peek : @<P>
This parselet runs P and returns its result, but resets the reading-context afterwards. It can be used to look ahead parsing constructs, but leaving the rest of the parser back to its original position, to decide.
Due to Tokays memorizing features, the parsing will only be done once, and is remembered.
Replacement for current peek-construct.
Expect : @<P> msg=void
This constructs expects P to be accepted. On failure, an error message is raised as Reject::Error.
Replacement for current expect-construct.
List : @<P, Separator: ',', empty: true>
Parse a separated list.
Keyword : @<P>
Parses a keyword, which is a consumable not followed by any alphabetic letter.
Definition
Example
User-defined generics
Example use-case is this grammar draft for Tokay's own REPL itself. It implements a generic
Set
parselet which can be used by different switches, allowing for feature enabling-/disabling like#debug
,#debug on
or#debug off
.The text was updated successfully, but these errors were encountered: