-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: enable Python when grammar has 4 sections
This is in anticipation of a new hybrid Java/Python mode in which the parser runs in Java and the semantics rep-loop runs in Python. In this commit, when an optional 4th section is detected, plcc.py generates ParseJsonAst.json. Thus allowing the parser to to generate JSON ASTs when the `--json_ast` flag is passed. It also generates experimental Python files. --- Closes #95 Co-authored-by: Reed Everis <[email protected]> Co-authored-by: Akshar Patel <[email protected]> Co-authored-by: Stoney Jackson <[email protected]>
- Loading branch information
1 parent
460d1e7
commit be3aa2e
Showing
59 changed files
with
293 additions
and
3,166 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
Empty file.
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,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' | ||
} |
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,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' | ||
} |
Oops, something went wrong.