GithubHelp home page GithubHelp logo

Getter:peek () is weird! about luamacro HOT 2 CLOSED

stevedonovan avatar stevedonovan commented on September 4, 2024
Getter:peek () is weird!

from luamacro.

Comments (2)

stevedonovan avatar stevedonovan commented on September 4, 2024

All I can say is yes, peek is a weird method. Let me have a look this
weekend.

On Tue, Jan 6, 2015 at 3:52 AM, Gary V. Vaughan [email protected]
wrote:

Hi Steve,

It makes sense to me that get:peek (n, true) counts spaces and comment
tokens, and that since you can't predict what space and comment tokens
might be in the input, why that is not the default.

But, with only one argument, peek is behaving weird… apparently space
tokens are not filled in correctly, containing a copy of a neighbouring
token, but taking up space in the 'skipped' token stream anyway. Is this a
bug, or am I not understanding how it works?

local macro = require "macro"

macro.define ('target', function (get)
local i = 0
repeat
i = i + 1
local tk, v = get:peek (i, true)
local tk_, v_ = get:peek (i)
print (i, tk, v. tk_, v_)
until v == " EOS"
return nil, trueend)

macro.substitute [[ target foo = "bar", function (t) -- comment print "test" end]]

What I'd like to do is check whether the 2nd non-space. non-comment token
is an "=" before expanding the macro, but that token is always 3 peek
positions forward, irrespective of dont_skip mode (unless of course the
unexpanded text has different spacing to my example).it seems like
1-argument peek ought to be able to do this?

Ideally, I'd then like to preserve line-breaks as I copy the remaining
tokens to the output, injecting some other missing lua syntax as I go. peek
with true as the second argument seems like it will let me detect and copy
whitespace once I get past the first issue?

Cheers!


Reply to this email directly or view it on GitHub
#5.

from luamacro.

gvvaughan avatar gvvaughan commented on September 4, 2024

The code above, and the macro I am writing are working with #6.

Unless I'm grossly misunderstanding how peek is designed to be used, this seems like the right approach to me.

from luamacro.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.