Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to Make lexer #1285

Merged
merged 13 commits into from
Jul 30, 2019
Merged

Improvements to Make lexer #1285

merged 13 commits into from
Jul 30, 2019

Conversation

bavison
Copy link
Contributor

@bavison bavison commented Jul 26, 2019

This is still far from handling the full syntax of makefiles, but it handles far more of the examples I threw at it than the previous version.

If I have one main remaining observation, it's that variable expansions and function invocations (i.e. $(thing)) is actually valid at any point in a makefile, but they are only being fully lexed when they occur within a recipe line. For example, in the following slightly contrived example,

NAME_OF_TARGET=TARGET
$(NAME_OF_TARGET)=$(filter %.o,$(MAKECMDGOALS))
SOURCE=$(TARGET:.o=.c)

ifneq "$(shell uname)" ''
$(shell echo $(TARGET)): $(shell echo $(SOURCE))
	cc -o $@ $(shell echo $(SOURCE))
endif

the only $(shell...) function that is differentially coloured into its component parts is the one on the penultimate line (and in fact lexing fails if you try it on the left-hand side of an assignment). By contrast, I note that GitHub's colouring above treats them all the same.

I'm not sure how consistency can be efficiently achieved.

\s matches newline characters which are syntacically distinct from whitespace
in makefiles
Both are valid for both variable expansions and function invocations, wherever
they occur.
…e, endif

These can occur both inside and outside recipes (called block_body state here)
without causing the recipe to end.
@pyrmont pyrmont added the needs-review The PR needs to be reviewed label Jul 26, 2019
Copy link
Contributor

@pyrmont pyrmont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bavison Thanks for submitting a PR!

In addition to these comments, could you update the visual sample to include some of the syntax that should now work with this lexer? It would be good to visually confirm that's working as intended.

lib/rouge/lexers/make.rb Show resolved Hide resolved
lib/rouge/lexers/make.rb Show resolved Hide resolved
lib/rouge/lexers/make.rb Outdated Show resolved Hide resolved
lib/rouge/lexers/make.rb Outdated Show resolved Hide resolved
lib/rouge/lexers/make.rb Show resolved Hide resolved
lib/rouge/lexers/make.rb Show resolved Hide resolved
@pyrmont pyrmont added author-action The PR has been reviewed but action by the author is needed and removed needs-review The PR needs to be reviewed labels Jul 28, 2019
Copy link
Contributor

@pyrmont pyrmont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good! I think this might be the last thing.

lib/rouge/lexers/make.rb Show resolved Hide resolved
@pyrmont pyrmont merged commit c5dab6a into rouge-ruby:master Jul 30, 2019
@pyrmont
Copy link
Contributor

pyrmont commented Jul 30, 2019

Thanks for the work on this one, too, @bavison! Writing that commit message really brought home how much this is an improvement on the previous version of the lexer O_O

@pyrmont pyrmont removed the author-action The PR has been reviewed but action by the author is needed label Jul 30, 2019
bavison added a commit to bavison/rouge that referenced this pull request Sep 9, 2019
This commit improves the Make lexer in the following ways:

- use`\t` in place of` \s`;
- support syntax variant `${}` as well as `$()`;
- support all built-in functions, not just `$(shell...)`;
- support include directive;
- support conditional directives `ifdef`, `ifndef`, `ifeq`, `ifneq`, 
  `else`, `endif`;
- support substitution references when expanding variables;
- permit macro names to start with digits; and
- register additional filename extensions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants