Skip to content

Commit

Permalink
Merge pull request #111 from ourPLCC/python
Browse files Browse the repository at this point in the history
refactor: enable Python when grammar has 4 sections
  • Loading branch information
StoneyJackson authored Apr 20, 2024
2 parents 460d1e7 + be3aa2e commit dd27f16
Show file tree
Hide file tree
Showing 59 changed files with 293 additions and 3,166 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ languages/
# PLCC places generated Java files in directories named Java. Ignore them.
Java/

# PLCC places generated Python files in directories named Python. Ignore them.
Python/

# Created by Docker environment
.bash_history

Expand Down
Empty file added src/langs/__init__.py
Empty file.
65 changes: 65 additions & 0 deletions src/langs/java.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
spec = {
"abstractStubFormatString" : """\
//{base}:top//
//{base}:import//
import java.util.*;
public abstract class {base}{ext} /*{base}:class*/ {{
public static final String $className = "{base}";
public static {base} parse(Scan scn$, Trace trace$) {{
Token t$ = scn$.cur();
Token.Match match$ = t$.match;
switch(match$) {{
{cases}
default:
throw new PLCCException(
"Parse error",
"{base} cannot begin with " + t$.errString()
);
}}
}}
//{base}//
}}
""",

"stubFormatString" : """\
//{cls}:top//
//{cls}:import//
import java.util.*;
// {ruleString}
public class {cls}{ext} /*{cls}:class*/ {{
public static final String $className = "{cls}";
public static final String $ruleString =
"{ruleString}";
{decls}
public {cls}({params}) {{
//{cls}:init//
{inits}
}}
public static {cls} parse(Scan scn$, Trace trace$) {{
if (trace$ != null)
trace$ = trace$.nonterm("{lhs}", scn$.lno);
{parse}
}}
//{cls}//
}}
""",
"extendFormatString" : ' extends {cls}',
"declFormatString" : 'public {fieldType} {field};',
"initFormatString" : 'this.{field} = {field};',
"paramFormatString" : '{fieldType} {field}',
"semFlag" : 'semantics',
"lineComment" : '//',
"blockCommentStart" : "/*",
"blockCommentEnd" : "*/",
"destFlag" : 'destdir',
"fileExt" : '.java'
}
40 changes: 40 additions & 0 deletions src/langs/python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
spec = {
"abstractStubFormatString" : """\
#{base}:top#
#{base}:import#
class {base}({ext}): #{base}:class#
className = "{base}"
#{base}#
""",

"stubFormatString" : """\
#{cls}:top#
#{cls}:import#
# {ruleString}
class {cls}({ext}): #{cls}:class#
className = "{cls}"
ruleString = "{ruleString}"
{decls}
def __init__({params}):
#{cls}:init#
{inits}
#{cls}#
""",
"extendFormatString" : '{cls}',
"declFormatString" : '{field} = None',
"initFormatString" : 'self.{field} = {field}',
"paramFormatString" : '{field}',
"semFlag" : 'python_semantics',
"lineComment" : '#',
"blockCommentStart" : "'''",
"blockCommentEnd" : "'''",
"destFlag" : 'python_destdir',
"fileExt" : '.py'
}
Loading

0 comments on commit dd27f16

Please sign in to comment.