Skip to content

Commit

Permalink
[translation] C+ type stubs for frontend/args_def.py.
Browse files Browse the repository at this point in the history
Down to 3 compile errors with frontend/args.py!  All related to
args::UsageError().
  • Loading branch information
Andy Chu committed May 9, 2020
1 parent 56cdd45 commit 30ed02b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
34 changes: 34 additions & 0 deletions cpp/frontend_arg_def.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// frontend_arg_def.h

#ifndef FRONTEND_ARG_DEF_H
#define FRONTEND_ARG_DEF_H

#include "mylib.h"

namespace args {
class _Action;
class SetToArg;
};

namespace arg_def {

class _FlagSpec {
public:
Dict<Str*, bool>* arity0;
Dict<Str*, args::SetToArg*>* arity1;
Dict<Str*, bool>* options;
Dict<Str*, runtime_asdl::value_t*>* defaults;
};

class _FlagSpecAndMore {
public:
Dict<Str*, args::_Action*>* actions_long;
Dict<Str*, args::_Action*>* actions_short;
Dict<Str*, runtime_asdl::value_t*>* defaults;

};

} // namespace arg_def

#endif // FRONTEND_ARG_DEF_H

1 change: 1 addition & 0 deletions cpp/preamble.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using id_kind_asdl::Kind_t;

// oil/cpp
#include "core_error.h"
#include "frontend_arg_def.h"
#include "frontend_match.h"
#include "frontend_tdop.h"
#include "osh_arith_parse.h"
Expand Down
13 changes: 7 additions & 6 deletions frontend/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@
from mycpp import mylib
from mycpp.mylib import tagswitch, iteritems

try:
import libc # OilFlags uses regexes right now.
except ImportError: # circular dependecy with arg_gen
libc = None

from typing import (
cast, Tuple, Optional, Dict, List, Any, IO, TYPE_CHECKING
)
Expand Down Expand Up @@ -217,7 +212,8 @@ def Peek2(self):
None is your SENTINEL for parsing.
"""
if self.i >= self.n:
return None, -1
no_str = None # type: str
return no_str, -1
else:
return self.argv[self.i], self.spids[self.i]

Expand Down Expand Up @@ -615,6 +611,11 @@ def ParseMore(spec, arg_r):


if mylib.PYTHON:
try:
import libc # OilFlags uses regexes right now.
except ImportError: # circular dependecy with arg_gen
libc = None

def ParseOil(spec, arg_r):
# type: (arg_def._OilFlags, Reader) -> Tuple[_Attributes, int]
out = _Attributes(spec.defaults)
Expand Down
1 change: 1 addition & 0 deletions osh/tdop.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def LeftAssign(p, w, left, rbp):

#
# Parser definition
# TODO: To be consistent, move this to osh/tdop_def.py.
#

if mylib.PYTHON:
Expand Down

0 comments on commit 30ed02b

Please sign in to comment.