From 69df0b216fc51889aee3323a5505b7d49ffc5b4d Mon Sep 17 00:00:00 2001 From: Andy C Date: Tue, 14 Jan 2025 11:56:31 -0500 Subject: [PATCH 1/2] [refactor] Move files out of lazylex/ Preparing for data_lang/htm8.py. Add htm8.asdl. Not used yet. --- build/py.sh | 1 + data_lang/htm8.asdl | 24 +++++++++++++++++++ .../testdata/hello.htm8 | 0 lazylex/README.md => doc/lazylex.md | 0 doctools/oils_doc_test.py | 4 ++-- lazylex/html_test.py | 2 +- 6 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 data_lang/htm8.asdl rename lazylex/testdata.html => data_lang/testdata/hello.htm8 (100%) rename lazylex/README.md => doc/lazylex.md (100%) diff --git a/build/py.sh b/build/py.sh index 625a376965..9a1e91170d 100755 --- a/build/py.sh +++ b/build/py.sh @@ -139,6 +139,7 @@ py-codegen() { # depends on syntax.asdl gen-asdl-py 'core/runtime.asdl' gen-asdl-py 'core/value.asdl' + gen-asdl-py 'data_lang/htm8.asdl' gen-asdl-py 'data_lang/nil8.asdl' gen-asdl-py 'display/pretty.asdl' gen-asdl-py 'mycpp/mycpp.asdl' diff --git a/data_lang/htm8.asdl b/data_lang/htm8.asdl new file mode 100644 index 0000000000..70bdbeae08 --- /dev/null +++ b/data_lang/htm8.asdl @@ -0,0 +1,24 @@ + +module htm8 +{ + + h8_id = + Decl + + # CommentBegin, ProcessingBegin, CDataBegin are "pseudo-tokens", not visible + | Comment | CommentBegin + | Processing | ProcessingBegin + | CData | CDataBegin + + | StartTag | StartEndTag | EndTag + + | DecChar | HexChar | CharEntity + + | RawData | HtmlCData + + | BadAmpersand | BadGreaterThan | BadLessThan + + | Invalid + | EndOfStream + generate [no_namespace_suffix] # cosmetic: call it h8_id, not h8_id_e +} diff --git a/lazylex/testdata.html b/data_lang/testdata/hello.htm8 similarity index 100% rename from lazylex/testdata.html rename to data_lang/testdata/hello.htm8 diff --git a/lazylex/README.md b/doc/lazylex.md similarity index 100% rename from lazylex/README.md rename to doc/lazylex.md diff --git a/doctools/oils_doc_test.py b/doctools/oils_doc_test.py index c173cf17e9..14fc58a48f 100755 --- a/doctools/oils_doc_test.py +++ b/doctools/oils_doc_test.py @@ -7,7 +7,7 @@ from lazylex import html from doctools import oils_doc # module under test -with open('lazylex/testdata.html') as f: +with open('data_lang/testdata/hello.htm8') as f: TEST_HTML = f.read() @@ -58,7 +58,7 @@ def testShPrompt(self): def testHighlightCode(self): # type: () -> None - # lazylex/testdata.html has the language-sh-prompt + # data_lang/testdata/hello.htm8 has the language-sh-prompt h = oils_doc.HighlightCode(TEST_HTML, None) self.assert_('' in h, h) diff --git a/lazylex/html_test.py b/lazylex/html_test.py index 7cb9f65535..ebe0677b17 100755 --- a/lazylex/html_test.py +++ b/lazylex/html_test.py @@ -9,7 +9,7 @@ log = html.log -with open('lazylex/testdata.html') as f: +with open('data_lang/testdata/hello.htm8') as f: TEST_HTML = f.read() From 30ee4f3edf1e77fde2d8581be211701eabad9d50 Mon Sep 17 00:00:00 2001 From: Andy C Date: Tue, 14 Jan 2025 12:12:35 -0500 Subject: [PATCH 2/2] [ASDL cleanup] Remove unnecessary Obj type Add comments. --- asdl/pybase.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/asdl/pybase.py b/asdl/pybase.py index e323bc2cd3..d6a3bcfa7d 100644 --- a/asdl/pybase.py +++ b/asdl/pybase.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -"""pybase.py.""" +"""asdl/pybase.py is a runtime library for ASDL in Python""" from __future__ import print_function from mycpp import mylib @@ -10,21 +10,16 @@ from asdl.runtime import TraversalState -class Obj(object): - # NOTE: We're using CAPS for these static fields, since they are constant at - # runtime after metaprogramming. - ASDL_TYPE = None # Used for type checking - - class SimpleObj(int): - """Base type of simple sum types.""" - # TODO: Get rid of this indirection? Although mycpp might use it. + """Base type of simple sum types, which are integers.""" + # TODO: Get rid of this class? mycpp uses it to tell if it should generate + # h8_id or h8_id*. pass -class CompoundObj(Obj): - # The tag is set for variant types, which are subclasses of sum - # types. Never set for product types. +class CompoundObj(object): + # The tag is set for variant types, which are subclasses of sum types. + # It's not set for product types. _type_tag = 0 # Starts at 1. Zero is invalid def PrettyTree(self, do_abbrev, trav=None): @@ -33,6 +28,8 @@ def PrettyTree(self, do_abbrev, trav=None): def __repr__(self): # type: () -> str + """Print this ASDL object nicely.""" + # TODO: Break this circular dependency. from asdl import format as fmt