question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add syntax for converting local failure to global failure

See original GitHub issue

Issue type

  • Bug Report: no
  • Feature Request: yes
  • Question: no
  • Not an issue: no

Prerequisites

  • Can you reproduce the issue?: yes
  • Did you search the repository issues?: yes
  • Did you check the forums?: no
  • Did you perform a web search (google, yahoo, etc)?: yes

Description

I think it would be a really powerful extension to the grammar if we were able to convert local failure (as in: failure that happens while parsing an optional (?) or a predicate (&, !)) to a global one. While it might not seem straightforward why this would be useful, in complex grammars (such as one I’m writing now) it becomes an invaluable tool.

I took the idea from the PEGTL parsing library. There is a rule called must<>, which, when present, will immediately throw an exception when the rule inside it didn’t match.

Technical details:

I propose a new operator (#), that, when present, compiles to a matcher with a throw-statement instead of one that just pushes FAILED onto the stack. I have already made a prototype that seems to work on most trivial use-cases, and will file a pull request right away.

Example code:

VariableDefninition = VarToken __ name:#Identifier __ #"=" __ #Expression

Expected behavior:

Whenever a VarToken (e.g. “var”) is encountered, it will try to parse the identifier, an equality sign, and an expression. Whenever any of these fail, the parser will throw an error (indicated by the #-symbol), even when VariableDefinition occurs in a predicate or an optional.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
polkovnikov-phcommented, Dec 10, 2018

PEG grammars are usually written without any lexer. In a case when lexeme couldn’t be parsed, it’s a global failure. PEG grammars would nevertheless try several other rules before failing to parse the string. The feature to make a non-backtrackable failure is thus useful. It’s also available in boost::spirit as atom<>.

The problem is that it’s a dirty hack. There’s a whole variety of dirty hacks (e.g. skipper grammars and lexeme<> rule), and assigning one of the very limited one-symbol combinations to them is not a good idea.

I’d rather recommend to figure out another long requested feature, rules parameterized with other rules, and just use something in lines of atom(p) = p / &{ error('Forced failiure'); } here.

0reactions
polkovnikov-phcommented, Dec 13, 2018

Several years ago I tried to add it to PEG.js, but it turned out way harder than I thought and I abandoned idea. Probably I should try it once more too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conversion failed when converting date and/or time from ...
Hello,. SSIS package fails with the above conversion error only on one of the server. when tried locally or on a different server, ......
Read more >
Conversion failed when converting date and/or time from ...
Insert Into MyTable(MyDate) Values ('2015-02-29');. The SQL server will throw the following error: Conversion failed when converting date and/or time from ...
Read more >
BuiltIn - Robot Framework
Documentation. Converts the given item to a binary string. The item , with an optional base , is first converted to an integer...
Read more >
Ltac — Coq 8.16.1 documentation - The Coq Proof Assistant
Example: Substitution of global and local symbols. Goal True. ... 1; Fail idtac n. The command has indeed failed with message: n not...
Read more >
10 Handling PL/SQL Errors
Errors could also occur at other times, for example if a hardware failure with disk ... Because a block can reference only local...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found