ambiguity="explicit" returns None
See original GitHub issueDescribe the bug
When I set ambiguity=“explicit”, it returns None when parsing. Not setting it makes it parse normally
To Reproduce
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Initial author: Bryan Hu.
The main program that will run.
"""
from pathlib import Path
import lark
here = Path(__file__).parent
lark_grammar = Path(here / "grammar.lark")
parser = lark.Lark(lark_grammar.read_text(), ambiguity="explicit")
DOC = R"""
func main (argv:List<Str>, argc: int) {
obj Greeter {
private var _name
var name: property<Str>
func init(name: str) -> Void {
self._name = name
self.name = property(
get=(func() -> Str {return self._name})
)
}
func __str__() -> Str {
return "hello, " + self._name
}
}
if not (len(argv) > 1) {
print("You gotta give me a name")
} else {
var maing: Greeter = Greeter(argv[1])
print(maing)
}
}
"""
print(parser.parse(DOC).pretty())
And the very ambiguous, nondeterministic grammar (still trying to reduce ambiguity):
%import common.WS
%import common.NEWLINE
%import common.CNAME -> IDENTIFIER
%import python.STRING
%import common.SIGNED_NUMBER -> NUMBER
%import common.SH_COMMENT -> COMMENT
%ignore WS
%ignore ";"
%ignore NEWLINE
%ignore COMMENT
start: _statement+
////////////////////////////////////////////////////////////////
_statement: _definition | _operation | _ifs
////////////////////////////////////////////////////////////////
_definition: function_definition | class_definition | variable_definition
// FUNCTION //
function_definition: "func" IDENTIFIER "(" [_sequence{functype, ","}] ")" ["->" _type] braced_code
anonymous_func: "(" "func" "(" [_sequence{functype, ","}] ")" ["->" _type] braced_code ")"
// VARIABLE //
?variable_definition: ("var"|"const") IDENTIFIER ((":" _type) | ([":" _type] "=" value))
// CLASS //
class_definition: "obj" IDENTIFIER [":" NAMESPACABLE] class_code
class_code: "{" (class_defs | _statement)+ "}"
?class_defs: meth_def | class_var_def
?meth_def: [PRIVATE|PUBLIC] function_definition
class_var_def: [PRIVATE|PUBLIC] variable_definition
PRIVATE: "private"
PUBLIC: "public"
////////////////////////////////////////////////////////////////
_operation: _binary | _logic | _misc | value
// BINARY //
_binary: add
| sub
| div
| mul
| bor
| band
| bnot
| bxor
add: _bop{"+"}
sub: _bop{"-"}
div: _bop{"/"}
mul: _bop{"*"}
bor: _bop{"|"}
band: _bop{"&"}
bnot: "!" _operation
bxor: _bop{"~"}
// LOGIC //
_logic: gt
| lt
| eq
| not
| and
| or
gt: _bop{">"}
lt: _bop{"<"}
eq: _bop{"=="}
and: _bop{"and"}
or: _bop{"or"}
not: "not" _operation
// MISCELLANEOUS //
_misc: assign | return | index | call_op
assign: _bop{"="}
return: "return" [_sequence{value, ","}]
index: value "[" value "]"
call_op: (NAMESPACABLE|anonymous_func) "(" [arguments] ")"
//! PRIVATE !//
_bop{thing}: value thing _operation
arg.2: [IDENTIFIER "=" ] value
arguments: _sequence{arg, ","} // To prevent clashing with assignment
// FILLER: "..."
////////////////////////////////////////////////////////////////
_ifs: if (elif)* else?
?if: "if" value braced_code
?elif: "else" if
?else: "else" braced_code
////////////////////////////////////////////////////////////////
?value: NAMESPACABLE
| STRING
| NUMBER
| BOOLEAN
| anonymous_func
| paranthesised
| _operation
NAMESPACABLE: /[a-zA-Z_]+(?:\.[0-9a-zA-Z_]+)*/
BOOLEAN: "true" | "false"
braced_code: "{" _statement+ "}" // TODO USE INDENT-BASED
_type: NAMESPACABLE | generic_type
generic_type: NAMESPACABLE "<" _type ">"
functype: (IDENTIFIER ":" _type) ["=" value]
paranthesised.2: "(" value ")" // Will clash with call-op
_sequence{x, sep}: x (sep x)* sep?
Terminal output:
Traceback (most recent call last):
File "__main__.py", line 40, in <module>
print(parser.parse(DOC).pretty())
AttributeError: 'NoneType' object has no attribute 'pretty'
If that is impossible, provide clear steps to reproduce the behavior.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
c# - How to resolve ambiguity when argument is null?
How to resolve it since I can't explicitly convert null to any of those classes? static void Main(string[] args) { Func(null); } ...
Read more >Automatically know that the function returns None if there is no ...
If you have a function with no arguments, there would be ambiguity around a function returning None and a function without a type...
Read more >PEP 484 – Type Hints - Python Enhancement Proposals
When the type of a value is object , the type checker will reject almost all operations on it, and assigning it to...
Read more >8.11 — Function overload resolution and ambiguous matches
If the compiler finds multiple matches in a given step, an ambiguous function call will result. This means no match from a given...
Read more >Ambiguity and Insecurities with Three-Way Comparison
Template non-type argument equality is ambiguous; it fails to specify the strength of the equality. Since this ambiguity affects the application binary ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You fixed it. Yep.
I have a fix for this. I’ll open a PR shortly.