Exemplo n.º 1
0
def rune_lit():        return _, [r(r"r'(\\[^\n]|[^\\\"\n])*'"), r('r"(\\[^\n]|[^\\\'\n])*"')]
def string_lit():      return _, [single_string, double_string, raw_string]
Exemplo n.º 2
0
def GotoStmt():        return _, r(r'\bgoto\b'), ident
def FallStmt():        return _, r(r'\bfallthrough\b')
Exemplo n.º 3
0
def IfStmt():          return _, r(r'\bif\b'), Optional(SimpleStmt, _, ';'), Expression, Block, ZeroOrMore(_, r(r'\belse\b'), _, r(r'\bif\b'), Expression, Block), Optional(_, r(r'\belse\b'), Block)
def SwitchStmt():      return _, r(r'\bswitch\b'), Optional(SimpleStmt, _, ';'), [ExprSwitchStmt, TypeSwitchStmt]
Exemplo n.º 4
0
def GoStmt():          return _, r(r'\bgo\b'), Expression
def ReturnStmt():      return _, r(r'\breturn\b'), Optional(ExpressionList)
Exemplo n.º 5
0
def BreakStmt():       return _, r(r'\bbreak\b'), Optional(ident)
def ContinueStmt():    return _, r(r'\bcontinue\b'), Optional(ident)
Exemplo n.º 6
0
def ChannelType():     return _, r('<-?'), Type, _, r('-?>')
def FunctionLit():     return _, r(r'\bfunc\b'), Function
Exemplo n.º 7
0
def TypeAssertion():   return _, r(r'\bas\b'), Type

# statements
def Block():           return _, '{', Optional(StatementList), _, '}'
Exemplo n.º 8
0
def ImportDecl():      return _, r(r'\bimport\b'), ImportSpec, ZeroOrMore(_, ',', ImportSpec), Optional(_, ',')
def ImportSpec():      return _, r(import_re), Optional(_, r(r'\bas\b'), ident)
Exemplo n.º 9
0
def ImportSpec():      return _, r(import_re), Optional(_, r(r'\bas\b'), ident)
def TopLevelDecls():   return TopLevelDecl, ZeroOrMore(nl, TopLevelDecl), Optional(nl)
Exemplo n.º 10
0
def NotKeyword():     return _, Not(r(r'\b(as|break|case|const|continue|default|defer|else|fallthrough|for|while|func|go|goto|if|import|interface|return|select|struct|switch|type|var)\b'))
def nl():              return r(r'[ \t\r]*[\n;]')
Exemplo n.º 11
0
def nl():              return r(r'[ \t\r]*[\n;]')
def _():               return r(r'[ \t\r\n]*')
Exemplo n.º 12
0
def raw_string():      return r("`[^`]*`")
def ident():           return NotKeyword, r(id_re)
Exemplo n.º 13
0
def double_string():   return r(r'\$?"(\\[^\n]|[^\\\'\n])*"')
def raw_string():      return r("`[^`]*`")
Exemplo n.º 14
0
def single_string():   return r(r"\$?'(\\[^\n]|[^\\\"\n])*'")
def double_string():   return r(r'\$?"(\\[^\n]|[^\\\'\n])*"')
Exemplo n.º 15
0
def FunctionType():    return _, r(r'\bfunc\b'), Signature
def Signature():       return _, '(', ParameterList, _, ')', Optional(Result)
Exemplo n.º 16
0
def ConstDecl():       return _, r(r'\bconst\b'), IdentifierList, _, '=', ExpressionList
def IdentifierList():  return ident, ZeroOrMore(_, ',', ident), Optional(_, ',')
Exemplo n.º 17
0
def InterfaceType():   return _, r(r'\binterface\b'), InterfaceBody
def InterfaceBody():   return _, '{', Optional(MethodSpec, ZeroOrMore(nl, MethodSpec), Optional(nl)), _, '}'
Exemplo n.º 18
0
def TypeDecl():        return _, r(r'\btype\b'), TypeSpec, ZeroOrMore(_, ',', TypeSpec), Optional(_, ',')
def TypeSpec():        return Type, ident
Exemplo n.º 19
0
def FunctionLit():     return _, r(r'\bfunc\b'), Function
def Function():        return _, Signature, Block
Exemplo n.º 20
0
def FunctionDecl():    return _, r(r'\bfunc\b'), ident, [Function, Signature]
def MethodDecl():      return _, r(r'\bfunc\b'), Receiver, ident, [Function, Signature]
Exemplo n.º 21
0
def ShortVarDecl():    return _, r(r'\bvar\b'), IdentifierList, _, '=', ExpressionList   
def GoStmt():          return _, r(r'\bgo\b'), Expression
Exemplo n.º 22
0
def MethodDecl():      return _, r(r'\bfunc\b'), Receiver, ident, [Function, Signature]
def Receiver():        return _, '(', Type, Optional(ident), _, ')'
Exemplo n.º 23
0
def ReturnStmt():      return _, r(r'\breturn\b'), Optional(ExpressionList)
def BreakStmt():       return _, r(r'\bbreak\b'), Optional(ident)
Exemplo n.º 24
0
def StructDecl():      return _, r(r'\bstruct\b'), ident, StructBody
def InterfaceDecl():   return _, r(r'\binterface\b'), ident, InterfaceBody
Exemplo n.º 25
0
def ContinueStmt():    return _, r(r'\bcontinue\b'), Optional(ident)
def GotoStmt():        return _, r(r'\bgoto\b'), ident
Exemplo n.º 26
0
def InterfaceDecl():   return _, r(r'\binterface\b'), ident, InterfaceBody

# expressions
def Expression():      return Optional(unary_op), SubExpr, ZeroOrMore(TailExpr)
Exemplo n.º 27
0
def FallStmt():        return _, r(r'\bfallthrough\b')
def IfStmt():          return _, r(r'\bif\b'), Optional(SimpleStmt, _, ';'), Expression, Block, ZeroOrMore(_, r(r'\belse\b'), _, r(r'\bif\b'), Expression, Block), Optional(_, r(r'\belse\b'), Block)
Exemplo n.º 28
0
def StructType():      return _, r(r'\bstruct\b'), StructBody
def StructBody():      return _, '{', Optional(FieldDecl, ZeroOrMore(nl, FieldDecl), Optional(nl)), _, '}'
Exemplo n.º 29
0
def SwitchStmt():      return _, r(r'\bswitch\b'), Optional(SimpleStmt, _, ';'), [ExprSwitchStmt, TypeSwitchStmt]
def ExprSwitchStmt():  return Optional(Expression), _, '{', ZeroOrMore(ExprCaseClause), _, '}'
Exemplo n.º 30
0
def imaginary_lit():   return _, [float_lit, r('[0-9]+')], 'i'
def rune_lit():        return _, [r(r"r'(\\[^\n]|[^\\\"\n])*'"), r('r"(\\[^\n]|[^\\\'\n])*"')]