Skip to content
This repository was archived by the owner on Feb 13, 2018. It is now read-only.

Parser Improvements - RegEx #4

Merged
merged 3 commits into from
Sep 25, 2016
Merged

Parser Improvements - RegEx #4

merged 3 commits into from
Sep 25, 2016

Conversation

2008Choco
Copy link
Contributor

@2008Choco 2008Choco commented Sep 24, 2016

Greatly improved the file parser using RegEx. This allows for more flexibility with whitespace and conditionals

Example:
function name(parameters) // This is valid
function name ( parameters , adsduadf ) // This is also valid
function name (parame\te*rs) // This is not valid

Whitespace is simply ignored in all declarations, including the declaration of variables. This allows for more flexibility with the compiler, much like Java's multi-line syntax and whitespace ignorer. Personally, this feels much more elegant, though if you disagree you are free to decline this pull request 😃

NOTE: I did not add support for the "for" loop, as I am not sure what your plans are for its syntax.
I also did not modify the way function parameters or any other variable parsing features act. I only changed the method of detecting that a line is x, y or z.

This was tested in a .TEA file, and it seems to have parsed everything perfectly. There should be no external changes, only internal efficiency improvements

+ Added a constructor to provide the String type
+ Added a getType(); to return the type of the variable
* Changed "type" to private and final to follow OOP conventions

Function:
* Changed all fields from public to private to follow OOP conventions
+ Added a couple constructors for easy accessibility for fields
+ Added necessary getter and setter methods

Variable:
* Changed all fields from public to private to follow OOP conventions
+ Added a couple constructors for easy accessibility for fields
+ Added necessary getter and setter methods

ParsedCode:
* Changed all fields from public to private to follow OOP conventions
+ Added a couple constructors for easy accessibility for fields
+ Added necessary getter and setter methods

Parser:
+ Created a new map and list of values for every file parse (This is necessary to allow for multiple scripts)
* The parse functions are now more specific to the regex match
+ Utilized the new Function constructor when building a new Function
+ Utilized all new constructors / methods in the Flow, Function, and Variable classes
@2008Choco
Copy link
Contributor Author

Just pushed up a new commit to change up the functionality of all type values. These should follow proper OOP conventions, and allow for the construction of values with constructors as well.

@DusterTheFirst
Copy link
Member

Nice! For The For Loops, For Now, I Don't Know What I'll Do For Them, Any Suggestions?

Also, When I Merge Your Request, How Do I Update My Code In Eclipse TO Match It"

@2008Choco
Copy link
Contributor Author

No suggestions for the for loop. I would suggest taking a look at how Lua does it. Obviously, parameter braces would be recommended rather than free-hand to match a similar syntax as while, but that's up to you. It's your language.

As for how to link it to your IDE, clone the project to your desktop on a local repository. (I assume you've already done this, as I believe you're using GitHub Desktop or SourceTree?). In Eclipse, do File -> Import -> [Git]: Projects from Git. Follow along the steps there and you should be on your way to importing your project

@DusterTheFirst
Copy link
Member

Gracias, Syntax Will Probably Be Like "for var, boolean, manipulateVar do end"

@2008Choco
Copy link
Contributor Author

2008Choco commented Sep 25, 2016

Might I suggest the removal of the "do" keyword to match with the while loop? Unless of course that's the syntax of while. If it is, then I am able to modify the regex to search for that as well

@DusterTheFirst DusterTheFirst merged commit 0ad6cc7 into TheDustyard:master Sep 25, 2016
@DusterTheFirst
Copy link
Member

DusterTheFirst commented Sep 25, 2016

Your Regex Thing Doesn't Work With Tabs...

Wit This:

            var jeff = 21

            while true
                yomamma
            end

It Doesn't Find Anything...

And I Dont Need While to have do

@2008Choco
Copy link
Contributor Author

2008Choco commented Sep 25, 2016

Oh... you want to know why that is? That's because I was silly and thought that the syntax was similar to Java :P It's expecting parameter braces for conditionals! As for why it's not working with tabs, it actually is. It's detecting it, but the way you're parsing it with the parseVariable() method is not. You're replacing all spaces, but indents are not spaces; they are whitespace. I suggest perhaps the use of the following:

s = s.replaceAll("\s+", "").toLowerCase()

Same thing goes for the other parsing functions. That will replace all whitespace characters including indents and spaces.

To fix the regex statements, replace the following:
private static final Pattern conditionalRegex = Pattern.compile("(while|if)\\s*\\(.+\\)");

With:
private static final Pattern conditionalRegex = Pattern.compile("(while|if)\\s+.+");

That should fix it to utilise the new syntax :D Functions, however expect parenthesis for parameters as per requested syntax :) I hope that fixes it

@2008Choco 2008Choco deleted the Parser branch September 25, 2016 20:38
@DusterTheFirst DusterTheFirst self-assigned this Oct 2, 2016
@DusterTheFirst
Copy link
Member

I Have Tried To Figure Out Why, But Your Regex Won't Recognise "function yomamma()" But Will For "function hello(inp)"

@2008Choco
Copy link
Contributor Author

My apologies. I must have messed up when writing that regex. I didn't take into consideration of the acceptance of no parameter fields in the parameter braces for functions. Here. This should fix it:

function\\s*\\w+\\s*\\(\\s*\\w*\\s*(,\\s*\\w*)*\\s*\\)

Just replace the regex currently being used for functions with the regex code above. That should fix everything :)

@DusterTheFirst
Copy link
Member

Thanks! I Am Not To Savy With Regex

@DusterTheFirst
Copy link
Member

Sorry If You Arnt The Person To Ask But, I AM Stuck With Parsing Nested Loops And Loops In Functions. My Current Version Doesn't Work With Theml

@DusterTheFirst
Copy link
Member

Personally would you seggest I use a third party parser, like luaj?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

2 participants