Skip to content

Commit

Permalink
[translation] Move TDOP spec to a different module.
Browse files Browse the repository at this point in the history
Start plugging a C++ version in.

Down to 6 errors.
  • Loading branch information
Andy Chu committed Nov 20, 2019
1 parent ebb1528 commit e1f994f
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
16 changes: 16 additions & 0 deletions cpp/arith_spec.h
@@ -0,0 +1,16 @@
// Replacement for osh/arith_spec

#ifndef ARITH_SPEC_H
#define ARITH_SPEC_H

namespace tdop { // forward declare
class ParserSpec;
}

namespace arith_spec {

tdop::ParserSpec* Spec();

} // arith_spec

#endif // ARITH_SPEC_H
4 changes: 2 additions & 2 deletions frontend/parse_lib.py
Expand Up @@ -22,7 +22,7 @@

from oil_lang import expr_parse
from oil_lang import expr_to_ast
from osh import arith_parse
from osh import arith_spec
from osh import cmd_parse
from osh import word_parse
from mycpp import mylib
Expand Down Expand Up @@ -309,7 +309,7 @@ def MakeArithParser(self, code_str):
lx = self._MakeLexer(line_reader)
w_parser = word_parse.WordParser(self, lx, line_reader)
w_parser.Init(lex_mode_e.Arith) # Special initialization
a_parser = tdop.TdopParser(arith_parse.SPEC, w_parser)
a_parser = tdop.TdopParser(arith_spec.Spec(), w_parser)
return a_parser

def MakeParserForCommandSub(self, line_reader, lexer, eof_id):
Expand Down
1 change: 1 addition & 0 deletions mycpp/examples.sh
Expand Up @@ -245,6 +245,7 @@ using id_kind_asdl::Kind_t;
// oil/cpp
#include "pretty.h"
#include "match.h"
#include "arith_spec.h"
// Hack for now. Every sum type should have repr()?
Expand Down
2 changes: 0 additions & 2 deletions osh/arith_parse.py
Expand Up @@ -175,5 +175,3 @@ def MakeShellSpec():
spec.Left(1, tdop.LeftBinaryOp, [Id.Arith_Comma])

return spec

SPEC = MakeShellSpec()
17 changes: 17 additions & 0 deletions osh/arith_spec.py
@@ -0,0 +1,17 @@
#!/usr/bin/env python2
"""
arith_spec.py
"""
from __future__ import print_function

from osh import arith_parse
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from frontend.tdop import ParserSpec

_SPEC = arith_parse.MakeShellSpec()

def Spec():
# type: () -> ParserSpec
return _SPEC
4 changes: 2 additions & 2 deletions osh/word_parse.py
Expand Up @@ -72,7 +72,7 @@
from frontend import lookup
from frontend import reader
from frontend import tdop
from osh import arith_parse
from osh import arith_spec
from osh import braces
from osh import word_
from mycpp.mylib import NewStr
Expand Down Expand Up @@ -932,7 +932,7 @@ def _ReadArithExpr(self):
See the assertion in ArithParser.Parse() -- unexpected extra input.
"""
# calls self.ReadWord(lex_mode_e.Arith)
a_parser = tdop.TdopParser(arith_parse.SPEC, self)
a_parser = tdop.TdopParser(arith_spec.Spec(), self)
anode = a_parser.Parse()
return anode

Expand Down

0 comments on commit e1f994f

Please sign in to comment.