Page 1 of 1

Forum code highlighting? (C++, Morrowind, OpenMW)

Posted: 07 May 2017, 23:28
by Jyby
Since out project is >90% C++, can we get some C++ code highlighting for

Code: Select all

[Code]
[/code] tags?

Re: Forum C++ code highlighting?

Posted: 08 May 2017, 05:50
by lgromanowski
Hi,
yes, I'll try to install syntax highlighter this evening

Re: Forum C++ code highlighting?

Posted: 08 May 2017, 08:17
by psi29a
Nice proposal, thanks Jyby and Lgro! :)

Re: Forum C++ code highlighting?

Posted: 08 May 2017, 20:15
by lgromanowski
Hi,
I've just added highlight.js but it's not perfect, example:

Code: Select all

#ifndef GAME_MWCLASS_MOBILE_H
#define GAME_MWCLASS_MOBILE_H

#include "../mwworld/class.hpp"

namespace ESM
{
    struct GameSetting;
}

namespace MWClass
{
    /// \brief Class holding functionality common to Creature and NPC
    class Actor : public MWWorld::Class
    {
    protected:

        Actor();

    public:
        virtual ~Actor();

        virtual void adjustPosition(const MWWorld::Ptr& ptr, bool force) const;
        ///< Adjust position to stand on ground. Must be called post model load
        /// @param force do this even if the ptr is flying

        virtual void insertObject(const MWWorld::Ptr& ptr, const std::string& model, MWPhysics::PhysicsSystem& physics) const;

        virtual bool useAnim() const;

        virtual void block(const MWWorld::Ptr &ptr) const;

        virtual osg::Vec3f getRotationVector(const MWWorld::Ptr& ptr) const;
        ///< Return desired rotations, as euler angles.

        virtual float getEncumbrance(const MWWorld::Ptr& ptr) const;
        ///< Returns total weight of objects inside this object (including modifications from magic
        /// effects). Throws an exception, if the object can't hold other objects.

        virtual bool allowTelekinesis(const MWWorld::ConstPtr& ptr) const;
        ///< Return whether this class of object can be activated with telekinesis

        virtual bool isActor() const;

        virtual bool canBeActivated(const MWWorld::Ptr& ptr) const;

        // not implemented
        Actor(const Actor&);
        Actor& operator= (const Actor&);
    };
}

#endif

Re: Forum C++ code highlighting?

Posted: 08 May 2017, 20:38
by AnyOldName3
It might be a good idea to make the language an optional argument to the code tag, as we're likely to get snippets of languages other than C++ here, such as Morrowind scripts.

Re: Forum C++ code highlighting?

Posted: 08 May 2017, 20:54
by lgromanowski
AnyOldName3 wrote:It might be a good idea to make the language an optional argument to the code tag, as we're likely to get snippets of languages other than C++ here, such as Morrowind scripts.
Highlight.js uses autodetection for language highlighting (unfortunately MW script is not on the supported languages list), but at this moment it's disabled - C++ language is forced - I'll change it tomorrow.

Re: Forum C++ code highlighting?

Posted: 08 May 2017, 22:09
by Jyby
Thanks Igro

@everyone and @AnyOldName3,

I wonder if we can work with highlightjs and write a highlighter for MW / OpenMW script.

http://highlightjs.readthedocs.io/en/la ... uests.html

Re: Forum C++ code highlighting?

Posted: 10 May 2017, 06:10
by silentthief
Jyby wrote:Thanks Igro

@everyone and @AnyOldName3,

I wonder if we can work with highlightjs and write a highlighter for MW / OpenMW script.

http://highlightjs.readthedocs.io/en/la ... uests.html
That would be really helpful.

Was thinking that this should work in the editor as well (Would be nice!!!). Perhaps even with using the (fill in the blank name of an IDE) that when you set up a command with an open brace/quote it populates the command with and open and close, like in code::blocks (programming IDE -- thats right I am trying to learn) if you put a cout << " command, it automatically populates with begin/end quotes and puts the cursor right in between (so it adds the second double quotes, so it becomes cout << "" and puts the cursor between the two sets doublequotes). Pretty sure you see similar setup with geany with regard to braces and other (searching for right term) delimiters (?).

Obviously, what this does is "try" to avoid syntax errors where you forget to leave off an end-brace or and end-quote.

ST

Re: Forum C++ code highlighting?

Posted: 11 May 2017, 06:52
by Jyby
Researching here for scripting reference: http://wiki.theassimilationlab.com/mmw/ ... or_Dummies
Following this guide for making a highlighter: http://highlightjs.readthedocs.io/en/la ... ral-syntax

I haven't given this much effort. Work in progress so far (not sure how successful I'll be):

Code: Select all

{
  case_insensitive: true,
  keywords: 'Begin StartScript StopScript End end if elseif else endif Endif while MessageBox Short Float Set set to',
  contains: [
    {
      className: 'string',
      begin: '\"', end: '\"'
    },
    hljs.COMMENT(
      ';*', // morrowind comments start with ;
      '*\n' // morrowind comments end with \n (do they end with LFRC on other computers?)
    ),
    {
      className: 'ref',
      begin: '\"', end: '\"->'
    }
  ]
}

// TODO: need to represent these

// I think these are represented as *->* in regex.
// Player->RemoveSpell, "Frost_Curse"
// Fargoth->ForceSneak

// Or these examples
// "seen-ref"->StartCombat Player

// if ( ( GetPos x ) == 500 )

// Something like set * to *,*,* for as many comma seperated items
// set temp to 100