Ejemplo n.º 1
0
def _assertReadWordWithArena(test, w_parser):
    w = w_parser.ReadWord(lex_mode_e.ShCommand)
    assert w is not None
    w.PrettyPrint()

    # Next word must be Eof_Real
    w2 = w_parser.ReadWord(lex_mode_e.ShCommand)
    test.assertTrue(
        test_lib.TokenWordsEqual(word.Token(token(Id.Eof_Real, '')), w2), w2)
    return w
Ejemplo n.º 2
0
def _assertReadWordWithArena(test, word_str):
    print('\n---', word_str)
    arena, w_parser = _InitWordParserWithArena(word_str)
    w = w_parser.ReadWord(lex_mode_e.OUTER)
    assert w is not None
    ast_lib.PrettyPrint(w)

    # Next word must be Eof_Real
    w2 = w_parser.ReadWord(lex_mode_e.OUTER)
    test.assertTrue(
        test_lib.TokenWordsEqual(ast.TokenWord(ast.token(Id.Eof_Real, '')),
                                 w2), w2)

    return arena, w
Ejemplo n.º 3
0
def _assertReadWordWithArena(test, word_str):
    print('\n---', word_str)
    arena = test_lib.MakeArena('word_parse_test.py')
    w_parser = _InitWordParser(word_str, arena=arena)
    w = w_parser.ReadWord(lex_mode_e.Outer)
    assert w is not None
    ast_lib.PrettyPrint(w)

    # Next word must be Eof_Real
    w2 = w_parser.ReadWord(lex_mode_e.Outer)
    test.assertTrue(
        test_lib.TokenWordsEqual(
            osh_word.TokenWord(syntax_asdl.token(Id.Eof_Real, '')), w2), w2)

    return arena, w
Ejemplo n.º 4
0
def _assertReadWordWithArena(test, word_str):
  print('\n---', word_str)
  arena, w_parser = _InitWordParserWithArena(word_str)
  w = w_parser.ReadWord(lex_mode_e.OUTER)
  if w:
    ast.PrettyPrint(w)
  else:
    err = w_parser.Error()
    test.fail("Couldn't parse %r: %s" % (word_str, err))

  # Next word must be Eof_Real
  w2 = w_parser.ReadWord(lex_mode_e.OUTER)
  test.assertTrue(
      test_lib.TokenWordsEqual(ast.TokenWord(ast.token(Id.Eof_Real, '')), w2),
      w2)

  return arena, w