#!python
from pypeg2 import Keyword, K, Enum, attr, optional, csl, maybe_some, name, Namespace, word, List, parse
class Type(Keyword):
grammar = Enum( K("int"), K("long") )
class Parameter:
grammar = attr("typing", Type), name()
class Parameters(Namespace):
grammar = optional(csl(Parameter))
class Instruction(str):
grammar = word, ";"
block = "{", maybe_some(Instruction), "}"
class Function(List):
grammar = attr("typing", Type), name(), \
"(", attr("parms", Parameters), ")", block
f = parse("int f(int a, long b) { do_this; do_that; }",
Function)
print(f.name)
print(f.typing)
print(f.parms["b"].typing)
print(f[0])
print(f[1])
I get the following no-member errors:
E: 22, 6: Instance of 'list' has no 'name' member (no-member)
E: 22, 6: Instance of 'List' has no 'name' member (no-member)
E: 22, 6: Instance of 'SyntaxError' has no 'name' member (no-member)
E: 23, 6: Instance of 'list' has no 'typing' member (no-member)
E: 23, 6: Instance of 'List' has no 'typing' member (no-member)
E: 23, 6: Instance of 'SyntaxError' has no 'typing' member (no-member)
E: 24, 6: Instance of 'SyntaxError' has no 'parms' member (no-member)
E: 24, 6: Instance of 'list' has no 'parms' member (no-member)
E: 24, 6: Instance of 'List' has no 'parms' member (no-member)
Originally reported by: Florian Bruhin (BitBucket: The-Compiler, GitHub: @The-Compiler?)
Last one, I promise! (After this I reported every issue where I had a workaround for)
With this code (slightly adjusted example from the docs) using pyPEG2:
I get the following
no-member
errors: