PileProject / drive

The drive project
Other
5 stars 4 forks source link

Add ProgramParser for alignment #32

Closed tiwanari closed 2 years ago

tiwanari commented 8 years ago

Parsing blocks feature

This is an experimental PR that introduces a parsing feature to our apps. These codes were originally written by Yuya Ono ( @onoyuuya ) .

How to use

This is a simple snippet that shows how to use this parser.

       SyntaxParser mProgramTree;

       private void alignBlocks() {
               parseBlocks();
               float dpfactor = getResources().getDisplayMetrics().density;
               Resources res = getResources();
               mProgramTree.alignment(res, dpfactor);
       }

       private void parseBlocks() {
               ArrayList<BaseBlock> blocks;
               blocks = load...;

               try {
                       mProgramTree = SyntaxParser.parseProgram(blocks);
                       new AlertDialog.Builder(this)
                               .setTitle("Analyze Result")
                               .setMessage(mProgramTree.toString())
                               .setPositiveButton(R.string.ok, null)
                               .show();
               } catch (SyntaxErrorException synex) {
                       new AlertDialog.Builder(this)
                               .setTitle("Syntax Error")
                               .setMessage(
                                       String.format("%s\nat %s", synex.getErrorCode(), synex.getBlock()))
                               .setPositiveButton(R.string.ok, null)
                               .show();
                       return;
               }
       }

Status

I have just imported the original codes and fixed them a little to remove errors. The modification I made may cause bugs (I'm not sure). I will check and refactor them.

Discussion

These codes originally have been made for alignment but we want to make it forward - convert blocks into codes. How should we do for the purpose?

mandaiy commented 2 years ago

Closed due to inactivity. Feel free to reopen this PR if you want :)