petitparser

Dart PetitParser to get at AST datastructure created with ExpressionBuilder

孤街浪徒 提交于 2020-12-13 04:52:28
问题 I'm new to petitparser, but it looks like it's the sonic screwdriver of parsers. For my first project, I'm building code to parse a simple expression that builds an AST tree of my Node objects, then walks that tree with a few rules to minimize the unneeded parens. I don't know what to pass to the output of .parse() (seems to be a Result) to get access to the tree I defined, so I can call .visit() on the top of the AST. Any ideas? class RIPParser { Parser _make_parser() { final builder =

Dart PetitParser to get at AST datastructure created with ExpressionBuilder

我的梦境 提交于 2020-12-13 04:51:28
问题 I'm new to petitparser, but it looks like it's the sonic screwdriver of parsers. For my first project, I'm building code to parse a simple expression that builds an AST tree of my Node objects, then walks that tree with a few rules to minimize the unneeded parens. I don't know what to pass to the output of .parse() (seems to be a Result) to get access to the tree I defined, so I can call .visit() on the top of the AST. Any ideas? class RIPParser { Parser _make_parser() { final builder =

How to define Pascal variables in PetitParser

半世苍凉 提交于 2019-12-23 11:52:53
问题 Here is the (simplified) EBNF section I'm trying to implement in PetitParser: variable :: component / identifier component :: indexed / field indexed :: variable , $[ , blah , $] field :: variable , $. , identifier What I did was to add all these productions (except identifier ) as ivars of my subclass of PPCompositeParser and define the corresponding methods as follows: variable ^component / self identifier component ^indexed / field identifier ^(#letter asParser, (#word asParser) star)

Is there a math parser for petitparser?

半世苍凉 提交于 2019-12-11 11:58:22
问题 is there a dart lib that can parse math strings such as (3+4)/4.5 ? I tried to build a basic parser with petitparser, but I am in over my head and its just trial and error right now :) Is there an petitparser (Dart or any other language) implementation of a simple math parser somewhere? 回答1: The introductory tutorial of PetitParser for Dart explains building a simple expression grammar in the section "Writing a More Complicated Grammar". There is a more complicated expression grammar in the

How to match the start and end of a block

随声附和 提交于 2019-12-11 08:22:35
问题 I want to define a special code block, which may starts by any combination of characters of {[<# , and the end will be }]># . Some example: { block-content } {## block-content ##} #[[<{### block-content ###}>]]# Is it possible with petitparser-dart? 回答1: Yes, back-references are possible, but it is not that straight-forward. First we need a function that can reverse our delimiter. I came up with the following: String reverseDelimiter(String token) { return token.split('').reversed.map((char)

PetitParser evaluator not working properly

夙愿已清 提交于 2019-12-11 07:29:55
问题 when I try running this code on pharo, my answers are somewhat off. I try evaluating 1-2+3 but for some reason, it does 1- (2+3) and I do not understand why this is so. Thanks for your time. number := #digit asParser plus token trim ==> [ :token | token inputValue asNumber ]. term := PPUnresolvedParser new. prod := PPUnresolvedParser new. term2 := PPUnresolvedParser new. prod2 := PPUnresolvedParser new. prim := PPUnresolvedParser new. term def: (prod , $+ asParser trim , term ==> [ :nodes |