-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[oil-language] Start implementing the parse_config() function
Part of the config dialect #951. It's statically typed, but doesn't run yet. [doc] Oil vs Python updates
- Loading branch information
Andy C
committed
May 22, 2022
1 parent
425fed0
commit 43b9b5b
Showing
10 changed files
with
134 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env python2 | ||
""" | ||
funcs.py | ||
""" | ||
from __future__ import print_function | ||
|
||
from _devbuild.gen.runtime_asdl import value | ||
from _devbuild.gen.syntax_asdl import source | ||
from asdl import runtime | ||
from core import alloc | ||
from core import error | ||
from core import main_loop | ||
from core import state | ||
from core import ui | ||
from frontend import reader | ||
|
||
import posix_ as posix | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from _devbuild.gen.runtime_asdl import value_t | ||
from core import process | ||
from frontend import parse_lib | ||
|
||
|
||
class ConfigParser(object): | ||
""" For parse_config() | ||
""" | ||
def __init__(self, fd_state, parse_ctx, errfmt): | ||
# type: (process.FdState, parse_lib.ParseContext, ui.ErrorFormatter) -> None | ||
self.fd_state = fd_state | ||
self.parse_ctx = parse_ctx | ||
self.errfmt = errfmt | ||
|
||
def ParseFile(self, path): | ||
# type: (str) -> value_t | ||
|
||
# TODO: need to close the file! | ||
try: | ||
f = self.fd_state.Open(path) | ||
except (IOError, OSError) as e: | ||
raise error.Expr("Couldn't open %r: %s" % (path, posix.strerror(e.errno))) | ||
|
||
arena = self.parse_ctx.arena | ||
line_reader = reader.FileLineReader(f, arena) | ||
|
||
parse_opts = state.MakeOilOpts() | ||
# Note: runtime needs these options and totally different memory | ||
|
||
# TODO: CommandParser needs parse_opts | ||
c_parser = self.parse_ctx.MakeConfigParser(line_reader) | ||
|
||
call_spid = runtime.NO_SPID # TODO: location info | ||
|
||
# TODO: Should there be a separate config file source? | ||
src = source.SourcedFile(path, call_spid) | ||
try: | ||
with alloc.ctx_Location(arena, src): | ||
node = main_loop.ParseWholeFile(c_parser) | ||
except error.Parse as e: | ||
self.errfmt.PrettyPrintError(e) | ||
return None | ||
|
||
# Wrap in expr.Block? | ||
return value.Block(node) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters