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.

Grammar is case sensitive?

See original GitHub issue

I’m currently experimenting with lark, and am attempting to run the following code:

from lark import Lark

grammar = '''
    Stmt: "foo"
'''

parser = Lark(grammar, start='Stmt')

This results in the following exception:

Traceback (most recent call last):
  File "C:\Python35\lib\site-packages\lark\parsers\lalr_parser.py", line 31, in get_action
    return states_idx[state][key]
KeyError: 'RULE'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tester.py", line 81, in <module>
    parser = construct_parser(grammar, root)
  File "tester.py", line 77, in construct_parser
    return Lark(lark_grammar, start=root)
  File "C:\Python35\lib\site-packages\lark\lark.py", line 143, in __init__
    self.grammar = load_grammar(grammar, source)
  File "C:\Python35\lib\site-packages\lark\load_grammar.py", line 537, in load_grammar
    tree = self.simplify_tree.transform( self.parser.parse(grammar_text+'\n') )
  File "C:\Python35\lib\site-packages\lark\parser_frontends.py", line 31, in parse
    return self.parser.parse(tokens)
  File "C:\Python35\lib\site-packages\lark\parsers\lalr_parser.py", line 60, in parse
    action, arg = get_action(token.type)
  File "C:\Python35\lib\site-packages\lark\parsers\lalr_parser.py", line 35, in get_action
    raise UnexpectedToken(token, expected, seq, i)
lark.common.UnexpectedToken: Unexpected token Token(RULE, 'tmt') at line 2, column 6.
Expected: dict_keys(['_COLON'])
Context: <no context>

However, when I convert the phrase Stmt to stmt, the grammar starts working.

Is this behavior intentional? I didn’t see anything in the documentation about this (unless I missed it?) and as far as I’m aware, both grammars are valid EBNF grammars – the casing of the non-terminals and terminals should be irrelevant (at least, according to the EBNF specification on wikipedia).

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
erezshcommented, Mar 26, 2020

No. You can open an issue with that feature request.

1reaction
erezshcommented, Nov 15, 2017

If you mean the terminal values, then yes, of course. You do it by adding “i” to the end of the string or regexp.

Examples:

HELLO: "hello"i   // Match HELLO, Hello, hello, etc.
REGEXP: /this is [also] case? insensitive/i

You can mix them too:

some_rule: "Case Sensitive"  "insensitive"i  "Sensitive again"

Does that answer you question?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Case-sensitive definition and meaning
In computing, if a written word such as a password is case-sensitive, it must be written in a particular form, for example using...
Read more >
CASE-SENSITIVE definition | Cambridge English Dictionary
case -sensitive meaning: 1. If a computer program is case-sensitive, it can recognize if a letter is a capital or a small…. Learn...
Read more >
case grammar
adj. relating to or denoting a case in some languages of nouns, pronouns, and adjectives, expressing location. ... n. (t… Case-sensitive , case-sensitive...
Read more >
Case Sensitive: how english grammar got good eBook : ...
Case Sensitive : how english grammar got good - Kindle edition by Jacobs, Robert. Download it once and read it on your Kindle...
Read more >
case-sensitive
case -sensitive meaning, definition, what is case-sensitive: a case-sensitive computer program recogn...: Learn more.
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