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.

Isn't this a terminal?

See original GitHub issue

What is your question?

I have a rule, defined as

_foo: ":"
    | "=>"
    | "->"
    | "="

Which I am pretty sure it can be a terminal. But it can’t

If you’re having trouble with your code or grammar

My working grammar where it is a rule:

%import common (WS_INLINE, NUMBER, NEWLINE)
%import common.CNAME
%import python (STRING, LONG_STRING, HEX_NUMBER, OCT_NUMBER, BIN_NUMBER, IMAG_NUMBER)
%ignore WS_INLINE
%declare _INDENT _DEDENT
_NL: /(\r?\n[\t ]*)+/
start: _NL* module+
module: ("mod" | "module") name ":" _block{container}
_block{x}: _NL _INDENT x+ _DEDENT
?container: dict | list

list: "[" _hang_sep{value, ","} "]"
    | _block{_hang_sep{_list_thing, _NL}}
_list_thing: ("*"|"+"|"-") value

dict:  _hang_sep{key_value, _NL}+
    | "{" _hang_sep{key_value, ","} "}"
key_value: name _kv_char value
_kv_char: ":"
        | "=>"
        | "->"
        | "="

?raw_value: name
         | NUMBER
         | HEX_NUMBER
         | OCT_NUMBER
         | BIN_NUMBER
         | IMAG_NUMBER
         | TIME
         | ENUM

ENUM: /:[\d\w]+/

?value: raw_value
      | container
// Don't read this messy regex (in Atom, the syntax highlighting breaks ;-;)
// Taken from here: https://stackoverflow.com/a/3143231, https://stackoverflow.com/a/37742, and https://stackoverflow.com/a/37767
TIME: /(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+)|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d)|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d)/
    | /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/
    // | /^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1\d|0?[1-9]))([-./])(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/

_sep{x, sep}: x ("," x)*
_hang_sep{x, sep}: _sep{x, sep} sep?
?name: ["t"] LONG_STRING
    | STRING
    | CNAME

The (also working) Python code:

from pathlib import Path
from typing import List

import lark
import lark.indenter

here = Path(__file__).parent


class Indenter(lark.indenter.Indenter):
    NL_type = "_NL"
    OPEN_PAREN_types: List[str] = []
    CLOSE_PAREN_types: List[str] = []
    INDENT_type = "_INDENT"
    DEDENT_type = "_DEDENT"
    tab_len = 4


grammar = lark.Lark(
    here.joinpath("grammar.lark").read_text(),
    postlex=Indenter(),
    parser="lalr",
)



DOC = """

mod 'test':
    foo: bar
    python:
        - is
        * the
        + best
        - you: know
    'but!!!': '''This is a configuration lang!'''


"""
print(parse.grammar.parse(DOC).pretty())


But if you change that single line where the rule is defined, it breaks.

Provide a small script that encapsulates your issue.

Explain what you’re trying to do, and what is obstructing your progress.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
MegaIngcommented, Mar 20, 2021

To quote you:

It might be possible to fix, but it certainly won’t be easy. I can try to split the offending state just before creating the parse table, according to information from the lexer, and fix all the pointers to it.

Or LALR(2).

And the problem here isn’t a conflict between two regex, but between a regex and a string.

But yes, I will work on interegular a bit more soon.

1reaction
MegaIngcommented, Mar 20, 2021

Can you in future try and create minimal grammars and scripts? Just try to take away stuff and see when it no longer breaks. That you now what exact section the problem is.

In this case the problem is the automatic terminal collision resolving between ":" and _KV_CHAR, which means that when _KV_CHAR matches :, the terminal that is generated is actually a COLON. This is a limitation of the contextual lexer, and can’t be fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

StdErr from ShellExec, stty: stdin isn't a terminal #14938 - GitHub
When I try to run a cell in a Jupyter notebook, I get the following error: StdErr from ShellExec, stty: stdin isn't a...
Read more >
The Unresponsive Terminal - Learning the UNIX ... - O'Reilly
A session can be hung for several reasons. One of the most common is that the connection between your terminal and the computer...
Read more >
Terminal isn't working... : r/GTFO - Reddit
Terminal isn't working... So i tried walking away from the terminal and then coming back to the terminal and it just doesnt work....
Read more >
Customer reviews: Adolescence Isn't Terminal
"Adolescene Isn't Terminal" by Kevin Leman is full of interesting insights and conclusions on how parents can survive the teenage years.
Read more >
Troubleshoot Terminal launch failures - Visual Studio Code
Bad shell names, arguments, or environment variables can cause the terminal to not launch. Keep this log for later if your problem isn't...
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